[lld] 5f404a7 - [ELF] De-template InputSectionBase::getLocation. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 18 17:34:03 PST 2022


Author: Fangrui Song
Date: 2022-01-18T17:33:58-08:00
New Revision: 5f404a749a84b301d96585859cba8d3071031f62

URL: https://github.com/llvm/llvm-project/commit/5f404a749a84b301d96585859cba8d3071031f62
DIFF: https://github.com/llvm/llvm-project/commit/5f404a749a84b301d96585859cba8d3071031f62.diff

LOG: [ELF] De-template InputSectionBase::getLocation. NFC

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/ELF/InputSection.h
    lld/ELF/Target.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 006c7308c582..fc8b3b19f104 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -278,20 +278,19 @@ Defined *InputSectionBase::getEnclosingFunction(uint64_t offset) {
 }
 
 // Returns an object file location string. Used to construct an error message.
-template <class ELFT>
 std::string InputSectionBase::getLocation(uint64_t offset) {
   std::string secAndOffset =
       (name + "+0x" + Twine::utohexstr(offset) + ")").str();
 
   // We don't have file for synthetic sections.
-  if (getFile<ELFT>() == nullptr)
+  if (file == nullptr)
     return (config->outputFile + ":(" + secAndOffset).str();
 
-  std::string file = toString(getFile<ELFT>());
+  std::string filename = toString(file);
   if (Defined *d = getEnclosingFunction(offset))
-    return file + ":(function " + toString(*d) + ": " + secAndOffset;
+    return filename + ":(function " + toString(*d) + ": " + secAndOffset;
 
-  return file + ":(" + secAndOffset;
+  return filename + ":(" + secAndOffset;
 }
 
 // This function is intended to be used for constructing an error message.
@@ -948,7 +947,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
       continue;
     }
 
-    std::string msg = getLocation<ELFT>(offset) + ": has non-ABS relocation " +
+    std::string msg = getLocation(offset) + ": has non-ABS relocation " +
                       toString(type) + " against symbol '" + toString(sym) +
                       "'";
     if (expr != R_PC && expr != R_ARM_PCA) {
@@ -1473,11 +1472,6 @@ template InputSection::InputSection(ObjFile<ELF64LE> &, const ELF64LE::Shdr &,
 template InputSection::InputSection(ObjFile<ELF64BE> &, const ELF64BE::Shdr &,
                                     StringRef);
 
-template std::string InputSectionBase::getLocation<ELF32LE>(uint64_t);
-template std::string InputSectionBase::getLocation<ELF32BE>(uint64_t);
-template std::string InputSectionBase::getLocation<ELF64LE>(uint64_t);
-template std::string InputSectionBase::getLocation<ELF64BE>(uint64_t);
-
 template void InputSection::writeTo<ELF32LE>(uint8_t *);
 template void InputSection::writeTo<ELF32BE>(uint8_t *);
 template void InputSection::writeTo<ELF64LE>(uint8_t *);

diff  --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 87b748fdf99e..d7dea9d2587a 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -184,7 +184,7 @@ class InputSectionBase : public SectionBase {
   Defined *getEnclosingFunction(uint64_t offset);
 
   // Returns a source location string. Used to construct an error message.
-  template <class ELFT> std::string getLocation(uint64_t offset);
+  std::string getLocation(uint64_t offset);
   std::string getSrcMsg(const Symbol &sym, uint64_t offset);
   std::string getObjMsg(uint64_t offset);
 

diff  --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 88d3006f9a2d..f0e7ebfc64df 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -107,7 +107,7 @@ template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) {
       continue;
     }
     if (isecLoc <= loc && loc < isecLoc + isec->getSize()) {
-      auto objLoc = isec->template getLocation<ELFT>(loc - isecLoc);
+      std::string objLoc = isec->getLocation(loc - isecLoc);
       // Return object file location and source file location.
       // TODO: Refactor getSrcMsg not to take a variable.
       Undefined dummy(nullptr, "", STB_LOCAL, 0, 0);


        


More information about the llvm-commits mailing list