The MASM Forum

General => The Laboratory => Topic started by: jcfuller on September 21, 2016, 03:40:55 AM

Title: interesting discovery
Post by: jcfuller on September 21, 2016, 03:40:55 AM
With all the expertise here and the pursuit of tiny I wonder if any one has any insight on the discovery I made recently: http://www.jose.it-berater.org/smfforum/index.php?topic=5144.0

I only have VS 2015 community so I could not test on earlier versions to see if has always been the case.

One of the big features of PowerBASIC as Hutch has mentioned is the dead code removal. FreeBasic also has basically the same thing by using the PRIVATE key word for func/subs.

Is it just the linker or a combination cl and link?
Can the same thing be done with ML64?

James
Title: Re: interesting discovery
Post by: TWell on September 21, 2016, 03:57:23 AM
cl.exe /Gy option, COMDAT support ?
look here (https://msdn.microsoft.com/en-us/library/bxwfs976.aspx)
i think link.exe isn't smart enought without that support.

jwasm/hjwasm may have that feature?

gcc option -ffunction-sections
Title: Re: interesting discovery
Post by: hutch-- on September 21, 2016, 12:11:17 PM
james,

As far as I can tell there is no trick to do this, if a module is in a library, if its not called its not added but if you either bundle modules together or have unused code in the main source it will be added to the EXE, used or not.
Title: Re: interesting discovery
Post by: TWell on September 21, 2016, 04:32:13 PM
Those functions have to be in separated object module and compiled with -Gy
, but data still goes to exe/dll as -Gy is for code only.
Try to split main and functions code to different files.

Sadly PellesC don't have that compiler option :(
Title: Re: interesting discovery
Post by: jcfuller on September 21, 2016, 09:18:40 PM
Tim,
  Thank you very much for your insight.
The results I am seeing is because all the code was in the same source file. This is for VC only.
If I split out the functions to another source file and #include them they are included in the exe.

Your link did not work for me but I did find the info for /Gy on msdn along with a link to:
https://msdn.microsoft.com/en-us/library/bxwfs976.aspx
where it states that /OPT:REF is the default.

I also compiled all the functions  using /Gy and linked the obj file to the main file. Only the F1 function that was called was included in the exe.

Now, why would one NOT use /Gy ? Are there any gotcha's with it??
Is this common knowledge among vc coders that I missed in my education?

James
Title: Re: interesting discovery
Post by: TWell on September 21, 2016, 09:35:42 PM
Thanks James.

With -Gy it works on one file too.
The map file shows it.