[lld] r315131 - Use error() instead of warn() to report undefined symbols.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 6 16:43:54 PDT 2017
Author: ruiu
Date: Fri Oct 6 16:43:54 2017
New Revision: 315131
URL: http://llvm.org/viewvc/llvm-project?rev=315131&view=rev
Log:
Use error() instead of warn() to report undefined symbols.
I believe the reason why we used warn() instead of error() to report
undefined symbols is because the older implementation of error() exitted
immediately. Here, we want to find as many undefined symbols as we can,
so I chose to use warn() instead of error().
Now error() does not exit immediately, so it doesn't make sense to keep
them as warnings.
Differential Revision: https://reviews.llvm.org/D38652
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/test/COFF/entry-inference.test
lld/trunk/test/COFF/force.test
lld/trunk/test/COFF/nodefaultlib.test
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=315131&r1=315130&r2=315131&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Fri Oct 6 16:43:54 2017
@@ -1177,6 +1177,8 @@ void LinkerDriver::link(ArrayRef<const c
// Make sure we have resolved all symbols.
Symtab->reportRemainingUndefines();
+ if (ErrorCount)
+ return;
// Windows specific -- if no /subsystem is given, we need to infer
// that from entry point name.
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=315131&r1=315130&r2=315131&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Fri Oct 6 16:43:54 2017
@@ -84,8 +84,16 @@ void SymbolTable::addFile(InputFile *Fil
Driver->parseDirectives(S);
}
+static void errorOrWarn(const Twine &S) {
+ if (Config->Force)
+ warn(S);
+ else
+ error(S);
+}
+
void SymbolTable::reportRemainingUndefines() {
SmallPtrSet<SymbolBody *, 8> Undefs;
+
for (auto &I : Symtab) {
Symbol *Sym = I.second;
auto *Undef = dyn_cast<Undefined>(Sym->body());
@@ -93,7 +101,9 @@ void SymbolTable::reportRemainingUndefin
continue;
if (!Sym->IsUsedInRegularObj)
continue;
+
StringRef Name = Undef->getName();
+
// A weak alias may have been resolved, so check for that.
if (Defined *D = Undef->getWeakAlias()) {
// We resolve weak aliases by replacing the alias's SymbolBody with the
@@ -112,6 +122,7 @@ void SymbolTable::reportRemainingUndefin
Sym->Body = D->symbol()->Body;
continue;
}
+
// If we can resolve a symbol by removing __imp_ prefix, do that.
// This odd rule is for compatibility with MSVC linker.
if (Name.startswith("__imp_")) {
@@ -124,23 +135,25 @@ void SymbolTable::reportRemainingUndefin
continue;
}
}
+
// Remaining undefined symbols are not fatal if /force is specified.
// They are replaced with dummy defined symbols.
if (Config->Force)
replaceBody<DefinedAbsolute>(Sym, Name, 0);
Undefs.insert(Sym->body());
}
+
if (Undefs.empty())
return;
+
for (SymbolBody *B : Config->GCRoot)
if (Undefs.count(B))
- warn("<root>: undefined symbol: " + B->getName());
+ errorOrWarn("<root>: undefined symbol: " + B->getName());
+
for (ObjFile *File : ObjFile::Instances)
for (SymbolBody *Sym : File->getSymbols())
if (Undefs.count(Sym))
- warn(toString(File) + ": undefined symbol: " + Sym->getName());
- if (!Config->Force)
- fatal("link failed");
+ errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName());
}
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
Modified: lld/trunk/test/COFF/entry-inference.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/entry-inference.test?rev=315131&r1=315130&r2=315131&view=diff
==============================================================================
--- lld/trunk/test/COFF/entry-inference.test (original)
+++ lld/trunk/test/COFF/entry-inference.test Fri Oct 6 16:43:54 2017
@@ -14,10 +14,10 @@
# RUN: not lld-link /out:%t.exe %t.obj > %t.log 2>&1
# RUN: FileCheck -check-prefix=WWINMAIN %s < %t.log
-# MAIN: <root>: undefined symbol: mainCRTStartup
-# WMAIN: <root>: undefined symbol: wmainCRTStartup
-# WINMAIN: <root>: undefined symbol: WinMainCRTStartup
-# WWINMAIN: <root>: undefined symbol: wWinMainCRTStartup
+# MAIN: error: <root>: undefined symbol: mainCRTStartup
+# WMAIN: error: <root>: undefined symbol: wmainCRTStartup
+# WINMAIN: error: <root>: undefined symbol: WinMainCRTStartup
+# WWINMAIN: error: <root>: undefined symbol: wWinMainCRTStartup
--- !COFF
header:
Modified: lld/trunk/test/COFF/force.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/force.test?rev=315131&r1=315130&r2=315131&view=diff
==============================================================================
--- lld/trunk/test/COFF/force.test (original)
+++ lld/trunk/test/COFF/force.test Fri Oct 6 16:43:54 2017
@@ -1,10 +1,11 @@
# RUN: yaml2obj < %s > %t.obj
# RUN: not lld-link /out:%t.exe /entry:main %t.obj >& %t.log
-# RUN: FileCheck %s < %t.log
+# RUN: FileCheck -check-prefix=ERROR %s < %t.log
# RUN: lld-link /out:%t.exe /entry:main %t.obj /force >& %t.log
-# RUN: FileCheck %s < %t.log
+# RUN: FileCheck -check-prefix=WARN %s < %t.log
-# CHECK: .obj: undefined symbol: foo
+# ERROR: error: {{.*}}.obj: undefined symbol: foo
+# WARN: warning: {{.*}}.obj: undefined symbol: foo
--- !COFF
header:
Modified: lld/trunk/test/COFF/nodefaultlib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/nodefaultlib.test?rev=315131&r1=315130&r2=315131&view=diff
==============================================================================
--- lld/trunk/test/COFF/nodefaultlib.test (original)
+++ lld/trunk/test/COFF/nodefaultlib.test Fri Oct 6 16:43:54 2017
@@ -19,9 +19,9 @@
# RUN: /nodefaultlib:std64.lib >& %t.log || true
# RUN: FileCheck -check-prefix=CHECK3 %s < %t.log
-CHECK1: hello64.obj: {{[Nn]}}o such file or directory
-CHECK2: hello64: {{[Nn]}}o such file or directory
-CHECK3: hello64.obj: undefined symbol: MessageBoxA
+CHECK1: error: could not open hello64.obj: {{[Nn]}}o such file or directory
+CHECK2: error: could not open hello64: {{[Nn]}}o such file or directory
+CHECK3: error: {{.*}}hello64.obj: undefined symbol: MessageBoxA
# RUN: lld-link /libpath:%T /out:%t.exe /entry:main \
# RUN: /subsystem:console hello64.obj /defaultlib:std64.lib
More information about the llvm-commits
mailing list