From f5339ec035c9472f41b279021f9614b96f75a1c2 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 7 Jul 2015 18:38:39 +0000 Subject: [PATCH] COFF: Improve undefined symbol diagnostics. We now report the names of any files containing undefined symbol references. Differential Revision: http://reviews.llvm.org/D10982 llvm-svn: 241612 --- lld/COFF/SymbolTable.cpp | 25 ++++++++++++++++--------- lld/test/COFF/entry-inference.test | 8 ++++---- lld/test/COFF/force.test | 2 +- lld/test/COFF/nodefaultlib.test | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 7f7187a37990..faa9aa7a7417 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -123,7 +123,7 @@ bool SymbolTable::queueEmpty() { } bool SymbolTable::reportRemainingUndefines(bool Resolve) { - bool Ret = false; + llvm::SmallPtrSet Undefs; for (auto &I : Symtab) { Symbol *Sym = I.second; auto *Undef = dyn_cast(Sym->Body); @@ -150,17 +150,24 @@ bool SymbolTable::reportRemainingUndefines(bool Resolve) { continue; } } - llvm::errs() << "undefined symbol: " << Name << "\n"; // Remaining undefined symbols are not fatal if /force is specified. // They are replaced with dummy defined symbols. - if (Config->Force) { - if (Resolve) - Sym->Body = new (Alloc) DefinedAbsolute(Name, 0); - continue; - } - Ret = true; + if (Config->Force && Resolve) + Sym->Body = new (Alloc) DefinedAbsolute(Name, 0); + Undefs.insert(Sym->Body); } - return Ret; + if (Undefs.empty()) + return false; + for (Undefined *U : Config->GCRoot) + if (Undefs.count(U->repl())) + llvm::errs() << ": undefined symbol: " << U->getName() << "\n"; + for (std::unique_ptr &File : Files) + if (!isa(File.get())) + for (SymbolBody *Sym : File->getSymbols()) + if (Undefs.count(Sym->repl())) + llvm::errs() << File->getShortName() << ": undefined symbol: " + << Sym->getName() << "\n"; + return !Config->Force; } void SymbolTable::addLazy(Lazy *New, std::vector *Accum) { diff --git a/lld/test/COFF/entry-inference.test b/lld/test/COFF/entry-inference.test index d23cd79169e5..2e18f92073db 100644 --- a/lld/test/COFF/entry-inference.test +++ b/lld/test/COFF/entry-inference.test @@ -14,10 +14,10 @@ # RUN: not lld -flavor link2 /out:%t.exe %t.obj > %t.log 2>&1 # RUN: FileCheck -check-prefix=WWINMAIN %s < %t.log -# MAIN: undefined symbol: mainCRTStartup -# WMAIN: undefined symbol: wmainCRTStartup -# WINMAIN: undefined symbol: WinMainCRTStartup -# WWINMAIN: undefined symbol: wWinMainCRTStartup +# MAIN: : undefined symbol: mainCRTStartup +# WMAIN: : undefined symbol: wmainCRTStartup +# WINMAIN: : undefined symbol: WinMainCRTStartup +# WWINMAIN: : undefined symbol: wWinMainCRTStartup --- header: diff --git a/lld/test/COFF/force.test b/lld/test/COFF/force.test index 4a6563071da6..52f8a0534c6d 100644 --- a/lld/test/COFF/force.test +++ b/lld/test/COFF/force.test @@ -4,7 +4,7 @@ # RUN: lld -flavor link2 /out:%t.exe /entry:main %t.obj /force >& %t.log # RUN: FileCheck %s < %t.log -# CHECK: undefined symbol: foo +# CHECK: .obj: undefined symbol: foo --- header: diff --git a/lld/test/COFF/nodefaultlib.test b/lld/test/COFF/nodefaultlib.test index 1589b5d0c251..dc5253fa2ed6 100644 --- a/lld/test/COFF/nodefaultlib.test +++ b/lld/test/COFF/nodefaultlib.test @@ -21,7 +21,7 @@ CHECK1: hello64.obj: {{[Nn]}}o such file or directory CHECK2: hello64: {{[Nn]}}o such file or directory -CHECK3: undefined symbol: MessageBoxA +CHECK3: hello64.obj: undefined symbol: MessageBoxA # RUN: lld -flavor link2 /libpath:%T /out:%t.exe /entry:main \ # RUN: /subsystem:console hello64.obj /defaultlib:std64.lib