I have an executable which links to a big .a archive that contains lots of functions. The executable only uses a small fraction of the functions in this archive, but for some reason it pulls everything from it and ends up being very big.
My suspicion is that some of the functionality that the executable is using somehow references something it shouldn't and that causes everything else to be pulled.
Is it possible to make gcc tell me what reference causes a specific symbol to be added in the executable? Why else can this happen?
I've tried using --gc-sections
with no effect.
I've tried using --version-script
to make all the symbols in the executable local with no effect
I'm not interested in -ffunction-sections
and -fdata-sections
since it is while object files I want to discard, not functions.
Other answers mention -why_live
but that seem to be implemented only for darwin and I am in linux x86_64
Use -Wl,-M
to pass -M
to the linker, causing it to print a link trace. This will show you the reasons (or at least the first-found reason) for every object file that gets linked from an archive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With