ld: --gc-sections incompatible with --emit-relocs ?
Fri Oct 13 01:18:00 GMT 2006
> After some tests, it appears that I also specify --emit-relocs on the
> linker line, and removing this --emit-relocs causes --gc-sections to
> work as expected.
> Is any of you aware of such a limitation ?
Yes. The problem is that if relocations are being emitted, then the
linker cannot safely discard sections. This is because the linker does
not know why the relocations are being emitted, so it cannot tell if the
relocations associated with (potentially) garbage collected sections
should be emitted or not.
> I did not find any reference in the manual.
True, this should be documented. I will fix that.
> I would appreciate any hints on how to try to remove/workaround this
You would need to add extra code to the linker. Probably a new command
line switch to tell the linker to aggressively garbage collect sections.
You will need to make sure that any section that is removed in this
way also has any relocations associated with it removed from its
equivalent *.rel or *.rela section. (Or at least not emitted when the
other relocs are emitted).
More information about the Binutils