[PATCH] D26411: Simplify getLocation() function.

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


ruiu created this revision.
ruiu added a reviewer: evgeny777.
ruiu added a subscriber: llvm-commits.

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


https://reviews.llvm.org/D26411

Files:
  ELF/Relocations.cpp
  ELF/Relocations.h
  ELF/SymbolTable.cpp


Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -386,8 +386,8 @@
     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()) +
         "'");
Index: ELF/Relocations.h
===================================================================
--- ELF/Relocations.h
+++ ELF/Relocations.h
@@ -88,7 +88,7 @@
 void createThunks(InputSectionBase<ELFT> &, const typename ELFT::Shdr &);
 
 template <class ELFT>
-std::string getLocation(SymbolBody *Sym, InputSectionBase<ELFT> &S,
+std::string getLocation(InputSectionBase<ELFT> &S,
                         typename ELFT::uint Offset);
 
 template <class ELFT>
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -539,20 +539,20 @@
 }
 
 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.
   std::string LineInfo = File->getLineInfo(&S, Offset);
   if (!LineInfo.empty())
     return LineInfo;
 
-  // If don't have STT_FILE typed symbol in object file then
-  // use object file name.
+  // File->SourceFile contains a STT_FILE symbol contents
+  // which is a filename. Compilers usually create STT_FILE symbols.
+  // If it's missing, we use 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 @@
       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<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);
 }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26411.77235.patch
Type: text/x-patch
Size: 3747 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161108/4a36c961/attachment.bin>


More information about the llvm-commits mailing list