[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

llvm-svn: 362882
This commit is contained in:
Martin Storsjo 2019-06-08 18:26:24 +00:00
parent c02f6bf07f
commit 4962f9464d
3 changed files with 9 additions and 0 deletions

View File

@ -269,6 +269,8 @@ bool mingw::link(ArrayRef<const char *> ArgsArr, raw_ostream &Diag) {
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)) {

View File

@ -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">;

View File

@ -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