GCC: how to find why the object file is not discarded

I have an executable that links to a large .a archive that contains many functions. The executable file uses only a small part of the functions in this archive, but for some reason it extracts everything from it and becomes very large.
My suspicion is that some of the functions that the executable uses are somehow referencing that it should not, and this causes everything else to stretch.
Is it possible for gcc to tell me which link causes a particular character to be added to the executable? Why else could this happen?

I tried using --gc-sections with no effect.
I tried using --version-script to make all characters in local executable without effect. I'm not interested in -ffunction-sections and -fdata-sections , since this is while the object files I want to drop, not the functions.
Other answers mention -why_live , but it seems that they are implemented only for darwin, and I on Linux x86_64

+8
c ++ c gcc linker ld
source share
1 answer

Use -Wl,-M to pass -M to the linker, forcing it to print the link trace. This will show you the reasons (or at least the root causes) for each object file that is associated with the archive.

+4
source share

All Articles