Lib change leads to larger executables

Sean Kelly sean at f4.ca
Wed Feb 21 11:27:39 PST 2007


Walter Bright wrote:
>> 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.

For some reason I thought an optimizing linker worked at a segment 
level, but I suppose that is not true for data in a library?  In other 
words, since libraries are indexed by module name, I suppose this means 
they are necessarily dealt with at module granularity instead?



More information about the Digitalmars-d mailing list