Index: ELF/InputFiles.cpp =================================================================== --- ELF/InputFiles.cpp +++ ELF/InputFiles.cpp @@ -357,9 +357,9 @@ // we see. The eglibc ARM dynamic loaders require the presence of an // attribute section for dlopen to work. // In a full implementation we would merge all attribute sections. - if (In::ARMAttributes == nullptr) { - In::ARMAttributes = make(this, &Sec, Name); - return In::ARMAttributes; + if (In::ARMAttributes == nullptr) { + In::ARMAttributes = make(this, &Sec, Name); + return In::ARMAttributes; } return &InputSection::Discarded; case SHT_RELA: Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -252,7 +252,7 @@ // section, but for --emit-relocs it is an virtual address. P->r_offset = RelocatedSection->OutSec->Addr + RelocatedSection->getOffset(Rel.r_offset); - P->setSymbolAndType(In::SymTab->getSymbolIndex(&Body), Type, + P->setSymbolAndType(In::X::SymTab->getSymbolIndex(&Body), Type, Config->isMips64EL()); if (Body.Type == STT_SECTION) { @@ -328,20 +328,20 @@ case R_TLSDESC_CALL: llvm_unreachable("cannot relocate hint relocs"); case R_TLSLD: - return In::Got->getTlsIndexOff() + A - In::Got->getSize(); + return In::X::Got->getTlsIndexOff() + A - In::X::Got->getSize(); case R_TLSLD_PC: - return In::Got->getTlsIndexVA() + A - P; + return In::X::Got->getTlsIndexVA() + A - P; case R_PPC_TOC: return getPPC64TocBase() + A; case R_TLSGD: - return In::Got->getGlobalDynOffset(Body) + A - - In::Got->getSize(); + return In::X::Got->getGlobalDynOffset(Body) + A - + In::X::Got->getSize(); case R_TLSGD_PC: - return In::Got->getGlobalDynAddr(Body) + A - P; + return In::X::Got->getGlobalDynAddr(Body) + A - P; case R_TLSDESC: - return In::Got->getGlobalDynAddr(Body) + A; + return In::X::Got->getGlobalDynAddr(Body) + A; case R_TLSDESC_PAGE: - return getAArch64Page(In::Got->getGlobalDynAddr(Body) + A) - + return getAArch64Page(In::X::Got->getGlobalDynAddr(Body) + A) - getAArch64Page(P); case R_PLT: return Body.getPltVA() + A; @@ -351,13 +351,13 @@ case R_SIZE: return Body.getSize() + A; case R_GOTREL: - return Body.getVA(A) - In::Got->getVA(); + return Body.getVA(A) - In::X::Got->getVA(); case R_GOTREL_FROM_END: - return Body.getVA(A) - In::Got->getVA() - - In::Got->getSize(); + return Body.getVA(A) - In::X::Got->getVA() - + In::X::Got->getSize(); case R_RELAX_TLS_GD_TO_IE_END: case R_GOT_FROM_END: - return Body.getGotOffset() + A - In::Got->getSize(); + return Body.getGotOffset() + A - In::X::Got->getSize(); case R_RELAX_TLS_GD_TO_IE_ABS: case R_GOT: return Body.getGotVA() + A; @@ -368,9 +368,9 @@ case R_GOT_PC: return Body.getGotVA() + A - P; case R_GOTONLY_PC: - return In::Got->getVA() + A - P; + return In::X::Got->getVA() + A - P; case R_GOTONLY_PC_FROM_END: - return In::Got->getVA() + A - P + In::Got->getSize(); + return In::X::Got->getVA() + A - P + In::X::Got->getSize(); case R_RELAX_TLS_LD_TO_LE: case R_RELAX_TLS_IE_TO_LE: case R_RELAX_TLS_GD_TO_LE: @@ -399,26 +399,29 @@ // If relocation against MIPS local symbol requires GOT entry, this entry // should be initialized by 'page address'. This address is high 16-bits // of sum the symbol's value and the addend. - return In::MipsGot->getVA() + - In::MipsGot->getPageEntryOffset(Body, A) - - In::MipsGot->getGp(); + return In::X::MipsGot->getVA() + + In::X::MipsGot->getPageEntryOffset(Body, A) - + In::X::MipsGot->getGp(); case R_MIPS_GOT_OFF: case R_MIPS_GOT_OFF32: // In case of MIPS if a GOT relocation has non-zero addend this addend // should be applied to the GOT entry content not to the GOT entry offset. // That is why we use separate expression type. - return In::MipsGot->getVA() + - In::MipsGot->getBodyEntryOffset(Body, A) - - In::MipsGot->getGp(); + return In::X::MipsGot->getVA() + + In::X::MipsGot->getBodyEntryOffset(Body, A) - + In::X::MipsGot->getGp(); case R_MIPS_GOTREL: - return Body.getVA(A) - In::MipsGot->getGp(); + return Body.getVA(A) - In::X::MipsGot->getGp(); case R_MIPS_TLSGD: - return In::MipsGot->getVA() + In::MipsGot->getTlsOffset() + - In::MipsGot->getGlobalDynOffset(Body) - - In::MipsGot->getGp(); + return In::X::MipsGot->getVA() + + In::X::MipsGot->getTlsOffset() + + In::X::MipsGot->getGlobalDynOffset(Body) - + In::X::MipsGot->getGp(); case R_MIPS_TLSLD: - return In::MipsGot->getVA() + In::MipsGot->getTlsOffset() + - In::MipsGot->getTlsIndexOff() - In::MipsGot->getGp(); + return In::X::MipsGot->getVA() + + In::X::MipsGot->getTlsOffset() + + In::X::MipsGot->getTlsIndexOff() - + In::X::MipsGot->getGp(); case R_PPC_OPD: { uint64_t SymVA = Body.getVA(A); // If we have an undefined weak symbol, we might get here with a symbol Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -297,7 +297,7 @@ void LinkerScript::discard(ArrayRef V) { for (InputSectionBase *S : V) { S->Live = false; - if (S == In::ShStrTab) + if (S == In::X::ShStrTab) error("discarding .shstrtab section is not allowed"); discard(S->DependentSections); } Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -107,7 +107,7 @@ if (isa(First)) return; - this->Link = In::SymTab->OutSec->SectionIndex; + this->Link = In::X::SymTab->OutSec->SectionIndex; // sh_info for SHT_REL[A] sections should contain the section header index of // the section to which the relocation applies. InputSectionBase *S = First->getRelocatedSection(); Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -106,7 +106,7 @@ {R_ABS, Target->TlsModuleIndexRel, Off, 0, &Body}); else { SymbolBody *Dest = LD ? nullptr : &Body; - In::RelaDyn->addReloc( + In::X::RelaDyn->addReloc( {Target->TlsModuleIndexRel, Got, Off, false, Dest, 0}); } }; @@ -122,9 +122,9 @@ uintX_t Off = Got->getGlobalDynOffset(Body); addModuleReloc(Body, Got, Off, false); if (Body.isPreemptible()) - In::RelaDyn->addReloc({Target->TlsOffsetRel, Got, - Off + (uintX_t)sizeof(uintX_t), false, - &Body, 0}); + In::X::RelaDyn->addReloc({Target->TlsOffsetRel, Got, + Off + (uintX_t)sizeof(uintX_t), false, + &Body, 0}); } C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); return 1; @@ -146,19 +146,19 @@ typedef typename ELFT::uint uintX_t; if (Config->EMachine == EM_ARM) - return handleNoRelaxTlsRelocation(In::Got, Type, Body, C, + return handleNoRelaxTlsRelocation(In::X::Got, Type, Body, C, Offset, Addend, Expr); if (Config->EMachine == EM_MIPS) - return handleNoRelaxTlsRelocation(In::MipsGot, Type, Body, C, + return handleNoRelaxTlsRelocation(In::X::MipsGot, Type, Body, C, Offset, Addend, Expr); bool IsPreemptible = isPreemptible(Body, Type); if (isRelExprOneOf(Expr) && Config->Shared) { - if (In::Got->addDynTlsEntry(Body)) { - uintX_t Off = In::Got->getGlobalDynOffset(Body); - In::RelaDyn->addReloc({Target->TlsDescRel, In::Got, Off, - !IsPreemptible, &Body, 0}); + if (In::X::Got->addDynTlsEntry(Body)) { + uintX_t Off = In::X::Got->getGlobalDynOffset(Body); + In::X::RelaDyn->addReloc({Target->TlsDescRel, In::X::Got, Off, + !IsPreemptible, &Body, 0}); } if (Expr != R_TLSDESC_CALL) C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); @@ -172,10 +172,10 @@ {R_RELAX_TLS_LD_TO_LE, Type, Offset, Addend, &Body}); return 2; } - if (In::Got->addTlsIndex()) - In::RelaDyn->addReloc({Target->TlsModuleIndexRel, In::Got, - In::Got->getTlsIndexOff(), false, - nullptr, 0}); + if (In::X::Got->addTlsIndex()) + In::X::RelaDyn->addReloc( + {Target->TlsModuleIndexRel, In::X::Got, + In::X::Got->getTlsIndexOff(), false, nullptr, 0}); C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); return 1; } @@ -190,19 +190,21 @@ if (isRelExprOneOf(Expr) || Target->isTlsGlobalDynamicRel(Type)) { if (Config->Shared) { - if (In::Got->addDynTlsEntry(Body)) { - uintX_t Off = In::Got->getGlobalDynOffset(Body); - In::RelaDyn->addReloc( - {Target->TlsModuleIndexRel, In::Got, Off, false, &Body, 0}); + if (In::X::Got->addDynTlsEntry(Body)) { + uintX_t Off = In::X::Got->getGlobalDynOffset(Body); + In::X::RelaDyn->addReloc({Target->TlsModuleIndexRel, + In::X::Got, Off, false, &Body, + 0}); // If the symbol is preemptible we need the dynamic linker to write // the offset too. uintX_t OffsetOff = Off + (uintX_t)sizeof(uintX_t); if (IsPreemptible) - In::RelaDyn->addReloc({Target->TlsOffsetRel, In::Got, - OffsetOff, false, &Body, 0}); + In::X::RelaDyn->addReloc({Target->TlsOffsetRel, + In::X::Got, OffsetOff, false, + &Body, 0}); else - In::Got->Relocations.push_back( + In::X::Got->Relocations.push_back( {R_ABS, Target->TlsOffsetRel, OffsetOff, 0, &Body}); } C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); @@ -216,10 +218,10 @@ {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_GD_TO_IE), Type, Offset, Addend, &Body}); if (!Body.isInGot()) { - In::Got->addEntry(Body); - In::RelaDyn->addReloc({Target->TlsGotRel, In::Got, - Body.getGotOffset(), false, &Body, - 0}); + In::X::Got->addEntry(Body); + In::X::RelaDyn->addReloc({Target->TlsGotRel, In::X::Got, + Body.getGotOffset(), false, &Body, + 0}); } return Target->TlsGdRelaxSkip; } @@ -495,7 +497,7 @@ Sym->symbol()->IsUsedInRegularObj = true; } - In::RelaDyn->addReloc({Target->CopyRel, ISec, 0, false, SS, 0}); + In::X::RelaDyn->addReloc({Target->CopyRel, ISec, 0, false, SS, 0}); } template @@ -657,7 +659,7 @@ bool IsWrite = C.Flags & SHF_WRITE; auto AddDyn = [=](const DynamicReloc &Reloc) { - In::RelaDyn->addReloc(Reloc); + In::X::RelaDyn->addReloc(Reloc); }; const elf::ObjectFile *File = C.getFile(); @@ -722,7 +724,7 @@ // needs it to be created. Here we request for that. if (isRelExprOneOf(Expr)) - In::Got->HasGotOffRel = true; + In::X::Got->HasGotOffRel = true; int64_t Addend = computeAddend(*File, Buf, E, RI, Expr, Body); @@ -778,7 +780,7 @@ // a dynamic relocation. // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf p.4-19 if (Config->EMachine == EM_MIPS) - In::MipsGot->addEntry(Body, Addend, Expr); + In::X::MipsGot->addEntry(Body, Addend, Expr); continue; } @@ -791,17 +793,17 @@ continue; if (Body.isGnuIFunc() && !Preemptible) { - In::Iplt->addEntry(Body); - In::IgotPlt->addEntry(Body); - In::RelaIplt->addReloc({Target->IRelativeRel, In::IgotPlt, - Body.getGotPltOffset(), - !Preemptible, &Body, 0}); + In::X::Iplt->addEntry(Body); + In::X::IgotPlt->addEntry(Body); + In::X::RelaIplt->addReloc( + {Target->IRelativeRel, In::X::IgotPlt, + Body.getGotPltOffset(), !Preemptible, &Body, 0}); } else { - In::Plt->addEntry(Body); - In::GotPlt->addEntry(Body); - In::RelaPlt->addReloc({Target->PltRel, In::GotPlt, - Body.getGotPltOffset(), !Preemptible, - &Body, 0}); + In::X::Plt->addEntry(Body); + In::X::GotPlt->addEntry(Body); + In::X::RelaPlt->addReloc({Target->PltRel, In::X::GotPlt, + Body.getGotPltOffset(), + !Preemptible, &Body, 0}); } continue; } @@ -815,9 +817,9 @@ // 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 - In::MipsGot->addEntry(Body, Addend, Expr); + In::X::MipsGot->addEntry(Body, Addend, Expr); if (Body.isTls() && Body.isPreemptible()) - AddDyn({Target->TlsGotRel, In::MipsGot, + AddDyn({Target->TlsGotRel, In::X::MipsGot, Body.getGotOffset(), false, &Body, 0}); continue; } @@ -825,7 +827,7 @@ if (Body.isInGot()) continue; - In::Got->addEntry(Body); + In::X::Got->addEntry(Body); uintX_t Off = Body.getGotOffset(); uint32_t DynType; RelExpr GotRE = R_ABS; @@ -841,9 +843,10 @@ bool Constant = !Preemptible && !(Config->pic() && !isAbsolute(Body)); if (!Constant) - AddDyn({DynType, In::Got, Off, !Preemptible, &Body, 0}); + AddDyn({DynType, In::X::Got, Off, !Preemptible, &Body, 0}); if (Constant || (!RelTy::IsRela && !Preemptible)) - In::Got->Relocations.push_back({GotRE, DynType, Off, 0, &Body}); + In::X::Got->Relocations.push_back( + {GotRE, DynType, Off, 0, &Body}); continue; } } Index: ELF/Symbols.cpp =================================================================== --- ELF/Symbols.cpp +++ ELF/Symbols.cpp @@ -101,7 +101,7 @@ case SymbolBody::DefinedCommonKind: if (!Config->DefineCommon) return 0; - return In::Common->OutSec->Addr + In::Common->OutSecOff + + return In::Common->OutSec->Addr + In::Common->OutSecOff + cast(Body).Offset; case SymbolBody::SharedKind: { auto &SS = cast(Body); @@ -164,7 +164,7 @@ } template typename ELFT::uint SymbolBody::getGotVA() const { - return In::Got->getVA() + getGotOffset(); + return In::X::Got->getVA() + getGotOffset(); } template typename ELFT::uint SymbolBody::getGotOffset() const { @@ -173,8 +173,8 @@ template typename ELFT::uint SymbolBody::getGotPltVA() const { if (this->IsInIgot) - return In::IgotPlt->getVA() + getGotPltOffset(); - return In::GotPlt->getVA() + getGotPltOffset(); + return In::X::IgotPlt->getVA() + getGotPltOffset(); + return In::X::GotPlt->getVA() + getGotPltOffset(); } template typename ELFT::uint SymbolBody::getGotPltOffset() const { @@ -183,8 +183,8 @@ template typename ELFT::uint SymbolBody::getPltVA() const { if (this->IsInIplt) - return In::Iplt->getVA() + PltIndex * Target->PltEntrySize; - return In::Plt->getVA() + Target->PltHeaderSize + + return In::X::Iplt->getVA() + PltIndex * Target->PltEntrySize; + return In::X::Plt->getVA() + Target->PltHeaderSize + PltIndex * Target->PltEntrySize; } @@ -213,7 +213,7 @@ if (isa(this)) { if (Config->DefineCommon) - return In::Common->OutSec; + return In::Common->OutSec; return nullptr; } Index: ELF/SyntheticSections.h =================================================================== --- ELF/SyntheticSections.h +++ ELF/SyntheticSections.h @@ -760,65 +760,65 @@ uint64_t Size, InputSectionBase *Section); // Linker generated sections which can be used as inputs. -template struct In { +struct In { static InputSection *ARMAttributes; - static BuildIdSection *BuildId; static InputSection *Common; - static DynamicSection *Dynamic; - static StringTableSection *DynStrTab; - static SymbolTableSection *DynSymTab; - static EhFrameHeader *EhFrameHdr; - static GnuHashTableSection *GnuHashTab; - static GdbIndexSection *GdbIndex; - static GotSection *Got; - static EhFrameSection *EhFrame; - static MipsGotSection *MipsGot; - static GotPltSection *GotPlt; - static IgotPltSection *IgotPlt; - static HashTableSection *HashTab; static InputSection *Interp; - static MipsRldMapSection *MipsRldMap; - static PltSection *Plt; - static PltSection *Iplt; - static RelocationSection *RelaDyn; - static RelocationSection *RelaPlt; - static RelocationSection *RelaIplt; - static StringTableSection *ShStrTab; - static StringTableSection *StrTab; - static SymbolTableSection *SymTab; - static VersionDefinitionSection *VerDef; - static VersionTableSection *VerSym; - static VersionNeedSection *VerNeed; -}; - -template InputSection *In::ARMAttributes; -template BuildIdSection *In::BuildId; -template InputSection *In::Common; -template DynamicSection *In::Dynamic; -template StringTableSection *In::DynStrTab; -template SymbolTableSection *In::DynSymTab; -template EhFrameHeader *In::EhFrameHdr; -template GdbIndexSection *In::GdbIndex; -template GnuHashTableSection *In::GnuHashTab; -template GotSection *In::Got; -template EhFrameSection *In::EhFrame; -template MipsGotSection *In::MipsGot; -template GotPltSection *In::GotPlt; -template IgotPltSection *In::IgotPlt; -template HashTableSection *In::HashTab; -template InputSection *In::Interp; -template MipsRldMapSection *In::MipsRldMap; -template PltSection *In::Plt; -template PltSection *In::Iplt; -template RelocationSection *In::RelaDyn; -template RelocationSection *In::RelaPlt; -template RelocationSection *In::RelaIplt; -template StringTableSection *In::ShStrTab; -template StringTableSection *In::StrTab; -template SymbolTableSection *In::SymTab; -template VersionDefinitionSection *In::VerDef; -template VersionTableSection *In::VerSym; -template VersionNeedSection *In::VerNeed; + + template struct X { + static BuildIdSection *BuildId; + static DynamicSection *Dynamic; + static StringTableSection *DynStrTab; + static SymbolTableSection *DynSymTab; + static EhFrameHeader *EhFrameHdr; + static GnuHashTableSection *GnuHashTab; + static GdbIndexSection *GdbIndex; + static GotSection *Got; + static EhFrameSection *EhFrame; + static MipsGotSection *MipsGot; + static GotPltSection *GotPlt; + static IgotPltSection *IgotPlt; + static HashTableSection *HashTab; + static MipsRldMapSection *MipsRldMap; + static PltSection *Plt; + static PltSection *Iplt; + static RelocationSection *RelaDyn; + static RelocationSection *RelaPlt; + static RelocationSection *RelaIplt; + static StringTableSection *ShStrTab; + static StringTableSection *StrTab; + static SymbolTableSection *SymTab; + static VersionDefinitionSection *VerDef; + static VersionTableSection *VerSym; + static VersionNeedSection *VerNeed; + }; +}; + +template BuildIdSection *In::X::BuildId; +template DynamicSection *In::X::Dynamic; +template StringTableSection *In::X::DynStrTab; +template SymbolTableSection *In::X::DynSymTab; +template EhFrameHeader *In::X::EhFrameHdr; +template GdbIndexSection *In::X::GdbIndex; +template GnuHashTableSection *In::X::GnuHashTab; +template GotSection *In::X::Got; +template EhFrameSection *In::X::EhFrame; +template MipsGotSection *In::X::MipsGot; +template GotPltSection *In::X::GotPlt; +template IgotPltSection *In::X::IgotPlt; +template HashTableSection *In::X::HashTab; +template MipsRldMapSection *In::X::MipsRldMap; +template PltSection *In::X::Plt; +template PltSection *In::X::Iplt; +template RelocationSection *In::X::RelaDyn; +template RelocationSection *In::X::RelaPlt; +template RelocationSection *In::X::RelaIplt; +template StringTableSection *In::X::ShStrTab; +template StringTableSection *In::X::StrTab; +template SymbolTableSection *In::X::SymTab; +template VersionDefinitionSection *In::X::VerDef; +template VersionTableSection *In::X::VerSym; +template VersionNeedSection *In::X::VerNeed; } // namespace elf } // namespace lld Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -197,7 +197,7 @@ Options->size = getSize(); if (!Config->Relocatable) - Reginfo.ri_gp_value = In::MipsGot->getGp(); + Reginfo.ri_gp_value = In::X::MipsGot->getGp(); memcpy(Buf + sizeof(Elf_Mips_Options), &Reginfo, sizeof(Reginfo)); } @@ -255,7 +255,7 @@ template void MipsReginfoSection::writeTo(uint8_t *Buf) { if (!Config->Relocatable) - Reginfo.ri_gp_value = In::MipsGot->getGp(); + Reginfo.ri_gp_value = In::X::MipsGot->getGp(); memcpy(Buf, &Reginfo, sizeof(Reginfo)); } @@ -309,8 +309,8 @@ uint64_t Size, InputSectionBase *Section) { auto *S = make(Name, /*IsLocal*/ true, STV_DEFAULT, Type, Value, Size, Section, nullptr); - if (In::SymTab) - In::SymTab->addSymbol(S); + if (In::X::SymTab) + In::X::SymTab->addSymbol(S); return S; } @@ -607,13 +607,13 @@ // Construct .eh_frame_hdr. .eh_frame_hdr is a binary search table // to get a FDE from an address to which FDE is applied. So here // we obtain two addresses and pass them to EhFrameHdr object. - if (In::EhFrameHdr) { + if (In::X::EhFrameHdr) { for (CieRecord *Cie : Cies) { uint8_t Enc = getFdeEncoding(Cie->Piece); for (SectionPiece *Fde : Cie->FdePieces) { uintX_t Pc = getFdePc(Buf, Fde->OutputOff, Enc); uintX_t FdeVA = this->OutSec->Addr + Fde->OutputOff; - In::EhFrameHdr->addFde(Pc, FdeVA); + In::X::EhFrameHdr->addFde(Pc, FdeVA); } } } @@ -1044,15 +1044,15 @@ // Add strings to .dynstr early so that .dynstr's size will be // fixed early. for (StringRef S : Config->AuxiliaryList) - add({DT_AUXILIARY, In::DynStrTab->addString(S)}); + add({DT_AUXILIARY, In::X::DynStrTab->addString(S)}); if (!Config->RPath.empty()) add({Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH, - In::DynStrTab->addString(Config->RPath)}); + In::X::DynStrTab->addString(Config->RPath)}); for (SharedFile *F : Symtab::X->getSharedFiles()) if (F->isNeeded()) - add({DT_NEEDED, In::DynStrTab->addString(F->getSoName())}); + add({DT_NEEDED, In::X::DynStrTab->addString(F->getSoName())}); if (!Config->SoName.empty()) - add({DT_SONAME, In::DynStrTab->addString(Config->SoName)}); + add({DT_SONAME, In::X::DynStrTab->addString(Config->SoName)}); // Set DT_FLAGS and DT_FLAGS_1. uint32_t DtFlags = 0; @@ -1084,11 +1084,11 @@ if (this->Size) return; // Already finalized. - this->Link = In::DynStrTab->OutSec->SectionIndex; - if (In::RelaDyn->OutSec->Size > 0) { + this->Link = In::X::DynStrTab->OutSec->SectionIndex; + if (In::X::RelaDyn->OutSec->Size > 0) { bool IsRela = Config->isRela(); - add({IsRela ? DT_RELA : DT_REL, In::RelaDyn}); - add({IsRela ? DT_RELASZ : DT_RELSZ, In::RelaDyn->OutSec->Size}); + add({IsRela ? DT_RELA : DT_REL, In::X::RelaDyn}); + add({IsRela ? DT_RELASZ : DT_RELSZ, In::X::RelaDyn->OutSec->Size}); add({IsRela ? DT_RELAENT : DT_RELENT, uintX_t(IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel))}); @@ -1096,29 +1096,29 @@ // The problem is in the tight relation between dynamic // relocations and GOT. So do not emit this tag on MIPS. if (Config->EMachine != EM_MIPS) { - size_t NumRelativeRels = In::RelaDyn->getRelativeRelocCount(); + size_t NumRelativeRels = In::X::RelaDyn->getRelativeRelocCount(); if (Config->ZCombreloc && NumRelativeRels) add({IsRela ? DT_RELACOUNT : DT_RELCOUNT, NumRelativeRels}); } } - if (In::RelaPlt->OutSec->Size > 0) { - add({DT_JMPREL, In::RelaPlt}); - add({DT_PLTRELSZ, In::RelaPlt->OutSec->Size}); + if (In::X::RelaPlt->OutSec->Size > 0) { + add({DT_JMPREL, In::X::RelaPlt}); + add({DT_PLTRELSZ, In::X::RelaPlt->OutSec->Size}); add({Config->EMachine == EM_MIPS ? DT_MIPS_PLTGOT : DT_PLTGOT, - In::GotPlt}); + In::X::GotPlt}); add({DT_PLTREL, uint64_t(Config->isRela() ? DT_RELA : DT_REL)}); } - add({DT_SYMTAB, In::DynSymTab}); + add({DT_SYMTAB, In::X::DynSymTab}); add({DT_SYMENT, sizeof(Elf_Sym)}); - add({DT_STRTAB, In::DynStrTab}); - add({DT_STRSZ, In::DynStrTab->getSize()}); + add({DT_STRTAB, In::X::DynStrTab}); + add({DT_STRSZ, In::X::DynStrTab->getSize()}); if (!Config->ZText) add({DT_TEXTREL, (uint64_t)0}); - if (In::GnuHashTab) - add({DT_GNU_HASH, In::GnuHashTab}); - if (In::HashTab) - add({DT_HASH, In::HashTab}); + if (In::X::GnuHashTab) + add({DT_GNU_HASH, In::X::GnuHashTab}); + if (In::X::HashTab) + add({DT_HASH, In::X::HashTab}); if (Out::PreinitArray) { add({DT_PREINIT_ARRAY, Out::PreinitArray}); @@ -1138,31 +1138,31 @@ if (SymbolBody *B = Symtab::X->findInCurrentDSO(Config->Fini)) add({DT_FINI, B}); - bool HasVerNeed = In::VerNeed->getNeedNum() != 0; - if (HasVerNeed || In::VerDef) - add({DT_VERSYM, In::VerSym}); - if (In::VerDef) { - add({DT_VERDEF, In::VerDef}); + bool HasVerNeed = In::X::VerNeed->getNeedNum() != 0; + if (HasVerNeed || In::X::VerDef) + add({DT_VERSYM, In::X::VerSym}); + if (In::X::VerDef) { + add({DT_VERDEF, In::X::VerDef}); add({DT_VERDEFNUM, getVerDefNum()}); } if (HasVerNeed) { - add({DT_VERNEED, In::VerNeed}); - add({DT_VERNEEDNUM, In::VerNeed->getNeedNum()}); + add({DT_VERNEED, In::X::VerNeed}); + add({DT_VERNEEDNUM, In::X::VerNeed->getNeedNum()}); } if (Config->EMachine == EM_MIPS) { add({DT_MIPS_RLD_VERSION, 1}); add({DT_MIPS_FLAGS, RHF_NOTPOT}); add({DT_MIPS_BASE_ADDRESS, Config->ImageBase}); - add({DT_MIPS_SYMTABNO, In::DynSymTab->getNumSymbols()}); - add({DT_MIPS_LOCAL_GOTNO, In::MipsGot->getLocalEntriesNum()}); - if (const SymbolBody *B = In::MipsGot->getFirstGlobalEntry()) + add({DT_MIPS_SYMTABNO, In::X::DynSymTab->getNumSymbols()}); + add({DT_MIPS_LOCAL_GOTNO, In::X::MipsGot->getLocalEntriesNum()}); + if (const SymbolBody *B = In::X::MipsGot->getFirstGlobalEntry()) add({DT_MIPS_GOTSYM, B->DynsymIndex}); else - add({DT_MIPS_GOTSYM, In::DynSymTab->getNumSymbols()}); - add({DT_PLTGOT, In::MipsGot}); - if (In::MipsRldMap) - add({DT_MIPS_RLD_MAP, In::MipsRldMap}); + add({DT_MIPS_GOTSYM, In::X::DynSymTab->getNumSymbols()}); + add({DT_PLTGOT, In::X::MipsGot}); + if (In::X::MipsRldMap) + add({DT_MIPS_RLD_MAP, In::X::MipsRldMap}); } this->OutSec->Link = this->Link; @@ -1248,11 +1248,11 @@ if (Config->isRela()) P->r_addend = Rel.getAddend(); P->r_offset = Rel.getOffset(); - if (Config->EMachine == EM_MIPS && Rel.getInputSec() == In::MipsGot) + if (Config->EMachine == EM_MIPS && Rel.getInputSec() == In::X::MipsGot) // Dynamic relocation against MIPS GOT section make deal TLS entries // allocated in the end of the GOT. We need to adjust the offset to take // in account 'local' and 'global' GOT entries. - P->r_offset += In::MipsGot->getTlsOffset(); + P->r_offset += In::X::MipsGot->getTlsOffset(); P->setSymbolAndType(Rel.getSymIndex(), Rel.Type, Config->isMips64EL()); } @@ -1272,8 +1272,9 @@ } template void RelocationSection::finalizeContents() { - this->Link = In::DynSymTab ? In::DynSymTab->OutSec->SectionIndex - : In::SymTab->OutSec->SectionIndex; + this->Link = In::X::DynSymTab + ? In::X::DynSymTab->OutSec->SectionIndex + : In::X::SymTab->OutSec->SectionIndex; // Set required output section properties. this->OutSec->Link = this->Link; @@ -1319,9 +1320,9 @@ // Because the first symbol entry is a null entry, 1 is the first. this->OutSec->Info = 1; - if (In::GnuHashTab) { + if (In::X::GnuHashTab) { // NB: It also sorts Symbols to meet the GNU hash table requirements. - In::GnuHashTab->addSymbols(Symbols); + In::X::GnuHashTab->addSymbols(Symbols); } else if (Config->EMachine == EM_MIPS) { std::stable_sort(Symbols.begin(), Symbols.end(), sortMipsSymbols); } @@ -1470,7 +1471,7 @@ } template void GnuHashTableSection::finalizeContents() { - this->OutSec->Link = In::DynSymTab->OutSec->SectionIndex; + this->OutSec->Link = In::X::DynSymTab->OutSec->SectionIndex; // Computes bloom filter size in word size. We want to allocate 8 // bits for each symbol. It must be a power of two. @@ -1489,7 +1490,7 @@ // Write a header. const endianness E = ELFT::TargetEndianness; write32(Buf, NBuckets); - write32(Buf + 4, In::DynSymTab->getNumSymbols() - Symbols.size()); + write32(Buf + 4, In::X::DynSymTab->getNumSymbols() - Symbols.size()); write32(Buf + 8, MaskWords); write32(Buf + 12, getShift2()); Buf += 16; @@ -1611,15 +1612,15 @@ } template void HashTableSection::finalizeContents() { - this->OutSec->Link = In::DynSymTab->OutSec->SectionIndex; + this->OutSec->Link = In::X::DynSymTab->OutSec->SectionIndex; unsigned NumEntries = 2; // nbucket and nchain. - NumEntries += In::DynSymTab->getNumSymbols(); // The chain entries. + NumEntries += In::X::DynSymTab->getNumSymbols(); // The chain entries. // Create as many buckets as there are symbols. // FIXME: This is simplistic. We can try to optimize it, but implementing // support for SHT_GNU_HASH is probably even more profitable. - NumEntries += In::DynSymTab->getNumSymbols(); + NumEntries += In::X::DynSymTab->getNumSymbols(); this->Size = NumEntries * 4; } @@ -1627,7 +1628,7 @@ // A 32-bit integer type in the target endianness. typedef typename ELFT::Word Elf_Word; - unsigned NumSymbols = In::DynSymTab->getNumSymbols(); + unsigned NumSymbols = In::X::DynSymTab->getNumSymbols(); auto *P = reinterpret_cast(Buf); *P++ = NumSymbols; // nbucket @@ -1636,7 +1637,7 @@ Elf_Word *Buckets = P; Elf_Word *Chains = P + NumSymbols; - for (const SymbolTableEntry &S : In::DynSymTab->getSymbols()) { + for (const SymbolTableEntry &S : In::X::DynSymTab->getSymbols()) { SymbolBody *Body = S.Symbol; StringRef Name = Body->getName(); unsigned I = Body->DynsymIndex; @@ -1672,9 +1673,9 @@ template void PltSection::addEntry(SymbolBody &Sym) { Sym.PltIndex = Entries.size(); - RelocationSection *PltRelocSection = In::RelaPlt; + RelocationSection *PltRelocSection = In::X::RelaPlt; if (HeaderSize == 0) { - PltRelocSection = In::RelaIplt; + PltRelocSection = In::X::RelaIplt; Sym.IsInIplt = true; } unsigned RelOff = PltRelocSection->getRelocOffset(); @@ -1699,7 +1700,7 @@ } template unsigned PltSection::getPltRelocOff() const { - return (HeaderSize == 0) ? In::Plt->getSize() : 0; + return (HeaderSize == 0) ? In::X::Plt->getSize() : 0; } template @@ -1938,7 +1939,7 @@ Buf[1] = DW_EH_PE_pcrel | DW_EH_PE_sdata4; Buf[2] = DW_EH_PE_udata4; Buf[3] = DW_EH_PE_datarel | DW_EH_PE_sdata4; - write32(Buf + 4, In::EhFrame->OutSec->Addr - this->getVA() - 4); + write32(Buf + 4, In::X::EhFrame->OutSec->Addr - this->getVA() - 4); write32(Buf + 8, Fdes.size()); Buf += 12; @@ -1952,7 +1953,7 @@ template size_t EhFrameHeader::getSize() const { // .eh_frame_hdr has a 12 bytes header followed by an array of FDEs. - return 12 + In::EhFrame->NumFdes * 8; + return 12 + In::X::EhFrame->NumFdes * 8; } template @@ -1961,7 +1962,7 @@ } template bool EhFrameHeader::empty() const { - return In::EhFrame->empty(); + return In::X::EhFrame->empty(); } template @@ -1976,11 +1977,11 @@ } template void VersionDefinitionSection::finalizeContents() { - FileDefNameOff = In::DynStrTab->addString(getFileDefName()); + FileDefNameOff = In::X::DynStrTab->addString(getFileDefName()); for (VersionDefinition &V : Config->VersionDefinitions) - V.NameOff = In::DynStrTab->addString(V.Name); + V.NameOff = In::X::DynStrTab->addString(V.Name); - this->OutSec->Link = In::DynStrTab->OutSec->SectionIndex; + this->OutSec->Link = In::X::DynStrTab->OutSec->SectionIndex; // sh_info should be set to the number of definitions. This fact is missed in // documentation, but confirmed by binutils community: @@ -2033,23 +2034,23 @@ template void VersionTableSection::finalizeContents() { // At the moment of june 2016 GNU docs does not mention that sh_link field // should be set, but Sun docs do. Also readelf relies on this field. - this->OutSec->Link = In::DynSymTab->OutSec->SectionIndex; + this->OutSec->Link = In::X::DynSymTab->OutSec->SectionIndex; } template size_t VersionTableSection::getSize() const { - return sizeof(Elf_Versym) * (In::DynSymTab->getSymbols().size() + 1); + return sizeof(Elf_Versym) * (In::X::DynSymTab->getSymbols().size() + 1); } template void VersionTableSection::writeTo(uint8_t *Buf) { auto *OutVersym = reinterpret_cast(Buf) + 1; - for (const SymbolTableEntry &S : In::DynSymTab->getSymbols()) { + for (const SymbolTableEntry &S : In::X::DynSymTab->getSymbols()) { OutVersym->vs_index = S.Symbol->symbol()->VersionId; ++OutVersym; } } template bool VersionTableSection::empty() const { - return !In::VerDef && In::VerNeed->empty(); + return !In::X::VerDef && In::X::VerNeed->empty(); } template @@ -2076,14 +2077,15 @@ // to create one by adding it to our needed list and creating a dynstr entry // for the soname. if (File->VerdefMap.empty()) - Needed.push_back({File, In::DynStrTab->addString(File->getSoName())}); + Needed.push_back( + {File, In::X::DynStrTab->addString(File->getSoName())}); typename SharedFile::NeededVer &NV = File->VerdefMap[Ver]; // If we don't already know that we need an Elf_Vernaux for this Elf_Verdef, // prepare to create one by allocating a version identifier and creating a // dynstr entry for the version name. if (NV.Index == 0) { - NV.StrTab = In::DynStrTab->addString(File->getStringTable().data() + - Ver->getAux()->vda_name); + NV.StrTab = In::X::DynStrTab->addString( + File->getStringTable().data() + Ver->getAux()->vda_name); NV.Index = NextIndex++; } SS->symbol()->VersionId = NV.Index; @@ -2125,7 +2127,7 @@ } template void VersionNeedSection::finalizeContents() { - this->OutSec->Link = In::DynStrTab->OutSec->SectionIndex; + this->OutSec->Link = In::X::DynStrTab->OutSec->SectionIndex; this->OutSec->Info = Needed.size(); } @@ -2266,6 +2268,10 @@ return T->getTargetInputSection(); } +InputSection *In::ARMAttributes; +InputSection *In::Common; +InputSection *In::Interp; + template InputSection *elf::createCommonSection(); template InputSection *elf::createCommonSection(); template InputSection *elf::createCommonSection(); Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -409,7 +409,7 @@ } void X86TargetInfo::writeGotPltHeader(uint8_t *Buf) const { - write32le(Buf, In::Dynamic->getVA()); + write32le(Buf, In::X::Dynamic->getVA()); } void X86TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &S) const { @@ -462,7 +462,7 @@ 0x90, 0x90, 0x90, 0x90 // nop; nop; nop; nop }; memcpy(Buf, PltData, sizeof(PltData)); - uint32_t Got = In::GotPlt->getVA(); + uint32_t Got = In::X::GotPlt->getVA(); write32le(Buf + 2, Got + 4); write32le(Buf + 8, Got + 8); } @@ -479,7 +479,7 @@ // jmp *foo@GOT(%ebx) or jmp *foo_in_GOT Buf[1] = Config->pic() ? 0xa3 : 0x25; - uint32_t Got = In::GotPlt->getVA(); + uint32_t Got = In::X::GotPlt->getVA(); write32le(Buf + 2, Config->Shared ? GotEntryAddr - Got : GotEntryAddr); write32le(Buf + 7, RelOff); write32le(Buf + 12, -Index * PltEntrySize - PltHeaderSize - 16); @@ -697,7 +697,7 @@ // required, but it is documented in the psabi and the glibc dynamic linker // seems to use it (note that this is relevant for linking ld.so, not any // other program). - write64le(Buf, In::Dynamic->getVA()); + write64le(Buf, In::X::Dynamic->getVA()); } template @@ -715,8 +715,8 @@ 0x0f, 0x1f, 0x40, 0x00 // nopl 0x0(rax) }; memcpy(Buf, PltData, sizeof(PltData)); - uint64_t Got = In::GotPlt->getVA(); - uint64_t Plt = In::Plt->getVA(); + uint64_t Got = In::X::GotPlt->getVA(); + uint64_t Plt = In::X::Plt->getVA(); write32le(Buf + 2, Got - Plt + 2); // GOT+8 write32le(Buf + 8, Got - Plt + 4); // GOT+16 } @@ -1130,7 +1130,7 @@ // TOC starts where the first of these sections starts. We always create a // .got when we see a relocation that uses it, so for us the start is always // the .got. - uint64_t TocVA = In::Got->getVA(); + uint64_t TocVA = In::X::Got->getVA(); // Per the ppc64-elf-linux ABI, The TOC base is TOC value plus 0x8000 // thus permitting a full 64 Kbytes segment. Note that the glibc startup @@ -1363,7 +1363,7 @@ } void AArch64TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { - write64le(Buf, In::Plt->getVA()); + write64le(Buf, In::X::Plt->getVA()); } // Page(Expr) is the page address of the expression Expr, defined @@ -1386,8 +1386,8 @@ }; memcpy(Buf, PltData, sizeof(PltData)); - uint64_t Got = In::GotPlt->getVA(); - uint64_t Plt = In::Plt->getVA(); + uint64_t Got = In::X::GotPlt->getVA(); + uint64_t Plt = In::X::Plt->getVA(); relocateOne(Buf + 4, R_AARCH64_ADR_PREL_PG_HI21, getAArch64Page(Got + 16) - getAArch64Page(Plt + 4)); relocateOne(Buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, Got + 16); @@ -1738,7 +1738,7 @@ } void ARMTargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { - write32le(Buf, In::Plt->getVA()); + write32le(Buf, In::X::Plt->getVA()); } void ARMTargetInfo::writeIgotPlt(uint8_t *Buf, const SymbolBody &S) const { @@ -1755,8 +1755,8 @@ 0x00, 0x00, 0x00, 0x00, // L2: .word &(.got.plt) - L1 - 8 }; memcpy(Buf, PltData, sizeof(PltData)); - uint64_t GotPlt = In::GotPlt->getVA(); - uint64_t L1 = In::Plt->getVA() + 8; + uint64_t GotPlt = In::X::GotPlt->getVA(); + uint64_t L1 = In::X::Plt->getVA() + 8; write32le(Buf + 16, GotPlt - L1 - 8); } @@ -2142,7 +2142,7 @@ template void MipsTargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const { - write32(Buf, In::Plt->getVA()); + write32(Buf, In::X::Plt->getVA()); } template @@ -2209,7 +2209,7 @@ write32(Buf + 20, 0x0018c082); // srl $24, $24, 2 write32(Buf + 24, 0x0320f809); // jalr $25 write32(Buf + 28, 0x2718fffe); // subu $24, $24, 2 - uint64_t Got = In::GotPlt->getVA(); + uint64_t Got = In::X::GotPlt->getVA(); writeMipsHi16(Buf, Got); writeMipsLo16(Buf + 4, Got); writeMipsLo16(Buf + 8, Got); Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -208,7 +208,7 @@ if (!ES->Live) continue; - In::EhFrame->addSection(ES); + In::X::EhFrame->addSection(ES); S = nullptr; } @@ -333,11 +333,11 @@ Out::Bss = make(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); Out::BssRelRo = make(".bss.rel.ro", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); - In::DynStrTab = make>(".dynstr", true); - In::Dynamic = make>(); - In::RelaDyn = make>( + In::X::DynStrTab = make>(".dynstr", true); + In::X::Dynamic = make>(); + In::X::RelaDyn = make>( Config->isRela() ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc); - In::ShStrTab = make>(".shstrtab", false); + In::X::ShStrTab = make>(".shstrtab", false); Out::ElfHeader = make("", 0, SHF_ALLOC); Out::ElfHeader->Size = sizeof(Elf_Ehdr); @@ -345,28 +345,28 @@ Out::ProgramHeaders->updateAlignment(sizeof(uintX_t)); if (needsInterpSection()) { - In::Interp = createInterpSection(); - Add(In::Interp); + In::Interp = createInterpSection(); + Add(In::Interp); } else { - In::Interp = nullptr; + In::Interp = nullptr; } if (!Config->Relocatable) Add(createCommentSection()); if (Config->Strip != StripPolicy::All) { - In::StrTab = make>(".strtab", false); - In::SymTab = make>(*In::StrTab); + In::X::StrTab = make>(".strtab", false); + In::X::SymTab = make>(*In::X::StrTab); } if (Config->BuildId != BuildIdKind::None) { - In::BuildId = make>(); - Add(In::BuildId); + In::X::BuildId = make>(); + Add(In::X::BuildId); } InputSection *Common = createCommonSection(); if (!Common->Data.empty()) { - In::Common = Common; + In::Common = Common; Add(Common); } @@ -376,8 +376,8 @@ Config->ExportDynamic; if (Config->EMachine == EM_MIPS) { if (!Config->Shared && HasDynSymTab) { - In::MipsRldMap = make>(); - Add(In::MipsRldMap); + In::X::MipsRldMap = make>(); + Add(In::X::MipsRldMap); } if (auto *Sec = MipsAbiFlagsSection::create()) Add(Sec); @@ -388,87 +388,88 @@ } if (HasDynSymTab) { - In::DynSymTab = make>(*In::DynStrTab); - Add(In::DynSymTab); + In::X::DynSymTab = + make>(*In::X::DynStrTab); + Add(In::X::DynSymTab); - In::VerSym = make>(); - Add(In::VerSym); + In::X::VerSym = make>(); + Add(In::X::VerSym); if (!Config->VersionDefinitions.empty()) { - In::VerDef = make>(); - Add(In::VerDef); + In::X::VerDef = make>(); + Add(In::X::VerDef); } - In::VerNeed = make>(); - Add(In::VerNeed); + In::X::VerNeed = make>(); + Add(In::X::VerNeed); if (Config->GnuHash) { - In::GnuHashTab = make>(); - Add(In::GnuHashTab); + In::X::GnuHashTab = make>(); + Add(In::X::GnuHashTab); } if (Config->SysvHash) { - In::HashTab = make>(); - Add(In::HashTab); + In::X::HashTab = make>(); + Add(In::X::HashTab); } - Add(In::Dynamic); - Add(In::DynStrTab); - Add(In::RelaDyn); + Add(In::X::Dynamic); + Add(In::X::DynStrTab); + Add(In::X::RelaDyn); } // Add .got. MIPS' .got is so different from the other archs, // it has its own class. if (Config->EMachine == EM_MIPS) { - In::MipsGot = make>(); - Add(In::MipsGot); + In::X::MipsGot = make>(); + Add(In::X::MipsGot); } else { - In::Got = make>(); - Add(In::Got); + In::X::Got = make>(); + Add(In::X::Got); } - In::GotPlt = make>(); - Add(In::GotPlt); - In::IgotPlt = make>(); - Add(In::IgotPlt); + In::X::GotPlt = make>(); + Add(In::X::GotPlt); + In::X::IgotPlt = make>(); + Add(In::X::IgotPlt); if (Config->GdbIndex) { - In::GdbIndex = make>(); - Add(In::GdbIndex); + In::X::GdbIndex = make>(); + Add(In::X::GdbIndex); } // We always need to add rel[a].plt to output if it has entries. // Even for static linking it can contain R_[*]_IRELATIVE relocations. - In::RelaPlt = make>( + In::X::RelaPlt = make>( Config->isRela() ? ".rela.plt" : ".rel.plt", false /*Sort*/); - Add(In::RelaPlt); + Add(In::X::RelaPlt); // The RelaIplt immediately follows .rel.plt (.rel.dyn for ARM) to ensure // that the IRelative relocations are processed last by the dynamic loader - In::RelaIplt = make>( - (Config->EMachine == EM_ARM) ? ".rel.dyn" : In::RelaPlt->Name, + In::X::RelaIplt = make>( + (Config->EMachine == EM_ARM) ? ".rel.dyn" : In::X::RelaPlt->Name, false /*Sort*/); - Add(In::RelaIplt); + Add(In::X::RelaIplt); - In::Plt = make>(Target->PltHeaderSize); - Add(In::Plt); - In::Iplt = make>(0); - Add(In::Iplt); + In::X::Plt = make>(Target->PltHeaderSize); + Add(In::X::Plt); + In::X::Iplt = make>(0); + Add(In::X::Iplt); if (!Config->Relocatable) { if (Config->EhFrameHdr) { - In::EhFrameHdr = make>(); - Add(In::EhFrameHdr); + In::X::EhFrameHdr = make>(); + Add(In::X::EhFrameHdr); } - In::EhFrame = make>(); - Add(In::EhFrame); + In::X::EhFrame = make>(); + Add(In::X::EhFrame); } - if (In::SymTab) - Add(In::SymTab); - Add(In::ShStrTab); - if (In::StrTab) - Add(In::StrTab); + if (In::X::SymTab) + Add(In::X::SymTab); + Add(In::X::ShStrTab); + if (In::X::StrTab) + Add(In::X::StrTab); } template @@ -524,7 +525,7 @@ // Local symbols are not in the linker's symbol table. This function scans // each object file's symbol table to copy local symbols to the output. template void Writer::copyLocalSymbols() { - if (!In::SymTab) + if (!In::X::SymTab) return; for (elf::ObjectFile *F : Symtab::X->getObjectFiles()) { for (SymbolBody *B : F->getLocalSymbols()) { @@ -542,7 +543,7 @@ SectionBase *Sec = DR->Section; if (!shouldKeepInSymtab(Sec, B->getName(), *B)) continue; - In::SymTab->addSymbol(B); + In::X::SymTab->addSymbol(B); } } } @@ -562,7 +563,7 @@ auto *Sym = make("", /*IsLocal=*/true, /*StOther=*/0, STT_SECTION, /*Value=*/0, /*Size=*/0, IS, nullptr); - In::SymTab->addSymbol(Sym); + In::X::SymTab->addSymbol(Sym); } } @@ -613,11 +614,11 @@ Type == SHT_PREINIT_ARRAY) return true; - if (Sec == In::GotPlt->OutSec) + if (Sec == In::X::GotPlt->OutSec) return Config->ZNow; - if (Sec == In::Dynamic->OutSec) + if (Sec == In::X::Dynamic->OutSec) return true; - if (In::Got && Sec == In::Got->OutSec) + if (In::X::Got && Sec == In::X::Got->OutSec) return true; if (Sec == Out::BssRelRo) return true; @@ -787,13 +788,13 @@ // need these symbols, since IRELATIVE relocs are resolved through GOT // and PLT. For details, see http://www.airs.com/blog/archives/403. template void Writer::addRelIpltSymbols() { - if (In::DynSymTab) + if (In::X::DynSymTab) return; StringRef S = Config->isRela() ? "__rela_iplt_start" : "__rel_iplt_start"; - addOptionalRegular(S, In::RelaIplt, 0, STV_HIDDEN, STB_WEAK); + addOptionalRegular(S, In::X::RelaIplt, 0, STV_HIDDEN, STB_WEAK); S = Config->isRela() ? "__rela_iplt_end" : "__rel_iplt_end"; - addOptionalRegular(S, In::RelaIplt, -1, STV_HIDDEN, STB_WEAK); + addOptionalRegular(S, In::X::RelaIplt, -1, STV_HIDDEN, STB_WEAK); } // The linker is expected to define some symbols depending on @@ -844,7 +845,7 @@ // to avoid the undefined symbol error. As usual special cases are ARM and // MIPS - the libc for these targets defines __tls_get_addr itself because // there are no TLS optimizations for these targets. - if (!In::DynSymTab && + if (!In::X::DynSymTab && (Config->EMachine != EM_MIPS && Config->EMachine != EM_ARM)) Symtab::X->addIgnored("__tls_get_addr"); @@ -929,7 +930,7 @@ } if (!Config->Relocatable) { - for (EhInputSection *ES : In::EhFrame->Sections) + for (EhInputSection *ES : In::X::EhFrame->Sections) Fn(*ES); } } @@ -1095,8 +1096,8 @@ // It should be okay as no one seems to care about the type. // Even the author of gold doesn't remember why gold behaves that way. // https://sourceware.org/ml/binutils/2002-03/msg00360.html - if (In::DynSymTab) - addRegular("_DYNAMIC", In::Dynamic, 0); + if (In::X::DynSymTab) + addRegular("_DYNAMIC", In::X::Dynamic, 0); // Define __rel[a]_iplt_{start,end} symbols if needed. addRelIpltSymbols(); @@ -1104,17 +1105,17 @@ // This responsible for splitting up .eh_frame section into // pieces. The relocation scan uses those pieces, so this has to be // earlier. - applySynthetic({In::EhFrame}, + applySynthetic({In::X::EhFrame}, [](SyntheticSection *SS) { SS->finalizeContents(); }); // Scan relocations. This must be done after every symbol is declared so that // we can correctly decide if a dynamic relocation is needed. forEachRelSec(scanRelocations); - if (In::Plt && !In::Plt->empty()) - In::Plt->addSymbols(); - if (In::Iplt && !In::Iplt->empty()) - In::Iplt->addSymbols(); + if (In::X::Plt && !In::X::Plt->empty()) + In::X::Plt->addSymbols(); + if (In::X::Iplt && !In::X::Iplt->empty()) + In::X::Iplt->addSymbols(); // Now that we have defined all possible global symbols including linker- // synthesized ones. Visit all symbols to give the finishing touches. @@ -1123,14 +1124,14 @@ if (!includeInSymtab(*Body)) continue; - if (In::SymTab) - In::SymTab->addSymbol(Body); + if (In::X::SymTab) + In::X::SymTab->addSymbol(Body); - if (In::DynSymTab && S->includeInDynsym()) { - In::DynSymTab->addSymbol(Body); + if (In::X::DynSymTab && S->includeInDynsym()) { + In::X::DynSymTab->addSymbol(Body); if (auto *SS = dyn_cast(Body)) if (cast>(SS->File)->isNeeded()) - In::VerNeed->addSymbol(SS); + In::X::VerNeed->addSymbol(SS); } } @@ -1153,7 +1154,7 @@ unsigned I = 1; for (OutputSection *Sec : OutputSections) { Sec->SectionIndex = I++; - Sec->ShName = In::ShStrTab->addString(Sec->Name); + Sec->ShName = In::X::ShStrTab->addString(Sec->Name); } // Binary and relocatable output does not have PHDRS. @@ -1169,14 +1170,14 @@ // Dynamic section must be the last one in this list and dynamic // symbol table section (DynSymTab) must be the first one. applySynthetic( - {In::DynSymTab, In::GnuHashTab, In::HashTab, - In::SymTab, In::ShStrTab, In::StrTab, - In::VerDef, In::DynStrTab, In::GdbIndex, - In::Got, In::MipsGot, In::IgotPlt, - In::GotPlt, In::RelaDyn, In::RelaIplt, - In::RelaPlt, In::Plt, In::Iplt, - In::Plt, In::EhFrameHdr, In::VerSym, - In::VerNeed, In::Dynamic}, + {In::X::DynSymTab, In::X::GnuHashTab, In::X::HashTab, + In::X::SymTab, In::X::ShStrTab, In::X::StrTab, + In::X::VerDef, In::X::DynStrTab, In::X::GdbIndex, + In::X::Got, In::X::MipsGot, In::X::IgotPlt, + In::X::GotPlt, In::X::RelaDyn, In::X::RelaIplt, + In::X::RelaPlt, In::X::Plt, In::X::Iplt, + In::X::Plt, In::X::EhFrameHdr, In::X::VerSym, + In::X::VerNeed, In::X::Dynamic}, [](SyntheticSection *SS) { SS->finalizeContents(); }); // Some architectures use small displacements for jump instructions. @@ -1190,7 +1191,7 @@ // are out of range. This will need to turn into a loop that converges // when no more Thunks are added if (createThunks(OutputSections)) - applySynthetic({In::MipsGot}, + applySynthetic({In::X::MipsGot}, [](SyntheticSection *SS) { SS->updateAllocSize(); }); } // Fill other section headers. The dynamic table is finalized @@ -1200,8 +1201,9 @@ Sec->finalize(); // createThunks may have added local symbols to the static symbol table - applySynthetic({In::SymTab, In::ShStrTab, In::StrTab}, - [](SyntheticSection *SS) { SS->postThunkContents(); }); + applySynthetic( + {In::X::SymTab, In::X::ShStrTab, In::X::StrTab}, + [](SyntheticSection *SS) { SS->postThunkContents(); }); } template void Writer::addPredefinedSections() { @@ -1341,9 +1343,9 @@ Ret.push_back(std::move(TlsHdr)); // Add an entry for .dynamic. - if (In::DynSymTab) - AddHdr(PT_DYNAMIC, In::Dynamic->OutSec->getPhdrFlags()) - ->add(In::Dynamic->OutSec); + if (In::X::DynSymTab) + AddHdr(PT_DYNAMIC, In::X::Dynamic->OutSec->getPhdrFlags()) + ->add(In::X::Dynamic->OutSec); // PT_GNU_RELRO includes all sections that should be marked as // read-only by dynamic linker after proccessing relocations. @@ -1355,10 +1357,10 @@ Ret.push_back(std::move(RelRo)); // PT_GNU_EH_FRAME is a special section pointing on .eh_frame_hdr. - if (!In::EhFrame->empty() && In::EhFrameHdr && - In::EhFrame->OutSec && In::EhFrameHdr->OutSec) - AddHdr(PT_GNU_EH_FRAME, In::EhFrameHdr->OutSec->getPhdrFlags()) - ->add(In::EhFrameHdr->OutSec); + if (!In::X::EhFrame->empty() && In::X::EhFrameHdr && + In::X::EhFrame->OutSec && In::X::EhFrameHdr->OutSec) + AddHdr(PT_GNU_EH_FRAME, In::X::EhFrameHdr->OutSec->getPhdrFlags()) + ->add(In::X::EhFrameHdr->OutSec); // PT_OPENBSD_RANDOMIZE specifies the location and size of a part of the // memory image of the program that must be filled with random data before any @@ -1738,7 +1740,7 @@ EHdr->e_phnum = Phdrs.size(); EHdr->e_shentsize = sizeof(Elf_Shdr); EHdr->e_shnum = OutputSections.size() + 1; - EHdr->e_shstrndx = In::ShStrTab->OutSec->SectionIndex; + EHdr->e_shstrndx = In::X::ShStrTab->OutSec->SectionIndex; if (Config->EMachine == EM_ARM) // We don't currently use any features incompatible with EF_ARM_EABI_VER5, @@ -1841,7 +1843,7 @@ } OutputSection *EhFrameHdr = - In::EhFrameHdr ? In::EhFrameHdr->OutSec : nullptr; + In::X::EhFrameHdr ? In::X::EhFrameHdr->OutSec : nullptr; // In -r or -emit-relocs mode, write the relocation sections first as in // ELf_Rel targets we might find out that we need to modify the relocated @@ -1862,13 +1864,13 @@ } template void Writer::writeBuildId() { - if (!In::BuildId || !In::BuildId->OutSec) + if (!In::X::BuildId || !In::X::BuildId->OutSec) return; // Compute a hash of all sections of the output file. uint8_t *Start = Buffer->getBufferStart(); uint8_t *End = Start + FileSize; - In::BuildId->writeBuildId({Start, End}); + In::X::BuildId->writeBuildId({Start, End}); } template void elf::writeResult();