[lld] r293139 - [ELF] Add warn-unresolved-symbols/error-unresolved-symbols options
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 18:19:20 PST 2017
Author: davide
Date: Wed Jan 25 20:19:20 2017
New Revision: 293139
URL: http://llvm.org/viewvc/llvm-project?rev=293139&view=rev
Log:
[ELF] Add warn-unresolved-symbols/error-unresolved-symbols options
Patch by Dmitry Mikulin.
PR: 31735
Differential Revision: https://reviews.llvm.org/D29150
Added:
lld/trunk/test/ELF/warn-unresolved-symbols.s
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Options.td
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=293139&r1=293138&r2=293139&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jan 25 20:19:20 2017
@@ -357,6 +357,13 @@ static UnresolvedPolicy getUnresolvedSym
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;
+
+ return UnresolvedPolicy::ReportError;
+ }
+
if (auto *Arg = Args.getLastArg(OPT_unresolved_symbols)) {
StringRef S = Arg->getValue();
if (S == "ignore-all" || S == "ignore-in-object-files")
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=293139&r1=293138&r2=293139&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Wed Jan 25 20:19:20 2017
@@ -82,6 +82,9 @@ def entry: S<"entry">, MetaVarName<"<ent
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">;
@@ -254,6 +257,9 @@ def version_script: S<"version-script">,
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">;
Added: lld/trunk/test/ELF/warn-unresolved-symbols.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/warn-unresolved-symbols.s?rev=293139&view=auto
==============================================================================
--- lld/trunk/test/ELF/warn-unresolved-symbols.s (added)
+++ lld/trunk/test/ELF/warn-unresolved-symbols.s Wed Jan 25 20:19:20 2017
@@ -0,0 +1,44 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
+
+## The link should fail with an undef error by default
+# RUN: not ld.lld %t1.o -o %t3 2>&1 | \
+# RUN: FileCheck -check-prefix=ERRUND %s
+
+## --error-unresolved-symbols should generate an error
+# RUN: not ld.lld %t1.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 -o %t5 --warn-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -check-prefix=WARNUND %s
+
+## Test that the last option wins
+# RUN: ld.lld %t1.o -o %t5 --error-unresolved-symbols --warn-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -check-prefix=WARNUND %s
+# RUN: not ld.lld %t1.o -o %t6 --warn-unresolved-symbols --error-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -check-prefix=ERRUND %s
+
+## Do not report undefines if linking relocatable or shared.
+## And while we're at it, check that we can accept single -
+## variants of these options.
+# RUN: ld.lld -r %t1.o -o %t7 -error-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -allow-empty -check-prefix=NOERR %s
+# RUN: ld.lld -shared %t1.o -o %t8.so --error-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -allow-empty -check-prefix=NOERR %s
+# RUN: ld.lld -r %t1.o -o %t9 -warn-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -allow-empty -check-prefix=NOWARN %s
+# RUN: ld.lld -shared %t1.o -o %t10.so --warn-unresolved-symbols 2>&1 | \
+# RUN: FileCheck -allow-empty -check-prefix=NOWARN %s
+
+# ERRUND: error: {{.*}}:(.text+0x1): undefined symbol 'undef'
+# WARNUND: warning: {{.*}}:(.text+0x1): undefined symbol 'undef'
+# NOERR-NOT: error: {{.*}}:(.text+0x1): undefined symbol 'undef'
+# NOWARN-NOT: warning: {{.*}}:(.text+0x1): undefined symbol 'undef'
+
+.globl _start
+_start:
+
+.globl _shared
+_shared:
+ callq undef at PLT
More information about the llvm-commits
mailing list