[PATCH] D29150: Add --warn-unresolved-symbols and --error-unresolved-symbols options
Dmitry Mikulin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 14:36:18 PST 2017
dmikulin created this revision.
dmikulin added a project: lld.
Added the following options for compatibility with binutils ld:
--warn-unresolved-symbols Report unresolved symbols as warnings
--error-unresolved-symbols Report unresolved symbols as errors
Repository:
rL LLVM
https://reviews.llvm.org/D29150
Files:
ELF/Driver.cpp
ELF/Options.td
test/ELF/warn-unresolved-symbols.s
Index: test/ELF/warn-unresolved-symbols.s
===================================================================
--- /dev/null
+++ test/ELF/warn-unresolved-symbols.s
@@ -0,0 +1,27 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/unresolved-symbols.s -o %t2.o
+
+## The link should fail with an undef error by default
+# RUN: not ld.lld %t1.o %t2.o -o %t3 2>&1 | \
+# RUN: FileCheck -check-prefix=ERRUND %s
+
+## --error-unresolved-symbols should generate an error
+# RUN: not ld.lld %t1.o %t2.o -o %t4 --error-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -check-prefix=ERRUND %s
+
+## --warn-unresolved-symbols should generate a warning
+# RUN: ld.lld %t1.o %t2.o -o %t5 --warn-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -check-prefix=WARNUND %s
+
+## Test that the last option wins
+# RUN: ld.lld %t1.o %t2.o -o %t5 --error-unresolved-symbols --warn-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -check-prefix=WARNUND %s
+# RUN: not ld.lld %t1.o %t2.o -o %t4 --warn-unresolved-symbols --error-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -check-prefix=ERRUND %s
+
+# ERRUND: error: {{.*}}:(.text+0x1): undefined symbol 'undef'
+# WARNUND: warning: {{.*}}:(.text+0x1): undefined symbol 'undef'
+
+.globl _start
+_start:
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ ELF/Options.td
@@ -79,6 +79,9 @@
def error_limit: S<"error-limit">,
HelpText<"Maximum number of errors to emit before stopping (0 = no limit)">;
+def error_undef: F<"error-unresolved-symbols">,
+ HelpText<"Report unresolved symbols as errors">;
+
def export_dynamic: F<"export-dynamic">,
HelpText<"Put symbols in the dynamic symbol table">;
@@ -248,6 +251,9 @@
def warn_common: F<"warn-common">,
HelpText<"Warn about duplicate common symbols">;
+def warn_undef: F<"warn-unresolved-symbols">,
+ HelpText<"Report unresolved symbols as warnings">;
+
def whole_archive: F<"whole-archive">,
HelpText<"Force load of all members in a static library">;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -341,6 +341,13 @@
if (Config->Relocatable)
return UnresolvedPolicy::Ignore;
+ if (auto *Arg = Args.getLastArg(OPT_warn_undef, OPT_error_undef)) {
+ if (Arg->getOption().getID() == OPT_warn_undef)
+ return UnresolvedPolicy::Warn;
+ if (Arg->getOption().getID() == OPT_error_undef)
+ return UnresolvedPolicy::ReportError;
+ }
+
if (auto *Arg = Args.getLastArg(OPT_unresolved_symbols)) {
StringRef S = Arg->getValue();
if (S == "ignore-all" || S == "ignore-in-object-files")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29150.85809.patch
Type: text/x-patch
Size: 2753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170125/fb587b18/attachment.bin>
More information about the llvm-commits
mailing list