[lld] r267640 - ELF: Merge UndefinedBitcode and UndefinedElf. NFC.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 17:05:06 PDT 2016


Author: pcc
Date: Tue Apr 26 19:05:06 2016
New Revision: 267640

URL: http://llvm.org/viewvc/llvm-project?rev=267640&view=rev
Log:
ELF: Merge UndefinedBitcode and UndefinedElf. NFC.

Differential Revision: http://reviews.llvm.org/D19566

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=267640&r1=267639&r2=267640&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Apr 26 19:05:06 2016
@@ -316,7 +316,8 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
   InputSectionBase<ELFT> *Sec = getSection(*Sym);
   if (Binding == STB_LOCAL) {
     if (Sym->st_shndx == SHN_UNDEF)
-      return new (Alloc) UndefinedElf<ELFT>(*Sym);
+      return new (Alloc)
+          Undefined(Sym->st_name, Sym->st_other, Sym->getType(), Sym->st_size);
     return new (Alloc) DefinedRegular<ELFT>(*Sym, Sec);
   }
 
@@ -324,7 +325,9 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
 
   switch (Sym->st_shndx) {
   case SHN_UNDEF:
-    return new (Alloc) UndefinedElf<ELFT>(Name, *Sym);
+    return new (Alloc)
+        Undefined(Name, Binding, Sym->st_other, Sym->getType(), Sym->st_size,
+                  /*IsBitcode*/ false);
   case SHN_COMMON:
     return new (Alloc) DefinedCommon(Name, Sym->st_size, Sym->st_value, Binding,
                                      Sym->st_other, Sym->getType());
@@ -337,7 +340,9 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
   case STB_WEAK:
   case STB_GNU_UNIQUE:
     if (Sec == &InputSection<ELFT>::Discarded)
-      return new (Alloc) UndefinedElf<ELFT>(Name, *Sym);
+      return new (Alloc)
+          Undefined(Name, Binding, Sym->st_other, Sym->getType(), Sym->st_size,
+                    /*IsBitcode*/ false);
     return new (Alloc) DefinedRegular<ELFT>(Name, *Sym, Sec);
   }
 }
@@ -470,6 +475,7 @@ BitcodeFile::createBody(const DenseSet<c
 
   uint32_t Flags = Sym.getFlags();
   bool IsWeak = Flags & BasicSymbolRef::SF_Weak;
+  uint32_t Binding = IsWeak ? STB_WEAK : STB_GLOBAL;
 
   uint8_t Visibility;
   if (GV)
@@ -482,23 +488,23 @@ BitcodeFile::createBody(const DenseSet<c
   if (GV)
     if (const Comdat *C = GV->getComdat())
       if (!KeptComdats.count(C)) {
-        Body = new (Alloc)
-          UndefinedBitcode(NameRef, IsWeak, Visibility);
+        Body = new (Alloc) Undefined(NameRef, Binding, Visibility, /*Type*/ 0,
+                                     /*Size*/ 0, /*IsBitcode*/ true);
         return Body;
       }
 
   const Module &M = Obj.getModule();
   if (Flags & BasicSymbolRef::SF_Undefined)
-    return new (Alloc) UndefinedBitcode(NameRef, IsWeak, Visibility);
+    return new (Alloc) Undefined(NameRef, Binding, Visibility, /*Type*/ 0,
+                                 /*Size*/ 0, /*IsBitcode*/ true);
   if (Flags & BasicSymbolRef::SF_Common) {
     // FIXME: Set SF_Common flag correctly for module asm symbols, and expose
     // size and alignment.
     assert(GV);
     const DataLayout &DL = M.getDataLayout();
     uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
-    return new (Alloc)
-        DefinedCommon(NameRef, Size, GV->getAlignment(),
-                      IsWeak ? STB_WEAK : STB_GLOBAL, Visibility, /*Type*/ 0);
+    return new (Alloc) DefinedCommon(NameRef, Size, GV->getAlignment(), Binding,
+                                     Visibility, /*Type*/ 0);
   }
   return new (Alloc) DefinedBitcode(NameRef, IsWeak, Visibility);
 }

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=267640&r1=267639&r2=267640&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Apr 26 19:05:06 2016
@@ -1503,8 +1503,7 @@ SymbolTableSection<ELFT>::getOutputSecti
     if (cast<SharedSymbol<ELFT>>(Sym)->needsCopy())
       return Out<ELFT>::Bss;
     break;
-  case SymbolBody::UndefinedElfKind:
-  case SymbolBody::UndefinedBitcodeKind:
+  case SymbolBody::UndefinedKind:
   case SymbolBody::LazyArchiveKind:
   case SymbolBody::LazyObjectKind:
     break;

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=267640&r1=267639&r2=267640&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Apr 26 19:05:06 2016
@@ -151,7 +151,8 @@ template <class ELFT> void SymbolTable<E
 template <class ELFT>
 SymbolBody *SymbolTable<ELFT>::addUndefined(StringRef Name) {
   auto *Sym = new (Alloc)
-      UndefinedElf<ELFT>(Name, STB_GLOBAL, STV_DEFAULT, /*Type*/ 0);
+      Undefined(Name, STB_GLOBAL, STV_DEFAULT, /*Type*/ 0, /*Size*/ 0,
+                /*IsBitcode*/ false);
   resolve(Sym);
   return Sym;
 }
@@ -314,7 +315,7 @@ template <class ELFT> Symbol *SymbolTabl
   if (K == SymbolBody::DefinedRegularKind ||
       K == SymbolBody::DefinedCommonKind ||
       K == SymbolBody::DefinedSyntheticKind ||
-      K == SymbolBody::UndefinedElfKind)
+      (K == SymbolBody::UndefinedKind && !New->IsUndefinedBitcode))
     Sym->IsUsedInRegularObj = true;
   return Sym;
 }

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=267640&r1=267639&r2=267640&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Apr 26 19:05:06 2016
@@ -75,8 +75,7 @@ static typename ELFT::uint getSymVA(cons
       return Body.getPltVA<ELFT>();
     return Out<ELFT>::Bss->getVA() + SS.OffsetInBss;
   }
-  case SymbolBody::UndefinedElfKind:
-  case SymbolBody::UndefinedBitcodeKind:
+  case SymbolBody::UndefinedKind:
     return 0;
   case SymbolBody::LazyArchiveKind:
   case SymbolBody::LazyObjectKind:
@@ -175,7 +174,7 @@ template <class ELFT> typename ELFT::uin
     return DR->Size;
   if (const auto *S = dyn_cast<SharedSymbol<ELFT>>(this))
     return S->Sym.st_size;
-  if (const auto *U = dyn_cast<UndefinedElf<ELFT>>(this))
+  if (const auto *U = dyn_cast<Undefined>(this))
     return U->Size;
   return 0;
 }
@@ -232,27 +231,18 @@ bool DefinedBitcode::classof(const Symbo
   return S->kind() == DefinedBitcodeKind;
 }
 
-UndefinedBitcode::UndefinedBitcode(StringRef N, bool IsWeak, uint8_t StOther)
-    : SymbolBody(SymbolBody::UndefinedBitcodeKind, N,
-                 IsWeak ? STB_WEAK : STB_GLOBAL, StOther, 0 /* Type */) {}
-
-template <typename ELFT>
-UndefinedElf<ELFT>::UndefinedElf(StringRef N, const Elf_Sym &Sym)
-    : SymbolBody(SymbolBody::UndefinedElfKind, N, Sym.getBinding(),
-                 Sym.st_other, Sym.getType()),
-      Size(Sym.st_size) {}
-
-template <typename ELFT>
-UndefinedElf<ELFT>::UndefinedElf(StringRef Name, uint8_t Binding,
-                                 uint8_t StOther, uint8_t Type)
-    : SymbolBody(SymbolBody::UndefinedElfKind, Name, Binding, StOther, Type) {}
+Undefined::Undefined(StringRef Name, uint8_t Binding, uint8_t StOther,
+                     uint8_t Type, uint64_t Size, bool IsBitcode)
+    : SymbolBody(SymbolBody::UndefinedKind, Name, Binding, StOther, Type),
+      Size(Size) {
+  this->IsUndefinedBitcode = IsBitcode;
+}
 
-template <typename ELFT>
-UndefinedElf<ELFT>::UndefinedElf(const Elf_Sym &Sym)
-    : SymbolBody(SymbolBody::UndefinedElfKind, Sym.st_name, Sym.st_other,
-                 Sym.getType()),
-      Size(Sym.st_size) {
-  assert(Sym.getBinding() == STB_LOCAL);
+Undefined::Undefined(uint32_t NameOffset, uint8_t StOther, uint8_t Type,
+                     uint64_t Size)
+    : SymbolBody(SymbolBody::UndefinedKind, NameOffset, StOther, Type),
+      Size(Size) {
+  this->IsUndefinedBitcode = false;
 }
 
 template <typename ELFT>
@@ -360,11 +350,6 @@ template uint32_t SymbolBody::template g
 template uint64_t SymbolBody::template getThunkVA<ELF64LE>() const;
 template uint64_t SymbolBody::template getThunkVA<ELF64BE>() const;
 
-template class elf::UndefinedElf<ELF32LE>;
-template class elf::UndefinedElf<ELF32BE>;
-template class elf::UndefinedElf<ELF64LE>;
-template class elf::UndefinedElf<ELF64BE>;
-
 template class elf::DefinedSynthetic<ELF32LE>;
 template class elf::DefinedSynthetic<ELF32BE>;
 template class elf::DefinedSynthetic<ELF64LE>;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=267640&r1=267639&r2=267640&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Apr 26 19:05:06 2016
@@ -90,8 +90,7 @@ public:
     DefinedBitcodeKind,
     DefinedSyntheticKind,
     DefinedLast = DefinedSyntheticKind,
-    UndefinedElfKind,
-    UndefinedBitcodeKind,
+    UndefinedKind,
     LazyArchiveKind,
     LazyObjectKind,
   };
@@ -99,9 +98,7 @@ public:
   Kind kind() const { return static_cast<Kind>(SymbolKind); }
 
   bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
-  bool isUndefined() const {
-    return SymbolKind == UndefinedBitcodeKind || SymbolKind == UndefinedElfKind;
-  }
+  bool isUndefined() const { return SymbolKind == UndefinedKind; }
   bool isDefined() const { return SymbolKind <= DefinedLast; }
   bool isCommon() const { return SymbolKind == DefinedCommonKind; }
   bool isLazy() const {
@@ -177,6 +174,11 @@ public:
   // symbol or if the symbol should point to its plt entry.
   unsigned NeedsCopyOrPltAddr : 1;
 
+  // True if the symbol is undefined and comes from a bitcode file. We need to
+  // keep track of this because undefined symbols only prevent internalization
+  // of bitcode symbols if they did not come from a bitcode file.
+  unsigned IsUndefinedBitcode : 1;
+
   // The following fields have the same meaning as the ELF symbol attributes.
   uint8_t Type;    // symbol type
   uint8_t Binding; // symbol binding
@@ -307,28 +309,16 @@ public:
   const OutputSectionBase<ELFT> &Section;
 };
 
-class UndefinedBitcode : public SymbolBody {
+class Undefined : public SymbolBody {
 public:
-  UndefinedBitcode(StringRef N, bool IsWeak, uint8_t StOther);
+  Undefined(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t Type,
+            uint64_t Size, bool IsBitcode);
+  Undefined(uint32_t NameOffset, uint8_t StOther, uint8_t Type, uint64_t Size);
 
-  static bool classof(const SymbolBody *S) {
-    return S->kind() == UndefinedBitcodeKind;
-  }
-};
-
-template <class ELFT> class UndefinedElf : public SymbolBody {
-  typedef typename ELFT::uint uintX_t;
-  typedef typename ELFT::Sym Elf_Sym;
-
-public:
-  UndefinedElf(StringRef N, const Elf_Sym &Sym);
-  UndefinedElf(const Elf_Sym &Sym);
-  UndefinedElf(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t Type);
-
-  uintX_t Size;
+  uint64_t Size;
 
   static bool classof(const SymbolBody *S) {
-    return S->kind() == SymbolBody::UndefinedElfKind;
+    return S->kind() == UndefinedKind;
   }
 };
 




More information about the llvm-commits mailing list