[lld] r286287 - Simplify getLocation() function.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 12:30:19 PST 2016


Author: ruiu
Date: Tue Nov  8 14:30:19 2016
New Revision: 286287

URL: http://llvm.org/viewvc/llvm-project?rev=286287&view=rev
Log:
Simplify getLocation() function.

All tests pass without the first parameter, so I guess we don't need it.

Differential Revision: https://reviews.llvm.org/D26411

Modified:
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Relocations.h
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=286287&r1=286286&r2=286287&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Nov  8 14:30:19 2016
@@ -539,8 +539,7 @@ static DefinedRegular<ELFT> *getSymbolAt
 }
 
 template <class ELFT>
-std::string getLocation(SymbolBody *Sym, InputSectionBase<ELFT> &S,
-                        typename ELFT::uint Offset) {
+std::string getLocation(InputSectionBase<ELFT> &S, typename ELFT::uint Offset) {
   ObjectFile<ELFT> *File = S.getFile();
 
   // First check if we can get desired values from debugging information.
@@ -548,11 +547,12 @@ std::string getLocation(SymbolBody *Sym,
   if (!LineInfo.empty())
     return LineInfo;
 
-  // If don't have STT_FILE typed symbol in object file then
-  // use object file name.
+  // File->SourceFile contains STT_FILE symbol contents which is a
+  // filename. Compilers usually create STT_FILE symbols. If it's
+  // missing, we use an actual filename.
   std::string SrcFile = File->SourceFile;
   if (SrcFile.empty())
-    SrcFile = Sym && Sym->File ? getFilename(Sym->File) : getFilename(File);
+    SrcFile = getFilename(File);
 
   // Find a symbol at a given location.
   DefinedRegular<ELFT> *Encl = getSymbolAt(&S, Offset);
@@ -576,7 +576,7 @@ static void reportUndefined(SymbolBody &
       Config->UnresolvedSymbols != UnresolvedPolicy::NoUndef)
     return;
 
-  std::string Msg = getLocation(&Sym, S, Offset) + ": undefined symbol '" +
+  std::string Msg = getLocation(S, Offset) + ": undefined symbol '" +
                     maybeDemangle(Sym.getName()) + "'";
 
   if (Config->UnresolvedSymbols == UnresolvedPolicy::Warn)
@@ -854,17 +854,13 @@ template void createThunks<ELF64LE>(Inpu
 template void createThunks<ELF64BE>(InputSectionBase<ELF64BE> &,
                                     const ELF64BE::Shdr &);
 
-template std::string getLocation<ELF32LE>(SymbolBody *Sym,
-                                          InputSectionBase<ELF32LE> &S,
+template std::string getLocation<ELF32LE>(InputSectionBase<ELF32LE> &S,
                                           uint32_t Offset);
-template std::string getLocation<ELF32BE>(SymbolBody *Sym,
-                                          InputSectionBase<ELF32BE> &S,
+template std::string getLocation<ELF32BE>(InputSectionBase<ELF32BE> &S,
                                           uint32_t Offset);
-template std::string getLocation<ELF64LE>(SymbolBody *Sym,
-                                          InputSectionBase<ELF64LE> &S,
+template std::string getLocation<ELF64LE>(InputSectionBase<ELF64LE> &S,
                                           uint64_t Offset);
-template std::string getLocation<ELF64BE>(SymbolBody *Sym,
-                                          InputSectionBase<ELF64BE> &S,
+template std::string getLocation<ELF64BE>(InputSectionBase<ELF64BE> &S,
                                           uint64_t Offset);
 }
 }

Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=286287&r1=286286&r2=286287&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Tue Nov  8 14:30:19 2016
@@ -88,8 +88,7 @@ template <class ELFT>
 void createThunks(InputSectionBase<ELFT> &, const typename ELFT::Shdr &);
 
 template <class ELFT>
-std::string getLocation(SymbolBody *Sym, InputSectionBase<ELFT> &S,
-                        typename ELFT::uint Offset);
+std::string getLocation(InputSectionBase<ELFT> &S, typename ELFT::uint Offset);
 
 template <class ELFT>
 static inline typename ELFT::uint getAddend(const typename ELFT::Rel &Rel) {

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=286287&r1=286286&r2=286287&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Nov  8 14:30:19 2016
@@ -386,8 +386,8 @@ static void reportDuplicate(SymbolBody *
     return;
   }
 
-  std::string OldLoc = getLocation(Existing, *D->Section, D->Value);
-  std::string NewLoc = getLocation(nullptr, *ErrSec, ErrOffset);
+  std::string OldLoc = getLocation(*D->Section, D->Value);
+  std::string NewLoc = getLocation(*ErrSec, ErrOffset);
 
   print(NewLoc + ": duplicate symbol '" + maybeDemangle(Existing->getName()) +
         "'");




More information about the llvm-commits mailing list