Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -279,7 +279,7 @@ // so that it points to an absolute address which is relative to GOT. // See "Global Data Symbols" in Chapter 6 in the following document: // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf - Symtab.addAbsolute("_gp", DefinedAbsolute::MipsGp); + Symtab.addAbsolute("_gp", DefinedRegular::MipsGp); } for (std::unique_ptr &F : Files) Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -65,7 +65,8 @@ if (Index == ELF::SHN_XINDEX) Index = this->ELFObj.getExtendedSymbolTableIndex(&Sym, this->Symtab, SymtabSHNDX); - else if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE) + else if (Index == ELF::SHN_UNDEF || Index == ELF::SHN_ABS || + Index >= ELF::SHN_LORESERVE) return 0; if (!Index) @@ -274,8 +275,6 @@ StringRef Name = *NameOrErr; switch (Sym->st_shndx) { - case SHN_ABS: - return new (this->Alloc) DefinedAbsolute(Name, *Sym); case SHN_UNDEF: return new (this->Alloc) UndefinedElf(Name, *Sym); case SHN_COMMON: @@ -291,7 +290,7 @@ InputSectionBase *Sec = getSection(*Sym); if (Sec == &InputSection::Discarded) return new (this->Alloc) UndefinedElf(Name, *Sym); - return new (this->Alloc) DefinedRegular(Name, *Sym, *Sec); + return new (this->Alloc) DefinedRegular(Name, *Sym, Sec); } } } Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -71,7 +71,7 @@ uint32_t SymIndex = Rel.getSymbol(Config->Mips64EL); if (SymbolBody *B = File->getSymbolBody(SymIndex)) if (auto *D = dyn_cast>(B->repl())) - return &D->Section; + return D->Section; // Local symbol if (const Elf_Sym *Sym = File->getLocalSymbol(SymIndex)) if (InputSectionBase *Sec = File->getSection(*Sym)) Index: ELF/MarkLive.cpp =================================================================== --- ELF/MarkLive.cpp +++ ELF/MarkLive.cpp @@ -89,7 +89,7 @@ auto MarkSymbol = [&](SymbolBody *Sym) { if (Sym) if (auto *D = dyn_cast>(Sym->repl())) - Enqueue(&D->Section); + Enqueue(D->Section); }; // Add GC root symbols. Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -789,15 +789,15 @@ auto &D = cast>(S); return D.Section.getVA() + D.Value; } - case SymbolBody::DefinedAbsoluteKind: - return cast>(S).Sym.st_value; case SymbolBody::DefinedRegularKind: { const auto &DR = cast>(S); - InputSectionBase &SC = DR.Section; + InputSectionBase *SC = DR.Section; + if (!SC) + return DR.Sym.st_value; if (DR.Sym.getType() == STT_TLS) - return SC.OutSec->getVA() + SC.getOffset(DR.Sym) - + return SC->OutSec->getVA() + SC->getOffset(DR.Sym) - Out::TlsPhdr->p_vaddr; - return SC.OutSec->getVA() + SC.getOffset(DR.Sym); + return SC->OutSec->getVA() + SC->getOffset(DR.Sym); } case SymbolBody::DefinedCommonKind: return Out::Bss->getVA() + cast>(S).OffsetInBSS; @@ -1341,9 +1341,11 @@ break; case SymbolBody::DefinedRegularKind: { auto *Sym = cast>(Body->repl()); - if (!Sym->Section.isLive()) - continue; - OutSec = Sym->Section.OutSec; + if (InputSectionBase *Sec = Sym->Section) { + if (!Sec->isLive()) + continue; + OutSec = Sec->OutSec; + } break; } case SymbolBody::DefinedCommonKind: @@ -1356,7 +1358,6 @@ } case SymbolBody::UndefinedElfKind: case SymbolBody::UndefinedKind: - case SymbolBody::DefinedAbsoluteKind: case SymbolBody::LazyKind: break; } @@ -1376,10 +1377,10 @@ ESym->setVisibility(Body->getVisibility()); ESym->st_value = getSymVA(*Body); - if (isa>(Body)) - ESym->st_shndx = SHN_ABS; - else if (OutSec) + if (OutSec) ESym->st_shndx = OutSec->SectionIndex; + else if (isa>(Body)) + ESym->st_shndx = SHN_ABS; ++ESym; } Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -95,7 +95,7 @@ template void SymbolTable::addAbsolute(StringRef Name, typename ELFFile::Elf_Sym &ESym) { - resolve(new (Alloc) DefinedAbsolute(Name, ESym)); + resolve(new (Alloc) DefinedRegular(Name, ESym, nullptr)); } template @@ -109,7 +109,7 @@ template SymbolBody *SymbolTable::addIgnored(StringRef Name) { auto *Sym = new (Alloc) - DefinedAbsolute(Name, DefinedAbsolute::IgnoreUndef); + DefinedRegular(Name, DefinedRegular::IgnoreUndef, nullptr); resolve(Sym); return Sym; } Index: ELF/Symbols.h =================================================================== --- ELF/Symbols.h +++ ELF/Symbols.h @@ -57,7 +57,6 @@ enum Kind { DefinedFirst, DefinedRegularKind = DefinedFirst, - DefinedAbsoluteKind, DefinedCommonKind, SharedKind, DefinedElfLast = SharedKind, @@ -131,7 +130,7 @@ Symbol *Backref = nullptr; }; -// The base class for any defined symbols, including absolute symbols, etc. +// The base class for any defined symbols. class Defined : public SymbolBody { public: Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility, bool IsTls); @@ -155,50 +154,6 @@ } }; -template class DefinedAbsolute : public DefinedElf { - typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; - -public: - static Elf_Sym IgnoreUndef; - - // The following symbols must be added early to reserve their places - // in symbol tables. The value of the symbols are set when all sections - // are finalized and their addresses are determined. - - // The content for _end and end symbols. - static Elf_Sym End; - - // The content for _gp symbol for MIPS target. - static Elf_Sym MipsGp; - - // __rel_iplt_start/__rel_iplt_end for signaling - // where R_[*]_IRELATIVE relocations do live. - static Elf_Sym RelaIpltStart; - static Elf_Sym RelaIpltEnd; - - DefinedAbsolute(StringRef N, const Elf_Sym &Sym) - : DefinedElf(SymbolBody::DefinedAbsoluteKind, N, Sym) {} - - static bool classof(const SymbolBody *S) { - return S->kind() == SymbolBody::DefinedAbsoluteKind; - } -}; - -template -typename DefinedAbsolute::Elf_Sym DefinedAbsolute::IgnoreUndef; - -template -typename DefinedAbsolute::Elf_Sym DefinedAbsolute::End; - -template -typename DefinedAbsolute::Elf_Sym DefinedAbsolute::MipsGp; - -template -typename DefinedAbsolute::Elf_Sym DefinedAbsolute::RelaIpltStart; - -template -typename DefinedAbsolute::Elf_Sym DefinedAbsolute::RelaIpltEnd; - template class DefinedCommon : public DefinedElf { typedef typename llvm::object::ELFFile::Elf_Sym Elf_Sym; @@ -227,7 +182,7 @@ public: DefinedRegular(StringRef N, const Elf_Sym &Sym, - InputSectionBase &Section) + InputSectionBase *Section) : DefinedElf(SymbolBody::DefinedRegularKind, N, Sym), Section(Section) {} @@ -235,9 +190,41 @@ return S->kind() == SymbolBody::DefinedRegularKind; } - InputSectionBase &Section; + InputSectionBase *Section; + + static Elf_Sym IgnoreUndef; + + // The following symbols must be added early to reserve their places + // in symbol tables. The value of the symbols are set when all sections + // are finalized and their addresses are determined. + + // The content for _end and end symbols. + static Elf_Sym End; + + // The content for _gp symbol for MIPS target. + static Elf_Sym MipsGp; + + // __rel_iplt_start/__rel_iplt_end for signaling + // where R_[*]_IRELATIVE relocations do live. + static Elf_Sym RelaIpltStart; + static Elf_Sym RelaIpltEnd; }; +template +typename DefinedRegular::Elf_Sym DefinedRegular::IgnoreUndef; + +template +typename DefinedRegular::Elf_Sym DefinedRegular::End; + +template +typename DefinedRegular::Elf_Sym DefinedRegular::MipsGp; + +template +typename DefinedRegular::Elf_Sym DefinedRegular::RelaIpltStart; + +template +typename DefinedRegular::Elf_Sym DefinedRegular::RelaIpltEnd; + // DefinedSynthetic is a class to represent linker-generated ELF symbols. // The difference from the regular symbol is that DefinedSynthetic symbols // don't belong to any input files or sections. Thus, its constructor Index: ELF/Symbols.cpp =================================================================== --- ELF/Symbols.cpp +++ ELF/Symbols.cpp @@ -113,9 +113,9 @@ } template static void doInitSymbols() { - DefinedAbsolute::End.setBinding(STB_GLOBAL); - DefinedAbsolute::IgnoreUndef.setBinding(STB_WEAK); - DefinedAbsolute::IgnoreUndef.setVisibility(STV_HIDDEN); + DefinedRegular::End.setBinding(STB_GLOBAL); + DefinedRegular::IgnoreUndef.setBinding(STB_WEAK); + DefinedRegular::IgnoreUndef.setVisibility(STV_HIDDEN); } void lld::elf2::initSymbols() { Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -591,9 +591,9 @@ Symtab.addAbsolute(Name, Sym); }; AddMarker(IsRela ? "__rela_iplt_start" : "__rel_iplt_start", - DefinedAbsolute::RelaIpltStart); + DefinedRegular::RelaIpltStart); AddMarker(IsRela ? "__rela_iplt_end" : "__rel_iplt_end", - DefinedAbsolute::RelaIpltEnd); + DefinedRegular::RelaIpltEnd); } template static bool includeInSymtab(const SymbolBody &B) { @@ -601,8 +601,8 @@ return false; // Don't include synthetic symbols like __init_array_start in every output. - if (auto *U = dyn_cast>(&B)) - if (&U->Sym == &DefinedAbsolute::IgnoreUndef) + if (auto *U = dyn_cast>(&B)) + if (&U->Sym == &DefinedRegular::IgnoreUndef) return false; return true; @@ -727,14 +727,14 @@ // So, if this symbol is referenced, we just add the placeholder here // and update its value later. if (Symtab.find("_end")) - Symtab.addAbsolute("_end", DefinedAbsolute::End); + Symtab.addAbsolute("_end", DefinedRegular::End); // If there is an undefined symbol "end", we should initialize it // with the same value as "_end". In any other case it should stay intact, // because it is an allowable name for a user symbol. if (SymbolBody *B = Symtab.find("end")) if (B->isUndefined()) - Symtab.addAbsolute("end", DefinedAbsolute::End); + Symtab.addAbsolute("end", DefinedRegular::End); // Scan relocations. This must be done after every symbol is declared so that // we can correctly decide if a dynamic relocation is needed. @@ -1039,20 +1039,20 @@ // Update "_end" and "end" symbols so that they // point to the end of the data segment. - DefinedAbsolute::End.st_value = VA; + DefinedRegular::End.st_value = VA; // Update __rel_iplt_start/__rel_iplt_end to wrap the // rela.plt section. if (Out::RelaPlt) { uintX_t Start = Out::RelaPlt->getVA(); - DefinedAbsolute::RelaIpltStart.st_value = Start; - DefinedAbsolute::RelaIpltEnd.st_value = + DefinedRegular::RelaIpltStart.st_value = Start; + DefinedRegular::RelaIpltEnd.st_value = Start + Out::RelaPlt->getSize(); } // Update MIPS _gp absolute symbol so that it points to the static data. if (Config->EMachine == EM_MIPS) - DefinedAbsolute::MipsGp.st_value = getMipsGpAddr(); + DefinedRegular::MipsGp.st_value = getMipsGpAddr(); } // Returns the number of PHDR entries.