diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index f094be5f6f2d..00cc0127a173 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -142,12 +142,8 @@ uint64_t SectionBase::getOffset(uint64_t Offset) const { return Offset == uint64_t(-1) ? OS->Size : Offset; } case Regular: + case Synthetic: return cast(this->Repl)->OutSecOff + Offset; - case Synthetic: { - auto *IS = cast(this->Repl); - // For synthetic sections we treat offset -1 as the end of the section. - return IS->OutSecOff + (Offset == uint64_t(-1) ? IS->getSize() : Offset); - } case EHFrame: // The file crtbeginT.o has relocations pointing to the start of an empty // .eh_frame that is known to be the first in the link. It does that to diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 199640097814..5dfc22583958 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -38,6 +38,7 @@ Defined *ElfSym::GlobalOffsetTable; Defined *ElfSym::MipsGp; Defined *ElfSym::MipsGpDisp; Defined *ElfSym::MipsLocalGp; +Defined *ElfSym::RelaIpltEnd; static uint64_t getSymVA(const Symbol &Sym, int64_t &Addend) { switch (Sym.kind()) { diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 5f4c79251b85..69e943f34e8c 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -315,6 +315,9 @@ struct ElfSym { static Defined *MipsGp; static Defined *MipsGpDisp; static Defined *MipsLocalGp; + + // __rela_iplt_end or __rel_iplt_end + static Defined *RelaIpltEnd; }; // A buffer class that is large enough to hold any Symbol-derived diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 27669f9b855a..ae5b580cc9b6 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -853,7 +853,8 @@ template void Writer::addRelIpltSymbols() { addOptionalRegular(S, InX::RelaIplt, 0, STV_HIDDEN, STB_WEAK); S = Config->IsRela ? "__rela_iplt_end" : "__rel_iplt_end"; - addOptionalRegular(S, InX::RelaIplt, -1, STV_HIDDEN, STB_WEAK); + ElfSym::RelaIpltEnd = + addOptionalRegular(S, InX::RelaIplt, 0, STV_HIDDEN, STB_WEAK); } template @@ -886,6 +887,9 @@ template void Writer::setReservedSymbolSections() { ElfSym::GlobalOffsetTable->Section = GotSection; } + if (ElfSym::RelaIpltEnd) + ElfSym::RelaIpltEnd->Value = InX::RelaIplt->getSize(); + PhdrEntry *Last = nullptr; PhdrEntry *LastRO = nullptr;