Lib change leads to larger executables

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Feb 22 09:22:32 PST 2007


janderson wrote:
> kris wrote:
> [snip]
>> 7) These fake dependencies are responsible for, in this case, the 
>> entire "locale" package to be bound to the example app, resulting in a 
>> 350% increase in size.
> [snip]
> 
> Is it not possible to have a tool which strips the executable of dead 
> code after its finished, using an external tool?

Presumably this would leave static constructors/destructors intact? If 
not, you'll have some problems with code that depends on them.

Now, assuming you do: tango.text.locale.Core contains 3 static 
constructors and a static destructor. The static destructor sets some 
variables to null, but the static constructors do a bit more. One of 
them directly allocates some class instances. That pulls in the vtable 
for that class, which in turn pulls in all virtual member functions. 
Those instantiate at least two other classes (not counting Exception)...

This kind of stuff can easily cascade into a lot of code, all because a 
single module got pulled in and its static constructors get called.

So all is not as simple as it seems, unfortunately. To get this 
right[1], you'd basically have to do the dependency analysis all over 
again. You might as well have the linker get it right the first time...
(IMHO, to get it to do that without requiring a special linker and/or 
object format, the compiler needs to somehow make sure the linker won't 
pick the wrong object file to link to)


[1]: i.e. don't include unnecessary code, but also include all code that 
_is_ necessary.



More information about the Digitalmars-d mailing list