"Stephen Sprunk" wrote:
>"Joris Dolderer" wrote:
>I want to compile and link a program statically against the dietlibc. Of
course, the dietlibc includes functions my program never needs. Is there
any way to throw them out of the final executable? Is there maybe a
program that cuts them away from the source code of the dietlibc?
...
Any decent, modern linker will do exactly what you ask when statically
linking. If yours doesn't, replace it.
Not exactly that. In every C environment I have worked on, the
granularity of the units that the linker can extract from a library is
quite coarse: "translation units"
All object code generated from the compilation of a single source file
is "atomic" as far as the linker is concerned, and must be included in
its totality in the final executable if a single reference is resolved
from that object code.
And, of course, a single file may contain more than one function, and
some of them may not be used.
The only way I know to force a "vanilla" linker to do this, is by
splitting the source code into one file per function before creating
the library. (I had to do some maintenance work on a project that did
just that, and the huge number of source files turned it into an
unmanageable mess.)
Even then, global variables can still create unwanted dependencies
between object modules.
To the OP: There are code analysis tool (I am using PC-Lint) that will
provide a list of unused functions and variables. It may be possible
to use it to drive other tools to remove these unused functions from
the source files (or surround them with #ifdef...#endif,) creating a
customized version of the library that includes no more than what is
actually used. (Hopefully no less either, it may be difficult to know
if a function is called indirectly.)
The details would be, of course, platform specific.
Roberto Waltman
[ Please reply to the group,
return address is invalid ]