diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 22470c107aca..0565f36a5611 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -215,6 +215,14 @@ RelocationSection::RelocationSection(StringRef Name, bool IsRela) this->Header.sh_addralign = sizeof(uintX_t); } +template +void RelocationSection::addReloc(const DynamicReloc &Reloc) { + SymbolBody *Sym = Reloc.Sym; + if (!Reloc.UseSymVA && Sym) + Sym->setUsedInDynamicReloc(); + Relocs.push_back(Reloc); +} + template static typename ELFFile::uintX_t getOffset(const DynamicReloc &Rel) { diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 8251de8a60fc..ffb338625e6a 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -255,7 +255,7 @@ class RelocationSection final : public OutputSectionBase { public: RelocationSection(StringRef Name, bool IsRela); - void addReloc(const DynamicReloc &Reloc) { Relocs.push_back(Reloc); } + void addReloc(const DynamicReloc &Reloc); unsigned getRelocOffset(); void finalize() override; void writeTo(uint8_t *Buf) override; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index f41c5d3f892a..fa80226af145 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -235,7 +235,6 @@ static bool handleTlsRelocation(unsigned Type, SymbolBody *Body, {Target->TlsModuleIndexRel, DynamicReloc::Off_GTlsIndex, Body}); Out::RelaDyn->addReloc( {Target->TlsOffsetRel, DynamicReloc::Off_GTlsOffset, Body}); - Body->setUsedInDynamicReloc(); return true; } if (!canBePreempted(Body, true)) @@ -306,7 +305,6 @@ void Writer::scanRelocs( continue; if (Target->needsCopyRel(Type, *B)) { B->NeedsCopy = true; - B->setUsedInDynamicReloc(); Out::RelaDyn->addReloc( {Target->CopyRel, DynamicReloc::Off_Bss, B}); continue; @@ -317,7 +315,6 @@ void Writer::scanRelocs( // to the symbol go through the PLT. This is true even for a local // symbol, although local symbols normally do not require PLT entries. if (Body && isGnuIFunc(*Body)) { - Body->setUsedInDynamicReloc(); if (Body->isInGot()) continue; Out::Plt->addEntry(Body); @@ -354,9 +351,6 @@ void Writer::scanRelocs( Out::RelaDyn->addReloc( {Target->GotRel, DynamicReloc::Off_Got, Body}); } - - if (canBePreempted(Body, /*NeedsGot=*/true)) - Body->setUsedInDynamicReloc(); continue; } @@ -372,6 +366,7 @@ void Writer::scanRelocs( // See "Global Offset Table" in Chapter 5 in the following document // for detailed description: // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf + // FIXME: Why do we need to set this here? Body->setUsedInDynamicReloc(); continue; } @@ -379,8 +374,6 @@ void Writer::scanRelocs( bool CBP = canBePreempted(Body, /*NeedsGot=*/true); bool Dynrel = Config->Shared && !Target->isRelRelative(Type) && !Target->isSizeRel(Type); - if (CBP) - Body->setUsedInDynamicReloc(); if (CBP || Dynrel) { uint32_t DynType; if (CBP) @@ -413,7 +406,6 @@ void Writer::scanRelocs( if (canBePreempted(Body, /*NeedsGot=*/false)) { // We don't know anything about the finaly symbol. Just ask the dynamic // linker to handle the relocation for us. - Body->setUsedInDynamicReloc(); Out::RelaDyn->addReloc({Target->getDynRel(Type), &C, RI.r_offset, false, Body, getAddend(RI)}); continue;