diff options
-rw-r--r-- | lld/ELF/InputSection.cpp | 16 | ||||
-rw-r--r-- | lld/ELF/LinkerScript.cpp | 4 | ||||
-rw-r--r-- | lld/ELF/OutputSections.cpp | 13 | ||||
-rw-r--r-- | lld/ELF/OutputSections.h | 21 | ||||
-rw-r--r-- | lld/ELF/Relocations.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Symbols.cpp | 4 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 20 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 74 |
8 files changed, 75 insertions, 79 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index b80c206ed8b..54dc97bea81 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -368,11 +368,11 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, return 0; if (Target->TcbSize) return Body.getVA<ELFT>(A) + - alignTo(Target->TcbSize, Out<ELFT>::TlsPhdr->p_align); - return Body.getVA<ELFT>(A) - Out<ELFT>::TlsPhdr->p_memsz; + alignTo(Target->TcbSize, Out::TlsPhdr->p_align); + return Body.getVA<ELFT>(A) - Out::TlsPhdr->p_memsz; case R_RELAX_TLS_GD_TO_LE_NEG: case R_NEG_TLS: - return Out<ELF32LE>::TlsPhdr->p_memsz - Body.getVA<ELFT>(A); + return Out::TlsPhdr->p_memsz - Body.getVA<ELFT>(A); case R_ABS: case R_RELAX_GOT_PC_NOPIC: return Body.getVA<ELFT>(A); @@ -409,14 +409,14 @@ getRelocTargetVA(uint32_t Type, int64_t A, typename ELFT::uint P, // so don't bother doing anything at all. if (!SymVA) return 0; - if (Out<ELF64BE>::Opd) { + if (Out::Opd) { // If this is a local call, and we currently have the address of a // function-descriptor, get the underlying code address instead. - uint64_t OpdStart = Out<ELF64BE>::Opd->Addr; - uint64_t OpdEnd = OpdStart + Out<ELF64BE>::Opd->Size; + uint64_t OpdStart = Out::Opd->Addr; + uint64_t OpdEnd = OpdStart + Out::Opd->Size; bool InOpd = OpdStart <= SymVA && SymVA < OpdEnd; if (InOpd) - SymVA = read64be(&Out<ELF64BE>::OpdBuf[SymVA - OpdStart]); + SymVA = read64be(&Out::OpdBuf[SymVA - OpdStart]); } return SymVA - P; } @@ -469,7 +469,7 @@ void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) { uintX_t AddrLoc = this->OutSec->Addr + Offset; uint64_t SymVA = 0; - if (!Sym.isTls() || Out<ELFT>::TlsPhdr) + if (!Sym.isTls() || Out::TlsPhdr) SymVA = SignExtend64<sizeof(uintX_t) * 8>( getRelocTargetVA<ELFT>(Type, Addend, AddrLoc, Sym, R_ABS)); Target->relocateOne(BufLoc, Type, SymVA); diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 5e06050859f..f71f877cd8e 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -829,9 +829,9 @@ template <class ELFT> std::vector<PhdrEntry> LinkerScript<ELFT>::createPhdrs() { PhdrEntry &Phdr = Ret.back(); if (Cmd.HasFilehdr) - Phdr.add(Out<ELFT>::ElfHeader); + Phdr.add(Out::ElfHeader); if (Cmd.HasPhdrs) - Phdr.add(Out<ELFT>::ProgramHeaders); + Phdr.add(Out::ProgramHeaders); if (Cmd.LMAExpr) { Phdr.p_paddr = Cmd.LMAExpr(0); diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 1832fc88d8d..ae325b08119 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -30,6 +30,19 @@ using namespace llvm::ELF; using namespace lld; using namespace lld::elf; +uint8_t Out::First; +OutputSection *Out::Bss; +OutputSection *Out::BssRelRo; +OutputSection *Out::Opd; +uint8_t *Out::OpdBuf; +PhdrEntry *Out::TlsPhdr; +OutputSection *Out::DebugInfo; +OutputSection *Out::ElfHeader; +OutputSection *Out::ProgramHeaders; +OutputSection *Out::PreinitArray; +OutputSection *Out::InitArray; +OutputSection *Out::FiniArray; + uint32_t OutputSection::getPhdrFlags() const { uint32_t Ret = PF_R; if (Flags & SHF_WRITE) diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 06a03e5b65c..69875137cdd 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -93,13 +93,10 @@ public: uint8_t *Loc = nullptr; }; -// All output sections that are hadnled by the linker specially are +// All output sections that are handled by the linker specially are // globally accessible. Writer initializes them, so don't use them // until Writer is initialized. -template <class ELFT> struct Out { - typedef typename ELFT::uint uintX_t; - typedef typename ELFT::Phdr Elf_Phdr; - +struct Out { static uint8_t First; static OutputSection *Bss; static OutputSection *BssRelRo; @@ -154,21 +151,9 @@ private: template <class ELFT> uint64_t getHeaderSize() { if (Config->OFormatBinary) return 0; - return Out<ELFT>::ElfHeader->Size + Out<ELFT>::ProgramHeaders->Size; + return Out::ElfHeader->Size + Out::ProgramHeaders->Size; } -template <class ELFT> uint8_t Out<ELFT>::First; -template <class ELFT> OutputSection *Out<ELFT>::Bss; -template <class ELFT> OutputSection *Out<ELFT>::BssRelRo; -template <class ELFT> OutputSection *Out<ELFT>::Opd; -template <class ELFT> uint8_t *Out<ELFT>::OpdBuf; -template <class ELFT> PhdrEntry *Out<ELFT>::TlsPhdr; -template <class ELFT> OutputSection *Out<ELFT>::DebugInfo; -template <class ELFT> OutputSection *Out<ELFT>::ElfHeader; -template <class ELFT> OutputSection *Out<ELFT>::ProgramHeaders; -template <class ELFT> OutputSection *Out<ELFT>::PreinitArray; -template <class ELFT> OutputSection *Out<ELFT>::InitArray; -template <class ELFT> OutputSection *Out<ELFT>::FiniArray; } // namespace elf } // namespace lld diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 3d4ce39f5e2..9cb5da32eaf 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -479,7 +479,7 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol *SS) { // See if this symbol is in a read-only segment. If so, preserve the symbol's // memory protection by reserving space in the .bss.rel.ro section. bool IsReadOnly = isReadOnly<ELFT>(SS); - OutputSection *OSec = IsReadOnly ? Out<ELFT>::BssRelRo : Out<ELFT>::Bss; + OutputSection *OSec = IsReadOnly ? Out::BssRelRo : Out::Bss; // Create a SyntheticSection in Out to hold the .bss and the Copy Reloc. auto *ISec = diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index d1588834886..3ffb50744c5 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -65,10 +65,10 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) { const OutputSection *OutSec = IS->getOutputSection<ELFT>(); uintX_t VA = (OutSec ? OutSec->Addr : 0) + IS->getOffset<ELFT>(Offset); if (D.isTls() && !Config->Relocatable) { - if (!Out<ELFT>::TlsPhdr) + if (!Out::TlsPhdr) fatal(toString(D.File) + " has a STT_TLS symbol but doesn't have a PT_TLS section"); - return VA - Out<ELFT>::TlsPhdr->p_vaddr; + return VA - Out::TlsPhdr->p_vaddr; } return VA; } diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 71d46fb3a30..4275748ac00 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1102,17 +1102,17 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() { if (In<ELFT>::HashTab) add({DT_HASH, In<ELFT>::HashTab}); - if (Out<ELFT>::PreinitArray) { - add({DT_PREINIT_ARRAY, Out<ELFT>::PreinitArray}); - add({DT_PREINIT_ARRAYSZ, Out<ELFT>::PreinitArray, Entry::SecSize}); + if (Out::PreinitArray) { + add({DT_PREINIT_ARRAY, Out::PreinitArray}); + add({DT_PREINIT_ARRAYSZ, Out::PreinitArray, Entry::SecSize}); } - if (Out<ELFT>::InitArray) { - add({DT_INIT_ARRAY, Out<ELFT>::InitArray}); - add({DT_INIT_ARRAYSZ, Out<ELFT>::InitArray, Entry::SecSize}); + if (Out::InitArray) { + add({DT_INIT_ARRAY, Out::InitArray}); + add({DT_INIT_ARRAYSZ, Out::InitArray, Entry::SecSize}); } - if (Out<ELFT>::FiniArray) { - add({DT_FINI_ARRAY, Out<ELFT>::FiniArray}); - add({DT_FINI_ARRAYSZ, Out<ELFT>::FiniArray, Entry::SecSize}); + if (Out::FiniArray) { + add({DT_FINI_ARRAY, Out::FiniArray}); + add({DT_FINI_ARRAYSZ, Out::FiniArray, Entry::SecSize}); } if (SymbolBody *B = Symtab<ELFT>::X->findInCurrentDSO(Config->Init)) @@ -1853,7 +1853,7 @@ template <class ELFT> void GdbIndexSection<ELFT>::writeTo(uint8_t *Buf) { } template <class ELFT> bool GdbIndexSection<ELFT>::empty() const { - return !Out<ELFT>::DebugInfo; + return !Out::DebugInfo; } template <class ELFT> diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 7f0ec1f4bac..e8adcfa6b15 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -301,20 +301,19 @@ template <class ELFT> void Writer<ELFT>::run() { exitLld(0); } -// Initialize Out<ELFT> members. +// Initialize Out members. template <class ELFT> void Writer<ELFT>::createSyntheticSections() { // Initialize all pointers with NULL. This is needed because // you can call lld::elf::main more than once as a library. - memset(&Out<ELFT>::First, 0, sizeof(Out<ELFT>)); + memset(&Out::First, 0, sizeof(Out)); auto Add = [](InputSectionBase *Sec) { Symtab<ELFT>::X->Sections.push_back(Sec); }; // Create singleton output sections. - Out<ELFT>::Bss = - make<OutputSection>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); - Out<ELFT>::BssRelRo = + Out::Bss = make<OutputSection>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); + Out::BssRelRo = make<OutputSection>(".bss.rel.ro", SHT_NOBITS, SHF_ALLOC | SHF_WRITE); In<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true); In<ELFT>::Dynamic = make<DynamicSection<ELFT>>(); @@ -322,10 +321,10 @@ template <class ELFT> void Writer<ELFT>::createSyntheticSections() { Config->Rela ? ".rela.dyn" : ".rel.dyn", Config->ZCombreloc); In<ELFT>::ShStrTab = make<StringTableSection<ELFT>>(".shstrtab", false); - Out<ELFT>::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC); - Out<ELFT>::ElfHeader->Size = sizeof(Elf_Ehdr); - Out<ELFT>::ProgramHeaders = make<OutputSection>("", 0, SHF_ALLOC); - Out<ELFT>::ProgramHeaders->updateAlignment(sizeof(uintX_t)); + Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC); + Out::ElfHeader->Size = sizeof(Elf_Ehdr); + Out::ProgramHeaders = make<OutputSection>("", 0, SHF_ALLOC); + Out::ProgramHeaders->updateAlignment(sizeof(uintX_t)); if (needsInterpSection<ELFT>()) { In<ELFT>::Interp = createInterpSection<ELFT>(); @@ -597,7 +596,7 @@ template <class ELFT> bool elf::isRelroSection(const OutputSection *Sec) { return true; if (In<ELFT>::Got && Sec == In<ELFT>::Got->OutSec) return true; - if (Sec == Out<ELFT>::BssRelRo) + if (Sec == Out::BssRelRo) return true; StringRef S = Sec->Name; @@ -841,7 +840,7 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() { // __ehdr_start is the location of ELF file headers. ElfSym<ELFT>::EhdrStart = - addOptionalSynthetic<ELFT>("__ehdr_start", Out<ELFT>::ElfHeader, 0); + addOptionalSynthetic<ELFT>("__ehdr_start", Out::ElfHeader, 0); auto Define = [](StringRef S, DefinedSynthetic *&Sym1, DefinedSynthetic *&Sym2) { @@ -1062,10 +1061,10 @@ static void removeUnusedSyntheticSections(std::vector<OutputSection *> &V) { // Create output section objects and add them to OutputSections. template <class ELFT> void Writer<ELFT>::finalizeSections() { - Out<ELFT>::DebugInfo = findSection(".debug_info"); - Out<ELFT>::PreinitArray = findSection(".preinit_array"); - Out<ELFT>::InitArray = findSection(".init_array"); - Out<ELFT>::FiniArray = findSection(".fini_array"); + Out::DebugInfo = findSection(".debug_info"); + Out::PreinitArray = findSection(".preinit_array"); + Out::InitArray = findSection(".init_array"); + Out::FiniArray = findSection(".fini_array"); // The linker needs to define SECNAME_start, SECNAME_end and SECNAME_stop // symbols for sections, so that the runtime can get the start and end @@ -1123,7 +1122,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { return; // So far we have added sections from input object files. - // This function adds linker-created Out<ELFT>::* sections. + // This function adds linker-created Out::* sections. addPredefinedSections(); removeUnusedSyntheticSections<ELFT>(OutputSections); @@ -1132,7 +1131,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() { // This is a bit of a hack. A value of 0 means undef, so we set it // to 1 t make __ehdr_start defined. The section number is not // particularly relevant. - Out<ELFT>::ElfHeader->SectionIndex = 1; + Out::ElfHeader->SectionIndex = 1; unsigned I = 1; for (OutputSection *Sec : OutputSections) { @@ -1183,8 +1182,8 @@ template <class ELFT> void Writer<ELFT>::addPredefinedSections() { OutputSections.push_back(Sec); } }; - Add(Out<ELFT>::Bss); - Add(Out<ELFT>::BssRelRo); + Add(Out::Bss); + Add(Out::BssRelRo); // ARM ABI requires .ARM.exidx to be terminated by some piece of data. // We have the terminater synthetic section class. Add that at the end. @@ -1203,10 +1202,9 @@ template <class ELFT> void Writer<ELFT>::addStartEndSymbols() { addOptionalSynthetic<ELFT>(End, OS, OS ? -1 : 0); }; - Define("__preinit_array_start", "__preinit_array_end", - Out<ELFT>::PreinitArray); - Define("__init_array_start", "__init_array_end", Out<ELFT>::InitArray); - Define("__fini_array_start", "__fini_array_end", Out<ELFT>::FiniArray); + Define("__preinit_array_start", "__preinit_array_end", Out::PreinitArray); + Define("__init_array_start", "__init_array_end", Out::InitArray); + Define("__fini_array_start", "__fini_array_end", Out::FiniArray); if (OutputSection *Sec = findSection(".ARM.exidx")) Define("__exidx_start", "__exidx_end", Sec); @@ -1268,7 +1266,7 @@ template <class ELFT> std::vector<PhdrEntry> Writer<ELFT>::createPhdrs() { }; // The first phdr entry is PT_PHDR which describes the program header itself. - AddHdr(PT_PHDR, PF_R)->add(Out<ELFT>::ProgramHeaders); + AddHdr(PT_PHDR, PF_R)->add(Out::ProgramHeaders); // PT_INTERP must be the second entry if exists. if (OutputSection *Sec = findSection(".interp")) @@ -1427,8 +1425,8 @@ bool elf::allocateHeaders(std::vector<PhdrEntry> &Phdrs, if (!ScriptConfig->HasSections) Config->ImageBase = Min = std::min(Min, Config->ImageBase); - Out<ELFT>::ElfHeader->Addr = Min; - Out<ELFT>::ProgramHeaders->Addr = Min + Out<ELFT>::ElfHeader->Size; + Out::ElfHeader->Addr = Min; + Out::ProgramHeaders->Addr = Min + Out::ElfHeader->Size; if (Script<ELFT>::X->hasPhdrsCommands()) return true; @@ -1436,10 +1434,10 @@ bool elf::allocateHeaders(std::vector<PhdrEntry> &Phdrs, if (FirstPTLoad->First) for (OutputSection *Sec : OutputSections) if (Sec->FirstInPtLoad == FirstPTLoad->First) - Sec->FirstInPtLoad = Out<ELFT>::ElfHeader; - FirstPTLoad->First = Out<ELFT>::ElfHeader; + Sec->FirstInPtLoad = Out::ElfHeader; + FirstPTLoad->First = Out::ElfHeader; if (!FirstPTLoad->Last) - FirstPTLoad->Last = Out<ELFT>::ProgramHeaders; + FirstPTLoad->Last = Out::ProgramHeaders; return true; } @@ -1447,7 +1445,7 @@ bool elf::allocateHeaders(std::vector<PhdrEntry> &Phdrs, // sections. These are special, we do not include them into output sections // list, but have them to simplify the code. template <class ELFT> void Writer<ELFT>::fixHeaders() { - Out<ELFT>::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size(); + Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size(); // If the script has SECTIONS, assignAddresses will compute the values. if (ScriptConfig->HasSections) return; @@ -1535,8 +1533,8 @@ template <class ELFT> void Writer<ELFT>::assignFileOffsetsBinary() { // Assign file offsets to output sections. template <class ELFT> void Writer<ELFT>::assignFileOffsets() { uintX_t Off = 0; - Off = setOffset<ELFT>(Out<ELFT>::ElfHeader, Off); - Off = setOffset<ELFT>(Out<ELFT>::ProgramHeaders, Off); + Off = setOffset<ELFT>(Out::ElfHeader, Off); + Off = setOffset<ELFT>(Out::ProgramHeaders, Off); for (OutputSection *Sec : OutputSections) Off = setOffset<ELFT>(Sec, Off); @@ -1574,7 +1572,7 @@ template <class ELFT> void Writer<ELFT>::setPhdrs() { // The TLS pointer goes after PT_TLS. At least glibc will align it, // so round up the size to make sure the offsets are correct. if (P.p_type == PT_TLS) { - Out<ELFT>::TlsPhdr = &P; + Out::TlsPhdr = &P; if (P.p_memsz) P.p_memsz = alignTo(P.p_memsz, P.p_align); } @@ -1801,10 +1799,10 @@ template <class ELFT> void Writer<ELFT>::writeSections() { // PPC64 needs to process relocations in the .opd section // before processing relocations in code-containing sections. - Out<ELFT>::Opd = findSection(".opd"); - if (Out<ELFT>::Opd) { - Out<ELFT>::OpdBuf = Buf + Out<ELFT>::Opd->Offset; - Out<ELFT>::Opd->template writeTo<ELFT>(Buf + Out<ELFT>::Opd->Offset); + Out::Opd = findSection(".opd"); + if (Out::Opd) { + Out::OpdBuf = Buf + Out::Opd->Offset; + Out::Opd->template writeTo<ELFT>(Buf + Out::Opd->Offset); } OutputSection *EhFrameHdr = @@ -1818,7 +1816,7 @@ template <class ELFT> void Writer<ELFT>::writeSections() { Sec->writeTo<ELFT>(Buf + Sec->Offset); for (OutputSection *Sec : OutputSections) - if (Sec != Out<ELFT>::Opd && Sec != EhFrameHdr && Sec->Type != SHT_REL && + if (Sec != Out::Opd && Sec != EhFrameHdr && Sec->Type != SHT_REL && Sec->Type != SHT_RELA) Sec->writeTo<ELFT>(Buf + Sec->Offset); |