r339304 | emaste | 2018-10-11 15:19:17 +0200 (Thu, 11 Oct 2018) | 13 lines lld: set sh_link and sh_info for .rela.plt sections ELF spec says that for SHT_REL and SHT_RELA sh_link should reference the associated string table and sh_info should reference the "section to which the relocation applies." ELF Tool Chain's elfcopy / strip use this (in part) to control whether or not the relocation entry is copied to the output. LLVM PR 37538 https://bugs.llvm.org/show_bug.cgi?id=37538 Approved by: re (kib) Obtained from: llvm r344226 (backported for 6.0) Index: tools/lld/ELF/SyntheticSections.cpp =================================================================== --- tools/lld/ELF/SyntheticSections.cpp (revision 339303) +++ tools/lld/ELF/SyntheticSections.cpp (revision 339304) @@ -1213,11 +1213,13 @@ void RelocationBaseSection::addReloc(const Dynamic void RelocationBaseSection::finalizeContents() { // If all relocations are R_*_RELATIVE they don't refer to any // dynamic symbol and we don't need a dynamic symbol table. If that - // is the case, just use 0 as the link. - Link = InX::DynSymTab ? InX::DynSymTab->getParent()->SectionIndex : 0; + // is the case, just use the index of the regular symbol table section. + getParent()->Link = InX::DynSymTab ? + InX::DynSymTab->getParent()->SectionIndex : + InX::SymTab->getParent()->SectionIndex; - // Set required output section properties. - getParent()->Link = Link; + if (InX::RelaIplt == this || InX::RelaPlt == this) + getParent()->Info = InX::GotPlt->getParent()->SectionIndex; } RelrBaseSection::RelrBaseSection()