[lld] r362882 - [MinGW] Support the -u/--undefined option.

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 8 11:26:24 PDT 2019


Author: mstorsjo
Date: Sat Jun  8 11:26:24 2019
New Revision: 362882

URL: http://llvm.org/viewvc/llvm-project?rev=362882&view=rev
Log:
[MinGW] Support the -u/--undefined option.

This is implemented by the lld-link option -include:, just like
--require-defined. Contrary to --require-defined, the -u/--undefined
option allows the symbol to remain undefined in the end.

This should fix PR42121.

Differential Revision: https://reviews.llvm.org/D62876

Modified:
    lld/trunk/MinGW/Driver.cpp
    lld/trunk/MinGW/Options.td
    lld/trunk/test/MinGW/driver.test

Modified: lld/trunk/MinGW/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Driver.cpp?rev=362882&r1=362881&r2=362882&view=diff
==============================================================================
--- lld/trunk/MinGW/Driver.cpp (original)
+++ lld/trunk/MinGW/Driver.cpp Sat Jun  8 11:26:24 2019
@@ -269,6 +269,8 @@ bool mingw::link(ArrayRef<const char *>
 
   for (auto *A : Args.filtered(OPT_require_defined))
     Add("-include:" + StringRef(A->getValue()));
+  for (auto *A : Args.filtered(OPT_undefined))
+    Add("-includeoptional:" + StringRef(A->getValue()));
 
   std::vector<StringRef> SearchPaths;
   for (auto *A : Args.filtered(OPT_L)) {

Modified: lld/trunk/MinGW/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Options.td?rev=362882&r1=362881&r2=362882&view=diff
==============================================================================
--- lld/trunk/MinGW/Options.td (original)
+++ lld/trunk/MinGW/Options.td Sat Jun  8 11:26:24 2019
@@ -46,6 +46,10 @@ def strip_all: F<"strip-all">,
     HelpText<"Omit all symbol information from the output binary">;
 def strip_debug: F<"strip-debug">,
     HelpText<"Omit all debug information, but keep symbol information">;
+def undefined: S<"u">,
+    HelpText<"Include symbol in the link, if available">;
+def undefined_long: S<"undefined">, Alias<undefined>;
+def undefined_eq: J<"undefined=">, Alias<undefined>;
 def whole_archive: F<"whole-archive">,
     HelpText<"Include all object files for following archives">;
 def v: Flag<["-"], "v">, HelpText<"Display the version number">;

Modified: lld/trunk/test/MinGW/driver.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/MinGW/driver.test?rev=362882&r1=362881&r2=362882&view=diff
==============================================================================
--- lld/trunk/test/MinGW/driver.test (original)
+++ lld/trunk/test/MinGW/driver.test Sat Jun  8 11:26:24 2019
@@ -157,6 +157,9 @@ MAP: -lldmap:bar.map
 RUN: ld.lld -### foo.o -m i386pe -require-defined _foo --require-defined _bar -require-defined=_baz --require-defined=_foo2 | FileCheck -check-prefix=REQUIRE-DEFINED %s
 REQUIRE-DEFINED: -include:_foo -include:_bar -include:_baz -include:_foo2
 
+RUN: ld.lld -### foo.o -m i386pe -u _foo --undefined _bar -undefined=_baz --undefined=_foo2 | FileCheck -check-prefix=UNDEFINED %s
+UNDEFINED: -includeoptional:_foo -includeoptional:_bar -includeoptional:_baz -includeoptional:_foo2
+
 RUN: ld.lld -### -m i386pep foo.o -Llibpath | FileCheck -check-prefix LIBPATH %s
 LIBPATH: -libpath:libpath
 




More information about the llvm-commits mailing list