Remove one of SymbolTable::addRegular function that forwards other addRegular.
authorRui Ueyama <ruiu@google.com>
Wed, 23 Nov 2016 06:59:47 +0000 (06:59 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 23 Nov 2016 06:59:47 +0000 (06:59 +0000)
So that we have less number of overloaded functions.

llvm-svn: 287745

lld/ELF/InputFiles.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/SymbolTable.h
lld/ELF/Writer.cpp

index 7d58ee9..f697fd2 100644 (file)
@@ -438,6 +438,7 @@ template <class ELFT>
 SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
   int Binding = Sym->getBinding();
   InputSectionBase<ELFT> *Sec = getSection(*Sym);
+
   if (Binding == STB_LOCAL) {
     if (Sym->getType() == STT_FILE)
       SourceFile = check(Sym->getName(this->StringTable));
@@ -452,20 +453,23 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
   }
 
   StringRef Name = check(Sym->getName(this->StringTable));
+  uint8_t StOther = Sym->st_other;
+  uint8_t Type = Sym->getType();
+  uintX_t Value = Sym->st_value;
+  uintX_t Size = Sym->st_size;
 
   switch (Sym->st_shndx) {
   case SHN_UNDEF:
-    return elf::Symtab<ELFT>::X->addUndefined(Name, Binding, Sym->st_other,
-                                              Sym->getType(),
-                                              /*CanOmitFromDynSym*/ false, this)
+    return elf::Symtab<ELFT>::X
+        ->addUndefined(Name, Binding, StOther, Type,
+                       /*CanOmitFromDynSym=*/false, this)
         ->body();
   case SHN_COMMON:
-    if (Sym->st_value == 0 || Sym->st_value >= UINT32_MAX)
+    if (Value == 0 || Value >= UINT32_MAX)
       fatal(getFilename(this) + ": common symbol '" + Name +
-            "' has invalid alignment: " + Twine(Sym->st_value));
-    return elf::Symtab<ELFT>::X->addCommon(Name, Sym->st_size, Sym->st_value,
-                                           Binding, Sym->st_other,
-                                           Sym->getType(), this)
+            "' has invalid alignment: " + Twine(Value));
+    return elf::Symtab<ELFT>::X
+        ->addCommon(Name, Size, Value, Binding, StOther, Type, this)
         ->body();
   }
 
@@ -476,12 +480,13 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
   case STB_WEAK:
   case STB_GNU_UNIQUE:
     if (Sec == &InputSection<ELFT>::Discarded)
-      return elf::Symtab<ELFT>::X->addUndefined(Name, Binding, Sym->st_other,
-                                                Sym->getType(),
-                                                /*CanOmitFromDynSym*/ false,
-                                                this)
+      return elf::Symtab<ELFT>::X
+          ->addUndefined(Name, Binding, StOther, Type,
+                         /*CanOmitFromDynSym=*/false, this)
           ->body();
-    return elf::Symtab<ELFT>::X->addRegular(Name, *Sym, Sec, this)->body();
+    return elf::Symtab<ELFT>::X
+        ->addRegular(Name, StOther, Type, Value, Size, Binding, Sec, this)
+        ->body();
   }
 }
 
index 1e27f21..c434f01 100644 (file)
@@ -367,14 +367,6 @@ static void reportDuplicate(SymbolBody *Existing,
 }
 
 template <typename ELFT>
-Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, const Elf_Sym &Sym,
-                                      InputSectionBase<ELFT> *Section,
-                                      InputFile *File) {
-  return addRegular(Name, Sym.st_other, Sym.getType(), Sym.st_value,
-                    Sym.st_size, Sym.getBinding(), Section, File);
-}
-
-template <typename ELFT>
 Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, uint8_t StOther,
                                       uint8_t Type, uintX_t Value, uintX_t Size,
                                       uint8_t Binding,
index 7f49c4c..bb4e371 100644 (file)
@@ -61,8 +61,6 @@ public:
   Symbol *addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
                      uintX_t Value, uintX_t Size, uint8_t Binding,
                      InputSectionBase<ELFT> *Section, InputFile *File);
-  Symbol *addRegular(StringRef Name, const Elf_Sym &Sym,
-                     InputSectionBase<ELFT> *Section, InputFile *File);
 
   Symbol *addSynthetic(StringRef N, const OutputSectionBase *Section,
                        uintX_t Value, uint8_t StOther);
index 460259f..9850e7c 100644 (file)
@@ -561,15 +561,13 @@ static Symbol *addOptionalSynthetic(StringRef Name, OutputSectionBase *Sec,
 }
 
 template <class ELFT>
-static Symbol *addRegular(StringRef Name, InputSectionBase<ELFT> *IS,
+static Symbol *addRegular(StringRef Name, InputSectionBase<ELFT> *Sec,
                           typename ELFT::uint Value) {
-  typename ELFT::Sym LocalHidden = {};
   // The linker generated symbols are added as STB_WEAK to allow user defined
   // ones to override them.
-  LocalHidden.setBindingAndType(STB_WEAK, STT_NOTYPE);
-  LocalHidden.setVisibility(STV_HIDDEN);
-  LocalHidden.st_value = Value;
-  return Symtab<ELFT>::X->addRegular(Name, LocalHidden, IS, nullptr);
+  return Symtab<ELFT>::X->addRegular(Name, STV_HIDDEN, STT_NOTYPE, Value,
+                                     /*Size=*/0, STB_WEAK, Sec,
+                                     /*File=*/nullptr);
 }
 
 template <class ELFT>