[lld] r256408 - Factor out static members from DefinedRegular.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 13 06:16:30 PST 2016


It might be possible to make it even smaller by in the .h having just

namespace ElfSym {
extern Elf_Sym MipsGp;
...
}

and defining them in a .cpp file.


Cheers,
Rafael



On 25 December 2015 at 01:12, Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Fri Dec 25 00:12:18 2015
> New Revision: 256408
>
> URL: http://llvm.org/viewvc/llvm-project?rev=256408&view=rev
> Log:
> Factor out static members from DefinedRegular.
>
> This patch moves statically-allocated Elf_Sym objects out
> of DefinedRegular class, so that the class definition becomes
> smaller.
>
> Modified:
>     lld/trunk/ELF/Driver.cpp
>     lld/trunk/ELF/SymbolTable.cpp
>     lld/trunk/ELF/Symbols.cpp
>     lld/trunk/ELF/Symbols.h
>     lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=256408&r1=256407&r2=256408&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Driver.cpp (original)
> +++ lld/trunk/ELF/Driver.cpp Fri Dec 25 00:12:18 2015
> @@ -279,7 +279,7 @@ template <class ELFT> void LinkerDriver:
>      // 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)
>
> Modified: lld/trunk/ELF/SymbolTable.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=256408&r1=256407&r2=256408&view=diff
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.cpp (original)
> +++ lld/trunk/ELF/SymbolTable.cpp Fri Dec 25 00:12:18 2015
> @@ -112,7 +112,7 @@ void SymbolTable<ELFT>::addSynthetic(Str
>  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;
>  }
>
> Modified: lld/trunk/ELF/Symbols.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=256408&r1=256407&r2=256408&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Symbols.cpp (original)
> +++ lld/trunk/ELF/Symbols.cpp Fri Dec 25 00:12:18 2015
> @@ -120,9 +120,9 @@ std::unique_ptr<InputFile> Lazy::getMemb
>  }
>
>  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() {
>
> Modified: lld/trunk/ELF/Symbols.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=256408&r1=256407&r2=256408&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Symbols.h (original)
> +++ lld/trunk/ELF/Symbols.h Fri Dec 25 00:12:18 2015
> @@ -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
>
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=256408&r1=256407&r2=256408&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Fri Dec 25 00:12:18 2015
> @@ -587,9 +587,9 @@ static void addIRelocMarkers(SymbolTable
>          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 includ
>
>    // 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>:
>    // 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>:
>
>    // 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.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list