[lld] r309840 - Use more consistent names

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 10:35:18 PDT 2017


Author: rafael
Date: Wed Aug  2 10:35:18 2017
New Revision: 309840

URL: http://llvm.org/viewvc/llvm-project?rev=309840&view=rev
Log:
Use more consistent names

Reviewing another change I noticed that we use "getSymbols" to mean
different things in different files. Depending on the file it can
return

ArrayRef<StringRef>
ArrayRef<SymbolBody*>
ArrayRef<Symbol*>
ArrayRef<Elf_Sym>

With this change it always returns an ArrayRef<SymbolBody*>. The other
functions are renamed getELFsyms() and getSymbolNames().

Note that we cannot return ArrayRef<Symbol*> instead of
ArreyRef<SymbolBody*> because local symbols have a SymbolBody but not
a Symbol.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/GdbIndex.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/LTO.cpp
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=309840&r1=309839&r2=309840&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Aug  2 10:35:18 2017
@@ -942,8 +942,8 @@ static void excludeLibs(opt::InputArgLis
   for (InputFile *File : Files)
     if (auto *F = dyn_cast<ArchiveFile>(File))
       if (All || Libs.count(path::filename(F->getName())))
-        for (Symbol *Sym : F->getSymbols())
-          Sym->VersionId = VER_NDX_LOCAL;
+        for (SymbolBody *Sym : F->getSymbols())
+          Sym->symbol()->VersionId = VER_NDX_LOCAL;
 }
 
 // Do actual linking. Note that when this function is called,

Modified: lld/trunk/ELF/GdbIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/GdbIndex.cpp?rev=309840&r1=309839&r2=309840&view=diff
==============================================================================
--- lld/trunk/ELF/GdbIndex.cpp (original)
+++ lld/trunk/ELF/GdbIndex.cpp Wed Aug  2 10:35:18 2017
@@ -88,7 +88,7 @@ LLDDwarfObj<ELFT>::findAux(const InputSe
 
   const ObjFile<ELFT> *File = Sec.getFile<ELFT>();
   uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
-  const typename ELFT::Sym &Sym = File->getELFSymbols()[SymIndex];
+  const typename ELFT::Sym &Sym = File->getELFSyms()[SymIndex];
   uint32_t SecIndex = File->getSectionIndex(Sym);
   SymbolBody &B = File->getRelocTargetSym(Rel);
   auto &DR = cast<DefinedRegular>(B);

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=309840&r1=309839&r2=309840&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Aug  2 10:35:18 2017
@@ -133,13 +133,13 @@ ELFFileBase<ELFT>::ELFFileBase(Kind K, M
 }
 
 template <class ELFT>
-typename ELFT::SymRange ELFFileBase<ELFT>::getGlobalSymbols() {
-  return makeArrayRef(Symbols.begin() + FirstNonLocal, Symbols.end());
+typename ELFT::SymRange ELFFileBase<ELFT>::getGlobalELFSyms() {
+  return makeArrayRef(ELFSyms.begin() + FirstNonLocal, ELFSyms.end());
 }
 
 template <class ELFT>
 uint32_t ELFFileBase<ELFT>::getSectionIndex(const Elf_Sym &Sym) const {
-  return check(getObj().getSectionIndex(&Sym, Symbols, SymtabSHNDX),
+  return check(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX),
                toString(this));
 }
 
@@ -147,8 +147,8 @@ template <class ELFT>
 void ELFFileBase<ELFT>::initSymtab(ArrayRef<Elf_Shdr> Sections,
                                    const Elf_Shdr *Symtab) {
   FirstNonLocal = Symtab->sh_info;
-  Symbols = check(getObj().symbols(Symtab), toString(this));
-  if (FirstNonLocal == 0 || FirstNonLocal > Symbols.size())
+  ELFSyms = check(getObj().symbols(Symtab), toString(this));
+  if (FirstNonLocal == 0 || FirstNonLocal > ELFSyms.size())
     fatal(toString(this) + ": invalid sh_info in symbol table");
 
   StringTable = check(getObj().getStringTableForSymtab(*Symtab, Sections),
@@ -188,13 +188,13 @@ StringRef ObjFile<ELFT>::getShtGroupSign
                                               const Elf_Shdr &Sec) {
   // Group signatures are stored as symbol names in object files.
   // sh_info contains a symbol index, so we fetch a symbol and read its name.
-  if (this->Symbols.empty())
+  if (this->ELFSyms.empty())
     this->initSymtab(
         Sections,
         check(object::getSection<ELFT>(Sections, Sec.sh_link), toString(this)));
 
   const Elf_Sym *Sym = check(
-      object::getSymbol<ELFT>(this->Symbols, Sec.sh_info), toString(this));
+      object::getSymbol<ELFT>(this->ELFSyms, Sec.sh_info), toString(this));
   StringRef Signature = check(Sym->getName(this->StringTable), toString(this));
 
   // As a special case, if a symbol is a section symbol and has no name,
@@ -523,8 +523,8 @@ StringRef ObjFile<ELFT>::getSectionName(
 }
 
 template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
-  SymbolBodies.reserve(this->Symbols.size());
-  for (const Elf_Sym &Sym : this->Symbols)
+  SymbolBodies.reserve(this->ELFSyms.size());
+  for (const Elf_Sym &Sym : this->ELFSyms)
     SymbolBodies.push_back(createSymbolBody(&Sym));
 }
 
@@ -617,7 +617,7 @@ ArchiveFile::ArchiveFile(std::unique_ptr
 template <class ELFT> void ArchiveFile::parse() {
   Symbols.reserve(File->getNumberOfSymbols());
   for (const Archive::Symbol &Sym : File->symbols())
-    Symbols.push_back(Symtab->addLazyArchive<ELFT>(this, Sym));
+    Symbols.push_back(Symtab->addLazyArchive<ELFT>(this, Sym)->body());
 }
 
 // Returns a buffer pointing to a member file containing a given symbol.
@@ -654,7 +654,7 @@ template <class ELFT>
 const typename ELFT::Shdr *
 SharedFile<ELFT>::getSection(const Elf_Sym &Sym) const {
   return check(
-      this->getObj().getSection(&Sym, this->Symbols, this->SymtabSHNDX),
+      this->getObj().getSection(&Sym, this->ELFSyms, this->SymtabSHNDX),
       toString(this));
 }
 
@@ -689,7 +689,7 @@ template <class ELFT> void SharedFile<EL
     }
   }
 
-  if (this->VersymSec && this->Symbols.empty())
+  if (this->VersymSec && this->ELFSyms.empty())
     error("SHT_GNU_versym should be associated with symbol table");
 
   // Search for a DT_SONAME tag to initialize this->SoName.
@@ -756,7 +756,7 @@ template <class ELFT> void SharedFile<EL
   const Elf_Versym *Versym = nullptr;
   std::vector<const Elf_Verdef *> Verdefs = parseVerdefs(Versym);
 
-  Elf_Sym_Range Syms = this->getGlobalSymbols();
+  Elf_Sym_Range Syms = this->getGlobalELFSyms();
   for (const Elf_Sym &Sym : Syms) {
     unsigned VersymIndex = 0;
     if (Versym) {
@@ -899,7 +899,8 @@ void BitcodeFile::parse(DenseSet<CachedH
     KeptComdats.push_back(ComdatGroups.insert(CachedHashStringRef(S)).second);
 
   for (const lto::InputFile::Symbol &ObjSym : Obj->symbols())
-    Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, this));
+    Symbols.push_back(
+        createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, this)->body());
 }
 
 static ELFKind getELFKind(MemoryBufferRef MB) {
@@ -1001,7 +1002,7 @@ InputFile *LazyObjFile::fetch() {
 }
 
 template <class ELFT> void LazyObjFile::parse() {
-  for (StringRef Sym : getSymbols())
+  for (StringRef Sym : getSymbolNames())
     Symtab->addLazyObject<ELFT>(Sym, *this);
 }
 
@@ -1041,7 +1042,7 @@ std::vector<StringRef> LazyObjFile::getB
 }
 
 // Returns a vector of globally-visible defined symbol names.
-std::vector<StringRef> LazyObjFile::getSymbols() {
+std::vector<StringRef> LazyObjFile::getSymbolNames() {
   if (isBitcode(this->MB))
     return getBitcodeSymbols();
 

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=309840&r1=309839&r2=309840&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Wed Aug  2 10:35:18 2017
@@ -126,11 +126,11 @@ public:
 
   uint32_t getSectionIndex(const Elf_Sym &Sym) const;
 
-  Elf_Sym_Range getGlobalSymbols();
-  Elf_Sym_Range getELFSymbols() const { return Symbols; }
+  Elf_Sym_Range getGlobalELFSyms();
+  Elf_Sym_Range getELFSyms() const { return ELFSyms; }
 
 protected:
-  ArrayRef<Elf_Sym> Symbols;
+  ArrayRef<Elf_Sym> ELFSyms;
   uint32_t FirstNonLocal = 0;
   ArrayRef<Elf_Word> SymtabSHNDX;
   StringRef StringTable;
@@ -244,7 +244,7 @@ public:
   InputFile *fetch();
 
 private:
-  std::vector<StringRef> getSymbols();
+  std::vector<StringRef> getSymbolNames();
   template <class ELFT> std::vector<StringRef> getElfSymbols();
   std::vector<StringRef> getBitcodeSymbols();
 
@@ -258,7 +258,7 @@ public:
   explicit ArchiveFile(std::unique_ptr<Archive> &&File);
   static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }
   template <class ELFT> void parse();
-  ArrayRef<Symbol *> getSymbols() { return Symbols; }
+  ArrayRef<SymbolBody *> getSymbols() { return Symbols; }
 
   // Returns a memory buffer for a given symbol and the offset in the archive
   // for the member. An empty memory buffer and an offset of zero
@@ -269,7 +269,7 @@ public:
 private:
   std::unique_ptr<Archive> File;
   llvm::DenseSet<uint64_t> Seen;
-  std::vector<Symbol *> Symbols;
+  std::vector<SymbolBody *> Symbols;
 };
 
 class BitcodeFile : public InputFile {
@@ -279,12 +279,12 @@ public:
   static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
   template <class ELFT>
   void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
-  ArrayRef<Symbol *> getSymbols() { return Symbols; }
+  ArrayRef<SymbolBody *> getSymbols() { return Symbols; }
   std::unique_ptr<llvm::lto::InputFile> Obj;
   static std::vector<BitcodeFile *> Instances;
 
 private:
-  std::vector<Symbol *> Symbols;
+  std::vector<SymbolBody *> Symbols;
 };
 
 // .so file.

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=309840&r1=309839&r2=309840&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Wed Aug  2 10:35:18 2017
@@ -127,15 +127,15 @@ static void undefine(Symbol *S) {
 void BitcodeCompiler::add(BitcodeFile &F) {
   lto::InputFile &Obj = *F.Obj;
   unsigned SymNum = 0;
-  std::vector<Symbol *> Syms = F.getSymbols();
+  std::vector<SymbolBody *> Syms = F.getSymbols();
   std::vector<lto::SymbolResolution> Resols(Syms.size());
 
   // Provide a resolution to the LTO API for each symbol.
   for (const lto::InputFile::Symbol &ObjSym : Obj.symbols()) {
-    Symbol *Sym = Syms[SymNum];
+    SymbolBody *B = Syms[SymNum];
+    Symbol *Sym = B->symbol();
     lto::SymbolResolution &R = Resols[SymNum];
     ++SymNum;
-    SymbolBody *B = Sym->body();
 
     // Ideally we shouldn't check for SF_Undefined but currently IRObjectFile
     // reports two symbols for module ASM defined. Without this check, lld

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=309840&r1=309839&r2=309840&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Aug  2 10:35:18 2017
@@ -457,7 +457,7 @@ static std::vector<SharedSymbol *> getSy
   uint64_t Value = SS->getValue<ELFT>();
 
   std::vector<SharedSymbol *> Ret;
-  for (const Elf_Sym &S : File->getGlobalSymbols()) {
+  for (const Elf_Sym &S : File->getGlobalELFSyms()) {
     if (S.st_shndx != Shndx || S.st_value != Value)
       continue;
     StringRef Name = check(S.getName(File->getStringTable()));




More information about the llvm-commits mailing list