Lib change leads to larger executables

Walter Bright newshound at digitalmars.com
Wed Feb 21 01:00:44 PST 2007


> It does, but increases the exe size of the first example from 180kb to 617kb!
 > 180kb is when compiled using build/rebuild/jake etc (no library) and 
the 617kb
 > is when using dmd+lib only. Same flags in both cases: none at all

Let's say you have a template instance, TI. It is declared in two 
modules, M1 and M2:

-----------M1------------
TI
A
-----------M2------------
TI
B
-------------------------

M1 also declares A, and M2 also declares B. Now, the linker is looking 
to resolve TI, and the first one it finds is one in M1, and so links in 
M1. Later on, it needs to resolve B, and so links in M2. The redundant 
TI is discarded (because it's a COMDAT).

However, suppose the program never references A, and A is a chunk of 
code that pulls in lots of other bloat. This could make the executable 
much larger than if, in resolving TI, it had picked M2 instead.

You can control which module containing TI will be pulled in by the 
linker to resolve TI, by specifying that module first to lib.exe.

You can also put TI in a third module that has neither A nor B in it. 
When compiling M1 and M2, import that third module, so TI won't be 
generated for M1 or M2.



More information about the Digitalmars-d mailing list