[gold] Relocation data handling for comdat sections when doing a relocatable link

Artemiy Volkov artemiyv@acm.org
Mon Nov 28 10:23:00 GMT 2016


Hi all,

I've stumbled upon an issue when linking a lot of C++ template-heavy
code into a single library with gold. To ensure that there's only one
copy of each text section corresponding to an instantiation of a
template function, it uses the comdat section mechanism, which is
handled just fine for regular linking in relocate_section().

However, for relocatable linking it uses scan_relocatable_relocs() +
relocate_relocs(). AFAICT, scan_relocatable_relocs() is simply setting
relocation strategy to RELOC_DISCARD for every relocation that refers
to a section that's being discarded, and that's a problem for every
comdat section except those whose contents end up being included in
the output file. This way lots of relocations in the debug sections
are discarded instead of adjusted and the debug information becomes
unreliable.

Is this a known problem? Or might I be doing something wrong?

Thanks,
Artemiy



More information about the Binutils mailing list