diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index ca817a36dbc2..47e4b33c22ae 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -27,6 +27,15 @@ using namespace llvm::sys::fs; using namespace lld; using namespace lld::elf; +// Returns "(internal)", "foo.a(bar.o)" or "baz.o". +std::string elf::getFilename(InputFile *F) { + if (!F) + return "(internal)"; + if (!F->ArchiveName.empty()) + return (F->ArchiveName + "(" + F->getName() + ")").str(); + return F->getName(); +} + template static ELFFile createELFObj(MemoryBufferRef MB) { std::error_code EC; diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index 15a3a8bec574..8245a1bab0cb 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -63,6 +63,9 @@ private: const Kind FileKind; }; +// Returns "(internal)", "foo.a(bar.o)" or "baz.o". +std::string getFilename(InputFile *F); + template class ELFFileBase : public InputFile { public: typedef typename ELFT::Shdr Elf_Shdr; diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 852be823acbc..4117487b58d3 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -45,15 +45,6 @@ template static bool isCompatible(InputFile *FileP) { return false; } -// Returns "(internal)", "foo.a(bar.o)" or "baz.o". -static std::string getFilename(InputFile *F) { - if (!F) - return "(internal)"; - if (!F->ArchiveName.empty()) - return (F->ArchiveName + "(" + F->getName() + ")").str(); - return F->getName(); -} - // Add symbols in File to the symbol table. template void SymbolTable::addFile(std::unique_ptr File) { diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 2ba08f7995f7..c568d7144e7a 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -799,7 +799,7 @@ static void reportUndefined(SymbolTable &Symtab, SymbolBody *Sym) { std::string Msg = "undefined symbol: " + Sym->getName().str(); if (InputFile *File = Sym->getSourceFile()) - Msg += " in " + File->getName().str(); + Msg += " in " + getFilename(File); if (Config->NoinhibitExec) warning(Msg); else diff --git a/lld/test/ELF/Inputs/undef.s b/lld/test/ELF/Inputs/undef.s new file mode 100644 index 000000000000..01776bf3505e --- /dev/null +++ b/lld/test/ELF/Inputs/undef.s @@ -0,0 +1,3 @@ + .global zed1 +zed1: + .quad zed2 diff --git a/lld/test/ELF/undef.s b/lld/test/ELF/undef.s index e0705a590c35..c8211c73866f 100644 --- a/lld/test/ELF/undef.s +++ b/lld/test/ELF/undef.s @@ -1,11 +1,15 @@ -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t -# RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s -# RUN: not ld.lld -pie %t -o %t2 2>&1 | FileCheck %s +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/undef.s -o %t2.o +# RUN: llvm-ar rc %t2.a %t2.o +# RUN: not ld.lld %t.o %t2.a -o %t.exe 2>&1 | FileCheck %s +# RUN: not ld.lld -pie %t.o %t2.a -o %t.exe 2>&1 | FileCheck %s # CHECK: undefined symbol: bar in {{.*}} # CHECK: undefined symbol: foo in {{.*}} -# REQUIRES: x86 +# CHECK: undefined symbol: zed2 in {{.*}}2.a({{.*}}.o) .globl _start _start: call foo call bar + call zed1