[lld] r321404 - Detemplate reportDuplicate.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 23 09:21:39 PST 2017


Author: rafael
Date: Sat Dec 23 09:21:39 2017
New Revision: 321404

URL: http://llvm.org/viewvc/llvm-project?rev=321404&view=rev
Log:
Detemplate reportDuplicate.

We normally avoid "switch (Config->EKind)", but in this case I think
it is worth it.

It is only executed when there is an error and it allows detemplating
a lot of code.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Writer.cpp
    lld/trunk/ELF/Writer.h

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Dec 23 09:21:39 2017
@@ -1056,7 +1056,7 @@ template <class ELFT> void LinkerDriver:
 
   // We need to create some reserved symbols such as _end. Create them.
   if (!Config->Relocatable)
-    addReservedSymbols<ELFT>();
+    addReservedSymbols();
 
   // Apply version scripts.
   Symtab->scanVersionScript();

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Sat Dec 23 09:21:39 2017
@@ -32,6 +32,7 @@
 using namespace llvm;
 using namespace llvm::ELF;
 using namespace llvm::object;
+using namespace llvm::sys;
 using namespace llvm::sys::fs;
 
 using namespace lld;
@@ -69,6 +70,50 @@ Optional<MemoryBufferRef> elf::readFile(
   return MBRef;
 }
 
+// Concatenates arguments to construct a string representing an error location.
+static std::string createFileLineMsg(StringRef Path, unsigned Line) {
+  std::string Filename = path::filename(Path);
+  std::string Lineno = ":" + std::to_string(Line);
+  if (Filename == Path)
+    return Filename + Lineno;
+  return Filename + Lineno + " (" + Path.str() + Lineno + ")";
+}
+
+template <class ELFT>
+static std::string getSrcMsgAux(ObjFile<ELFT> &File, const Symbol &Sym,
+                                InputSectionBase &Sec, uint64_t Offset) {
+  // In DWARF, functions and variables are stored to different places.
+  // First, lookup a function for a given offset.
+  if (Optional<DILineInfo> Info = File.getDILineInfo(&Sec, Offset))
+    return createFileLineMsg(Info->FileName, Info->Line);
+
+  // If it failed, lookup again as a variable.
+  if (Optional<std::pair<std::string, unsigned>> FileLine =
+          File.getVariableLoc(Sym.getName()))
+    return createFileLineMsg(FileLine->first, FileLine->second);
+
+  // File.SourceFile contains STT_FILE symbol, and that is a last resort.
+  return File.SourceFile;
+}
+
+std::string InputFile::getSrcMsg(const Symbol &Sym, InputSectionBase &Sec,
+                                 uint64_t Offset) {
+  if (kind() != ObjKind)
+    return "";
+  switch (Config->EKind) {
+  default:
+    llvm_unreachable("Invalid kind");
+  case ELF32LEKind:
+    return getSrcMsgAux(cast<ObjFile<ELF32LE>>(*this), Sym, Sec, Offset);
+  case ELF32BEKind:
+    return getSrcMsgAux(cast<ObjFile<ELF32BE>>(*this), Sym, Sec, Offset);
+  case ELF64LEKind:
+    return getSrcMsgAux(cast<ObjFile<ELF64LE>>(*this), Sym, Sec, Offset);
+  case ELF64BEKind:
+    return getSrcMsgAux(cast<ObjFile<ELF64BE>>(*this), Sym, Sec, Offset);
+  }
+}
+
 template <class ELFT> void ObjFile<ELFT>::initializeDwarf() {
   DWARFContext Dwarf(make_unique<LLDDwarfObj<ELFT>>(this));
   const DWARFObject &Obj = Dwarf.getDWARFObj();
@@ -646,8 +691,8 @@ template <class ELFT> Symbol *ObjFile<EL
     if (Sec == &InputSection::Discarded)
       return Symtab->addUndefined<ELFT>(Name, Binding, StOther, Type,
                                         /*CanOmitFromDynSym=*/false, this);
-    return Symtab->addRegular<ELFT>(Name, StOther, Type, Value, Size, Binding,
-                                    Sec, this);
+    return Symtab->addRegular(Name, StOther, Type, Value, Size, Binding, Sec,
+                              this);
   }
 }
 
@@ -979,7 +1024,7 @@ static ELFKind getELFKind(MemoryBufferRe
   return (Endian == ELFDATA2LSB) ? ELF64LEKind : ELF64BEKind;
 }
 
-template <class ELFT> void BinaryFile::parse() {
+void BinaryFile::parse() {
   ArrayRef<uint8_t> Data = toArrayRef(MB.getBuffer());
   auto *Section = make<InputSection>(nullptr, SHF_ALLOC | SHF_WRITE,
                                      SHT_PROGBITS, 8, Data, ".data");
@@ -994,12 +1039,12 @@ template <class ELFT> void BinaryFile::p
     if (!isAlnum(S[I]))
       S[I] = '_';
 
-  Symtab->addRegular<ELFT>(Saver.save(S + "_start"), STV_DEFAULT, STT_OBJECT, 0,
-                           0, STB_GLOBAL, Section, nullptr);
-  Symtab->addRegular<ELFT>(Saver.save(S + "_end"), STV_DEFAULT, STT_OBJECT,
-                           Data.size(), 0, STB_GLOBAL, Section, nullptr);
-  Symtab->addRegular<ELFT>(Saver.save(S + "_size"), STV_DEFAULT, STT_OBJECT,
-                           Data.size(), 0, STB_GLOBAL, nullptr, nullptr);
+  Symtab->addRegular(Saver.save(S + "_start"), STV_DEFAULT, STT_OBJECT, 0, 0,
+                     STB_GLOBAL, Section, nullptr);
+  Symtab->addRegular(Saver.save(S + "_end"), STV_DEFAULT, STT_OBJECT,
+                     Data.size(), 0, STB_GLOBAL, Section, nullptr);
+  Symtab->addRegular(Saver.save(S + "_size"), STV_DEFAULT, STT_OBJECT,
+                     Data.size(), 0, STB_GLOBAL, nullptr, nullptr);
 }
 
 static bool isBitcode(MemoryBufferRef MB) {
@@ -1143,8 +1188,3 @@ template class elf::SharedFile<ELF32LE>;
 template class elf::SharedFile<ELF32BE>;
 template class elf::SharedFile<ELF64LE>;
 template class elf::SharedFile<ELF64BE>;
-
-template void BinaryFile::parse<ELF32LE>();
-template void BinaryFile::parse<ELF32BE>();
-template void BinaryFile::parse<ELF64LE>();
-template void BinaryFile::parse<ELF64BE>();

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Sat Dec 23 09:21:39 2017
@@ -109,6 +109,9 @@ public:
   // Cache for toString(). Only toString() should use this member.
   mutable std::string ToStringCache;
 
+  std::string getSrcMsg(const Symbol &Sym, InputSectionBase &Sec,
+                        uint64_t Offset);
+
 protected:
   InputFile(Kind K, MemoryBufferRef M);
   std::vector<InputSectionBase *> Sections;
@@ -327,7 +330,7 @@ class BinaryFile : public InputFile {
 public:
   explicit BinaryFile(MemoryBufferRef M) : InputFile(BinaryKind, M) {}
   static bool classof(const InputFile *F) { return F->kind() == BinaryKind; }
-  template <class ELFT> void parse();
+  void parse();
 };
 
 InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sat Dec 23 09:21:39 2017
@@ -24,7 +24,6 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/Endian.h"
-#include "llvm/Support/Path.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/xxhash.h"
 #include <mutex>
@@ -263,40 +262,17 @@ std::string InputSectionBase::getLocatio
   return (SrcFile + ":(" + Name + "+0x" + utohexstr(Offset) + ")").str();
 }
 
-// Concatenates arguments to construct a string representing an error location.
-static std::string createFileLineMsg(StringRef Path, unsigned Line) {
-  std::string Filename = path::filename(Path);
-  std::string Lineno = ":" + std::to_string(Line);
-  if (Filename == Path)
-    return Filename + Lineno;
-  return Filename + Lineno + " (" + Path.str() + Lineno + ")";
-}
-
 // This function is intended to be used for constructing an error message.
 // The returned message looks like this:
 //
 //   foo.c:42 (/home/alice/possibly/very/long/path/foo.c:42)
 //
 //  Returns an empty string if there's no way to get line info.
-template <class ELFT>
 std::string InputSectionBase::getSrcMsg(const Symbol &Sym, uint64_t Offset) {
   // Synthetic sections don't have input files.
-  ObjFile<ELFT> *File = getFile<ELFT>();
   if (!File)
     return "";
-
-  // In DWARF, functions and variables are stored to different places.
-  // First, lookup a function for a given offset.
-  if (Optional<DILineInfo> Info = File->getDILineInfo(this, Offset))
-    return createFileLineMsg(Info->FileName, Info->Line);
-
-  // If it failed, lookup again as a variable.
-  if (Optional<std::pair<std::string, unsigned>> FileLine =
-          File->getVariableLoc(Sym.getName()))
-    return createFileLineMsg(FileLine->first, FileLine->second);
-
-  // File->SourceFile contains STT_FILE symbol, and that is a last resort.
-  return File->SourceFile;
+  return File->getSrcMsg(Sym, *this, Offset);
 }
 
 // Returns a filename string along with an optional section name. This
@@ -1019,15 +995,6 @@ template std::string InputSectionBase::g
 template std::string InputSectionBase::getLocation<ELF64LE>(uint64_t);
 template std::string InputSectionBase::getLocation<ELF64BE>(uint64_t);
 
-template std::string InputSectionBase::getSrcMsg<ELF32LE>(const Symbol &,
-                                                          uint64_t);
-template std::string InputSectionBase::getSrcMsg<ELF32BE>(const Symbol &,
-                                                          uint64_t);
-template std::string InputSectionBase::getSrcMsg<ELF64LE>(const Symbol &,
-                                                          uint64_t);
-template std::string InputSectionBase::getSrcMsg<ELF64BE>(const Symbol &,
-                                                          uint64_t);
-
 template void InputSection::writeTo<ELF32LE>(uint8_t *);
 template void InputSection::writeTo<ELF32BE>(uint8_t *);
 template void InputSection::writeTo<ELF64LE>(uint8_t *);

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sat Dec 23 09:21:39 2017
@@ -168,7 +168,6 @@ public:
 
   // Returns a source location string. Used to construct an error message.
   template <class ELFT> std::string getLocation(uint64_t Offset);
-  template <class ELFT>
   std::string getSrcMsg(const Symbol &Sym, uint64_t Offset);
   std::string getObjMsg(uint64_t Offset);
 

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sat Dec 23 09:21:39 2017
@@ -70,12 +70,11 @@ using namespace lld::elf;
 // >>> defined in /home/alice/src/foo.o
 // >>> referenced by bar.c:12 (/home/alice/src/bar.c:12)
 // >>>               /home/alice/src/bar.o:(.text+0x1)
-template <class ELFT>
 static std::string getLocation(InputSectionBase &S, const Symbol &Sym,
                                uint64_t Off) {
   std::string Msg =
       "\n>>> defined in " + toString(Sym.File) + "\n>>> referenced by ";
-  std::string Src = S.getSrcMsg<ELFT>(Sym, Off);
+  std::string Src = S.getSrcMsg(Sym, Off);
   if (!Src.empty())
     Msg += Src + "\n>>>               ";
   return Msg + S.getObjMsg(Off);
@@ -365,7 +364,6 @@ static bool isRelExpr(RelExpr Expr) {
 //
 // If this function returns false, that means we need to emit a
 // dynamic relocation so that the relocation will be fixed at load-time.
-template <class ELFT>
 static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym,
                                      InputSectionBase &S, uint64_t RelOff) {
   // These expressions always compute a constant
@@ -410,7 +408,7 @@ static bool isStaticLinkTimeConstant(Rel
     return true;
 
   error("relocation " + toString(Type) + " cannot refer to absolute symbol: " +
-        toString(Sym) + getLocation<ELFT>(S, Sym, RelOff));
+        toString(Sym) + getLocation(S, Sym, RelOff));
   return true;
 }
 
@@ -625,13 +623,13 @@ static RelExpr adjustExpr(Symbol &Sym, R
         "can't create dynamic relocation " + toString(Type) + " against " +
         (Sym.getName().empty() ? "local symbol" : "symbol: " + toString(Sym)) +
         " in readonly segment; recompile object files with -fPIC" +
-        getLocation<ELFT>(S, Sym, RelOff));
+        getLocation(S, Sym, RelOff));
     return Expr;
   }
 
   if (Sym.getVisibility() != STV_DEFAULT) {
     error("cannot preempt symbol: " + toString(Sym) +
-          getLocation<ELFT>(S, Sym, RelOff));
+          getLocation(S, Sym, RelOff));
     return Expr;
   }
 
@@ -643,7 +641,7 @@ static RelExpr adjustExpr(Symbol &Sym, R
         error("unresolvable relocation " + toString(Type) +
               " against symbol '" + toString(*B) +
               "'; recompile with -fPIC or remove '-z nocopyreloc'" +
-              getLocation<ELFT>(S, Sym, RelOff));
+              getLocation(S, Sym, RelOff));
 
       addCopyRelSymbol<ELFT>(B);
     }
@@ -722,7 +720,6 @@ static int64_t computeAddend(const RelTy
 
 // Report an undefined symbol if necessary.
 // Returns true if this function printed out an error message.
-template <class ELFT>
 static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec,
                                  uint64_t Offset) {
   if (Config->UnresolvedSymbols == UnresolvedPolicy::IgnoreAll)
@@ -739,7 +736,7 @@ static bool maybeReportUndefined(Symbol
   std::string Msg =
       "undefined symbol: " + toString(Sym) + "\n>>> referenced by ";
 
-  std::string Src = Sec.getSrcMsg<ELFT>(Sym, Offset);
+  std::string Src = Sec.getSrcMsg(Sym, Offset);
   if (!Src.empty())
     Msg += Src + "\n>>>               ";
   Msg += Sec.getObjMsg(Offset);
@@ -899,7 +896,7 @@ static void scanRelocs(InputSectionBase
       continue;
 
     // Skip if the target symbol is an erroneous undefined symbol.
-    if (maybeReportUndefined<ELFT>(Sym, Sec, Rel.r_offset))
+    if (maybeReportUndefined(Sym, Sec, Rel.r_offset))
       continue;
 
     RelExpr Expr =
@@ -938,7 +935,7 @@ static void scanRelocs(InputSectionBase
       Expr = fromPlt(Expr);
 
     bool IsConstant =
-        isStaticLinkTimeConstant<ELFT>(Expr, Type, Sym, Sec, Rel.r_offset);
+        isStaticLinkTimeConstant(Expr, Type, Sym, Sec, Rel.r_offset);
 
     Expr = adjustExpr<ELFT>(Sym, Expr, Type, Sec, Rel.r_offset, IsConstant);
     if (errorCount())
@@ -997,7 +994,7 @@ static void scanRelocs(InputSectionBase
         errorOrWarn(
             "relocation " + toString(Type) +
             " cannot be used against shared object; recompile with -fPIC" +
-            getLocation<ELFT>(Sec, Sym, Offset));
+            getLocation(Sec, Sym, Offset));
 
       InX::RelaDyn->addReloc(
           {Target->getDynRel(Type), &Sec, Offset, false, &Sym, Addend});

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Sat Dec 23 09:21:39 2017
@@ -70,7 +70,7 @@ template <class ELFT> void SymbolTable::
   // Binary file
   if (auto *F = dyn_cast<BinaryFile>(File)) {
     BinaryFiles.push_back(F);
-    F->parse<ELFT>();
+    F->parse();
     return;
   }
 
@@ -135,11 +135,10 @@ template <class ELFT> void SymbolTable::
   }
 }
 
-template <class ELFT>
 Defined *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
                                   uint8_t Binding) {
-  Symbol *Sym = addRegular<ELFT>(Name, Visibility, STT_NOTYPE, 0, 0, Binding,
-                                 nullptr, nullptr);
+  Symbol *Sym =
+      addRegular(Name, Visibility, STT_NOTYPE, 0, 0, Binding, nullptr, nullptr);
   return cast<Defined>(Sym);
 }
 
@@ -424,9 +423,8 @@ static void reportDuplicate(Symbol *Sym,
               toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
 }
 
-template <class ELFT>
 static void reportDuplicate(Symbol *Sym, InputSectionBase *ErrSec,
-                            typename ELFT::uint ErrOffset) {
+                            uint64_t ErrOffset) {
   Defined *D = cast<Defined>(Sym);
   if (!D->Section || !ErrSec) {
     reportDuplicate(Sym, ErrSec ? ErrSec->File : nullptr);
@@ -441,9 +439,9 @@ static void reportDuplicate(Symbol *Sym,
   //   >>> defined at baz.c:563
   //   >>>            baz.o in archive libbaz.a
   auto *Sec1 = cast<InputSectionBase>(D->Section);
-  std::string Src1 = Sec1->getSrcMsg<ELFT>(*Sym, D->Value);
+  std::string Src1 = Sec1->getSrcMsg(*Sym, D->Value);
   std::string Obj1 = Sec1->getObjMsg(D->Value);
-  std::string Src2 = ErrSec->getSrcMsg<ELFT>(*Sym, ErrOffset);
+  std::string Src2 = ErrSec->getSrcMsg(*Sym, ErrOffset);
   std::string Obj2 = ErrSec->getObjMsg(ErrOffset);
 
   std::string Msg = "duplicate symbol: " + toString(*Sym) + "\n>>> defined at ";
@@ -456,7 +454,6 @@ static void reportDuplicate(Symbol *Sym,
   warnOrError(Msg);
 }
 
-template <typename ELFT>
 Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
                                 uint64_t Value, uint64_t Size, uint8_t Binding,
                                 SectionBase *Section, InputFile *File) {
@@ -470,8 +467,7 @@ Symbol *SymbolTable::addRegular(StringRe
     replaceSymbol<Defined>(S, File, Name, Binding, StOther, Type, Value, Size,
                            Section);
   else if (Cmp == 0)
-    reportDuplicate<ELFT>(S, dyn_cast_or_null<InputSectionBase>(Section),
-                          Value);
+    reportDuplicate(S, dyn_cast_or_null<InputSectionBase>(Section), Value);
   return S;
 }
 
@@ -797,28 +793,6 @@ template void SymbolTable::addCombinedLT
 template void SymbolTable::addCombinedLTOObject<ELF64LE>();
 template void SymbolTable::addCombinedLTOObject<ELF64BE>();
 
-template Symbol *SymbolTable::addRegular<ELF32LE>(StringRef, uint8_t, uint8_t,
-                                                  uint64_t, uint64_t, uint8_t,
-                                                  SectionBase *, InputFile *);
-template Symbol *SymbolTable::addRegular<ELF32BE>(StringRef, uint8_t, uint8_t,
-                                                  uint64_t, uint64_t, uint8_t,
-                                                  SectionBase *, InputFile *);
-template Symbol *SymbolTable::addRegular<ELF64LE>(StringRef, uint8_t, uint8_t,
-                                                  uint64_t, uint64_t, uint8_t,
-                                                  SectionBase *, InputFile *);
-template Symbol *SymbolTable::addRegular<ELF64BE>(StringRef, uint8_t, uint8_t,
-                                                  uint64_t, uint64_t, uint8_t,
-                                                  SectionBase *, InputFile *);
-
-template Defined *SymbolTable::addAbsolute<ELF32LE>(StringRef, uint8_t,
-                                                    uint8_t);
-template Defined *SymbolTable::addAbsolute<ELF32BE>(StringRef, uint8_t,
-                                                    uint8_t);
-template Defined *SymbolTable::addAbsolute<ELF64LE>(StringRef, uint8_t,
-                                                    uint8_t);
-template Defined *SymbolTable::addAbsolute<ELF64BE>(StringRef, uint8_t,
-                                                    uint8_t);
-
 template Symbol *
 SymbolTable::addLazyArchive<ELF32LE>(StringRef, ArchiveFile &,
                                      const object::Archive::Symbol);

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Sat Dec 23 09:21:39 2017
@@ -42,7 +42,6 @@ public:
 
   ArrayRef<Symbol *> getSymbols() const { return SymVector; }
 
-  template <class ELFT>
   Defined *addAbsolute(StringRef Name,
                        uint8_t Visibility = llvm::ELF::STV_HIDDEN,
                        uint8_t Binding = llvm::ELF::STB_GLOBAL);
@@ -51,7 +50,6 @@ public:
   template <class ELFT>
   Symbol *addUndefined(StringRef Name, uint8_t Binding, uint8_t StOther,
                        uint8_t Type, bool CanOmitFromDynSym, InputFile *File);
-  template <class ELFT>
   Symbol *addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
                      uint64_t Value, uint64_t Size, uint8_t Binding,
                      SectionBase *Section, InputFile *File);

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Dec 23 09:21:39 2017
@@ -156,35 +156,34 @@ template <class ELFT> static void combin
   V.erase(std::remove(V.begin(), V.end(), nullptr), V.end());
 }
 
-template <class ELFT>
 static Defined *addOptionalRegular(StringRef Name, SectionBase *Sec,
                                    uint64_t Val, uint8_t StOther = STV_HIDDEN,
                                    uint8_t Binding = STB_GLOBAL) {
   Symbol *S = Symtab->find(Name);
   if (!S || S->isDefined())
     return nullptr;
-  Symbol *Sym = Symtab->addRegular<ELFT>(Name, StOther, STT_NOTYPE, Val,
-                                         /*Size=*/0, Binding, Sec,
-                                         /*File=*/nullptr);
+  Symbol *Sym = Symtab->addRegular(Name, StOther, STT_NOTYPE, Val,
+                                   /*Size=*/0, Binding, Sec,
+                                   /*File=*/nullptr);
   return cast<Defined>(Sym);
 }
 
 // The linker is expected to define some symbols depending on
 // the linking result. This function defines such symbols.
-template <class ELFT> void elf::addReservedSymbols() {
+void elf::addReservedSymbols() {
   if (Config->EMachine == EM_MIPS) {
     // Define _gp for MIPS. st_value of _gp symbol will be updated by Writer
     // so that it points to an absolute address which by default is relative
     // to GOT. Default offset is 0x7ff0.
     // See "Global Data Symbols" in Chapter 6 in the following document:
     // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
-    ElfSym::MipsGp = Symtab->addAbsolute<ELFT>("_gp", STV_HIDDEN, STB_GLOBAL);
+    ElfSym::MipsGp = Symtab->addAbsolute("_gp", STV_HIDDEN, STB_GLOBAL);
 
     // On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
     // start of function and 'gp' pointer into GOT.
     if (Symtab->find("_gp_disp"))
       ElfSym::MipsGpDisp =
-          Symtab->addAbsolute<ELFT>("_gp_disp", STV_HIDDEN, STB_GLOBAL);
+          Symtab->addAbsolute("_gp_disp", STV_HIDDEN, STB_GLOBAL);
 
     // The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
     // pointer. This symbol is used in the code generated by .cpload pseudo-op
@@ -192,10 +191,10 @@ template <class ELFT> void elf::addReser
     // https://sourceware.org/ml/binutils/2004-12/msg00094.html
     if (Symtab->find("__gnu_local_gp"))
       ElfSym::MipsLocalGp =
-          Symtab->addAbsolute<ELFT>("__gnu_local_gp", STV_HIDDEN, STB_GLOBAL);
+          Symtab->addAbsolute("__gnu_local_gp", STV_HIDDEN, STB_GLOBAL);
   }
 
-  ElfSym::GlobalOffsetTable = addOptionalRegular<ELFT>(
+  ElfSym::GlobalOffsetTable = addOptionalRegular(
       "_GLOBAL_OFFSET_TABLE_", Out::ElfHeader, Target->GotBaseSymOff);
 
   // __ehdr_start is the location of ELF file headers. Note that we define
@@ -209,14 +208,14 @@ template <class ELFT> void elf::addReser
   // different in different DSOs, so we chose the start address of the DSO.
   for (const char *Name :
        {"__ehdr_start", "__executable_start", "__dso_handle"})
-    addOptionalRegular<ELFT>(Name, Out::ElfHeader, 0, STV_HIDDEN);
+    addOptionalRegular(Name, Out::ElfHeader, 0, STV_HIDDEN);
 
   // If linker script do layout we do not need to create any standart symbols.
   if (Script->HasSectionsCommand)
     return;
 
   auto Add = [](StringRef S, int64_t Pos) {
-    return addOptionalRegular<ELFT>(S, Out::ElfHeader, Pos, STV_DEFAULT);
+    return addOptionalRegular(S, Out::ElfHeader, Pos, STV_DEFAULT);
   };
 
   ElfSym::Bss = Add("__bss_start", 0);
@@ -834,10 +833,10 @@ template <class ELFT> void Writer<ELFT>:
   if (!Config->Static)
     return;
   StringRef S = Config->IsRela ? "__rela_iplt_start" : "__rel_iplt_start";
-  addOptionalRegular<ELFT>(S, InX::RelaIplt, 0, STV_HIDDEN, STB_WEAK);
+  addOptionalRegular(S, InX::RelaIplt, 0, STV_HIDDEN, STB_WEAK);
 
   S = Config->IsRela ? "__rela_iplt_end" : "__rel_iplt_end";
-  addOptionalRegular<ELFT>(S, InX::RelaIplt, -1, STV_HIDDEN, STB_WEAK);
+  addOptionalRegular(S, InX::RelaIplt, -1, STV_HIDDEN, STB_WEAK);
 }
 
 template <class ELFT>
@@ -1385,9 +1384,9 @@ template <class ELFT> void Writer<ELFT>:
   // Even the author of gold doesn't remember why gold behaves that way.
   // https://sourceware.org/ml/binutils/2002-03/msg00360.html
   if (InX::DynSymTab)
-    Symtab->addRegular<ELFT>("_DYNAMIC", STV_HIDDEN, STT_NOTYPE, 0 /*Value*/,
-                             /*Size=*/0, STB_WEAK, InX::Dynamic,
-                             /*File=*/nullptr);
+    Symtab->addRegular("_DYNAMIC", STV_HIDDEN, STT_NOTYPE, 0 /*Value*/,
+                       /*Size=*/0, STB_WEAK, InX::Dynamic,
+                       /*File=*/nullptr);
 
   // Define __rel[a]_iplt_{start,end} symbols if needed.
   addRelIpltSymbols();
@@ -1534,13 +1533,13 @@ template <class ELFT> void Writer<ELFT>:
     // These symbols resolve to the image base if the section does not exist.
     // A special value -1 indicates end of the section.
     if (OS) {
-      addOptionalRegular<ELFT>(Start, OS, 0);
-      addOptionalRegular<ELFT>(End, OS, -1);
+      addOptionalRegular(Start, OS, 0);
+      addOptionalRegular(End, OS, -1);
     } else {
       if (Config->Pic)
         OS = Out::ElfHeader;
-      addOptionalRegular<ELFT>(Start, OS, 0);
-      addOptionalRegular<ELFT>(End, OS, 0);
+      addOptionalRegular(Start, OS, 0);
+      addOptionalRegular(End, OS, 0);
     }
   };
 
@@ -1562,8 +1561,8 @@ void Writer<ELFT>::addStartStopSymbols(O
   StringRef S = Sec->Name;
   if (!isValidCIdentifier(S))
     return;
-  addOptionalRegular<ELFT>(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
-  addOptionalRegular<ELFT>(Saver.save("__stop_" + S), Sec, -1, STV_DEFAULT);
+  addOptionalRegular(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
+  addOptionalRegular(Saver.save("__stop_" + S), Sec, -1, STV_DEFAULT);
 }
 
 static bool needsPtLoad(OutputSection *Sec) {
@@ -2063,8 +2062,3 @@ template void elf::writeResult<ELF32LE>(
 template void elf::writeResult<ELF32BE>();
 template void elf::writeResult<ELF64LE>();
 template void elf::writeResult<ELF64BE>();
-
-template void elf::addReservedSymbols<ELF32LE>();
-template void elf::addReservedSymbols<ELF32BE>();
-template void elf::addReservedSymbols<ELF64LE>();
-template void elf::addReservedSymbols<ELF64BE>();

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=321404&r1=321403&r2=321404&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Sat Dec 23 09:21:39 2017
@@ -46,7 +46,7 @@ struct PhdrEntry {
   bool HasLMA = false;
 };
 
-template <class ELFT> void addReservedSymbols();
+void addReservedSymbols();
 llvm::StringRef getOutputSectionName(InputSectionBase *S);
 
 template <class ELFT> uint32_t calcMipsEFlags();




More information about the llvm-commits mailing list