diff options
-rw-r--r-- | lld/ELF/Driver.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/SymbolTable.cpp | 2 | ||||
-rw-r--r-- | lld/ELF/Symbols.cpp | 6 | ||||
-rw-r--r-- | lld/ELF/Symbols.h | 61 | ||||
-rw-r--r-- | lld/ELF/Writer.cpp | 19 |
5 files changed, 43 insertions, 47 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 9402c2d182d..6d881373b30 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -279,7 +279,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { // 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", DefinedRegular<ELFT>::MipsGp); + Symtab.addAbsolute("_gp", ElfSym<ELFT>::MipsGp); } for (std::unique_ptr<InputFile> &F : Files) diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 826d6eff01f..e022ecd2e90 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -112,7 +112,7 @@ void SymbolTable<ELFT>::addSynthetic(StringRef Name, template <class ELFT> SymbolBody *SymbolTable<ELFT>::addIgnored(StringRef Name) { auto *Sym = new (Alloc) - DefinedRegular<ELFT>(Name, DefinedRegular<ELFT>::IgnoreUndef, nullptr); + DefinedRegular<ELFT>(Name, ElfSym<ELFT>::IgnoreUndef, nullptr); resolve(Sym); return Sym; } diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 44434177435..f8d585242a8 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -120,9 +120,9 @@ std::unique_ptr<InputFile> Lazy::getMember() { } template <class ELFT> static void doInitSymbols() { - DefinedRegular<ELFT>::End.setBinding(STB_GLOBAL); - DefinedRegular<ELFT>::IgnoreUndef.setBinding(STB_WEAK); - DefinedRegular<ELFT>::IgnoreUndef.setVisibility(STV_HIDDEN); + ElfSym<ELFT>::End.setBinding(STB_GLOBAL); + ElfSym<ELFT>::IgnoreUndef.setBinding(STB_WEAK); + ElfSym<ELFT>::IgnoreUndef.setVisibility(STV_HIDDEN); } void lld::elf2::initSymbols() { diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 43e6a1196fc..e2a543c08cf 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -189,40 +189,8 @@ public: // If this is null, the symbol is absolute. InputSectionBase<ELFT> *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 <class ELFT> -typename DefinedRegular<ELFT>::Elf_Sym DefinedRegular<ELFT>::IgnoreUndef; - -template <class ELFT> -typename DefinedRegular<ELFT>::Elf_Sym DefinedRegular<ELFT>::End; - -template <class ELFT> -typename DefinedRegular<ELFT>::Elf_Sym DefinedRegular<ELFT>::MipsGp; - -template <class ELFT> -typename DefinedRegular<ELFT>::Elf_Sym DefinedRegular<ELFT>::RelaIpltStart; - -template <class ELFT> -typename DefinedRegular<ELFT>::Elf_Sym DefinedRegular<ELFT>::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 @@ -316,6 +284,35 @@ private: const llvm::object::Archive::Symbol Sym; }; +// Some linker-generated symbols need to be created as +// DefinedRegular symbols, so they need Elf_Sym symbols. +// Here we allocate such Elf_Sym symbols statically. +template <class ELFT> struct ElfSym { + typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym; + + // Used to represent an undefined symbol which we don't want + // to add to the output file's symbol table. + static Elf_Sym IgnoreUndef; + + // 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 <class ELFT> typename ElfSym<ELFT>::Elf_Sym ElfSym<ELFT>::IgnoreUndef; +template <class ELFT> typename ElfSym<ELFT>::Elf_Sym ElfSym<ELFT>::End; +template <class ELFT> typename ElfSym<ELFT>::Elf_Sym ElfSym<ELFT>::MipsGp; +template <class ELFT> +typename ElfSym<ELFT>::Elf_Sym ElfSym<ELFT>::RelaIpltStart; +template <class ELFT> typename ElfSym<ELFT>::Elf_Sym ElfSym<ELFT>::RelaIpltEnd; + } // namespace elf2 } // namespace lld diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index f2973d4c2d0..6bc6e6f1a6e 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -587,9 +587,9 @@ static void addIRelocMarkers(SymbolTable<ELFT> &Symtab, bool IsDynamic) { Symtab.addAbsolute(Name, Sym); }; AddMarker(IsRela ? "__rela_iplt_start" : "__rel_iplt_start", - DefinedRegular<ELFT>::RelaIpltStart); + ElfSym<ELFT>::RelaIpltStart); AddMarker(IsRela ? "__rela_iplt_end" : "__rel_iplt_end", - DefinedRegular<ELFT>::RelaIpltEnd); + ElfSym<ELFT>::RelaIpltEnd); } template <class ELFT> static bool includeInSymtab(const SymbolBody &B) { @@ -598,7 +598,7 @@ template <class ELFT> static bool includeInSymtab(const SymbolBody &B) { // Don't include synthetic symbols like __init_array_start in every output. if (auto *U = dyn_cast<DefinedRegular<ELFT>>(&B)) - if (&U->Sym == &DefinedRegular<ELFT>::IgnoreUndef) + if (&U->Sym == &ElfSym<ELFT>::IgnoreUndef) return false; return true; @@ -723,14 +723,14 @@ template <class ELFT> void Writer<ELFT>::createSections() { // So, if this symbol is referenced, we just add the placeholder here // and update its value later. if (Symtab.find("_end")) - Symtab.addAbsolute("_end", DefinedRegular<ELFT>::End); + Symtab.addAbsolute("_end", ElfSym<ELFT>::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", DefinedRegular<ELFT>::End); + Symtab.addAbsolute("end", ElfSym<ELFT>::End); // Scan relocations. This must be done after every symbol is declared so that // we can correctly decide if a dynamic relocation is needed. @@ -1035,20 +1035,19 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() { // Update "_end" and "end" symbols so that they // point to the end of the data segment. - DefinedRegular<ELFT>::End.st_value = VA; + ElfSym<ELFT>::End.st_value = VA; // Update __rel_iplt_start/__rel_iplt_end to wrap the // rela.plt section. if (Out<ELFT>::RelaPlt) { uintX_t Start = Out<ELFT>::RelaPlt->getVA(); - DefinedRegular<ELFT>::RelaIpltStart.st_value = Start; - DefinedRegular<ELFT>::RelaIpltEnd.st_value = - Start + Out<ELFT>::RelaPlt->getSize(); + ElfSym<ELFT>::RelaIpltStart.st_value = Start; + ElfSym<ELFT>::RelaIpltEnd.st_value = Start + Out<ELFT>::RelaPlt->getSize(); } // Update MIPS _gp absolute symbol so that it points to the static data. if (Config->EMachine == EM_MIPS) - DefinedRegular<ELFT>::MipsGp.st_value = getMipsGpAddr<ELFT>(); + ElfSym<ELFT>::MipsGp.st_value = getMipsGpAddr<ELFT>(); } // Returns the number of PHDR entries. |