Index: ELF/Relocations.h =================================================================== --- ELF/Relocations.h +++ ELF/Relocations.h @@ -88,7 +88,7 @@ void createThunks(InputSectionBase &, const typename ELFT::Shdr &); template -std::string getLocation(SymbolBody *Sym, InputSectionBase &S, +std::string getLocation(InputSectionBase &S, typename ELFT::uint Offset); template Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -539,8 +539,7 @@ } template -std::string getLocation(SymbolBody *Sym, InputSectionBase &S, - typename ELFT::uint Offset) { +std::string getLocation(InputSectionBase &S, typename ELFT::uint Offset) { ObjectFile *File = S.getFile(); // First check if we can get desired values from debugging information. @@ -548,11 +547,12 @@ 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 *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(InputSectionBase &, const ELF64BE::Shdr &); -template std::string getLocation(SymbolBody *Sym, - InputSectionBase &S, +template std::string getLocation(InputSectionBase &S, uint32_t Offset); -template std::string getLocation(SymbolBody *Sym, - InputSectionBase &S, +template std::string getLocation(InputSectionBase &S, uint32_t Offset); -template std::string getLocation(SymbolBody *Sym, - InputSectionBase &S, +template std::string getLocation(InputSectionBase &S, uint64_t Offset); -template std::string getLocation(SymbolBody *Sym, - InputSectionBase &S, +template std::string getLocation(InputSectionBase &S, uint64_t Offset); } } 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()) + "'");