From 759bae956abf7fb46c28f5e23a4feee593c883ae Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 12 May 2020 14:02:13 -0400 Subject: [PATCH] [lld-macho] Ignore -platform_version and -syslibroot flags. clang passes these flags; this makes it easier to try `clang -v` output with `ld -flavor darwinnew`. Differential Revision: https://reviews.llvm.org/D79797 --- lld/MachO/Driver.cpp | 20 +++++++++++++++++++- lld/MachO/Options.td | 2 ++ lld/test/MachO/platform-version.test | 16 ++++++++++++++++ lld/test/MachO/silent-ignore.test | 3 ++- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lld/test/MachO/platform-version.test diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index 858969b..311e155 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -131,6 +131,18 @@ static bool markSubLibrary(StringRef searchName) { return false; } +static void handlePlatformVersion(opt::ArgList::iterator &it, + const opt::ArgList::iterator &end) { + // -platform_version takes 3 args, which LLVM's option library doesn't + // support directly. So this explicitly handles that. + // FIXME: stash skipped args for later use. + for (int i = 0; i < 3; ++i) { + ++it; + if (it == end || (*it)->getOption().getID() != OPT_INPUT) + fatal("usage: -platform_version platform min_version sdk_version"); + } +} + bool macho::link(llvm::ArrayRef argsArr, bool canExitEarly, raw_ostream &stdoutOS, raw_ostream &stderrOS) { lld::stdoutOS = &stdoutOS; @@ -162,7 +174,9 @@ bool macho::link(llvm::ArrayRef argsArr, bool canExitEarly, return !errorCount(); } - for (opt::Arg *arg : args) { + for (opt::ArgList::iterator it = args.begin(), end = args.end(); it != end; + ++it) { + const opt::Arg *arg = *it; switch (arg->getOption().getID()) { case OPT_INPUT: addFile(arg->getValue()); @@ -171,6 +185,10 @@ bool macho::link(llvm::ArrayRef argsArr, bool canExitEarly, if (Optional path = findDylib(arg->getValue())) addFile(*path); break; + case OPT_platform_version: { + handlePlatformVersion(it, end); // Can advance "it". + break; + } } } diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td index 3068dc3..fd0971f 100644 --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -32,5 +32,7 @@ def v: Flag<["-"], "v">, HelpText<"Display the version number and exit">; def: Flag<["-"], "demangle">; def: Flag<["-"], "dynamic">; def: Flag<["-"], "no_deduplicate">; +def platform_version: Flag<["-"], "platform_version">; def: Separate<["-"], "lto_library">; def: Separate<["-"], "macosx_version_min">; +def: Separate<["-"], "syslibroot">; diff --git a/lld/test/MachO/platform-version.test b/lld/test/MachO/platform-version.test new file mode 100644 index 0000000..4c486c6 --- /dev/null +++ b/lld/test/MachO/platform-version.test @@ -0,0 +1,16 @@ +# RUN: not lld -flavor darwinnew -platform_version 2>&1 \ +# RUN: | FileCheck --check-prefix=FAIL %s +# RUN: not lld -flavor darwinnew -platform_version macos 2>&1 \ +# RUN: | FileCheck --check-prefix=FAIL %s +# RUN: not lld -flavor darwinnew -platform_version macos 10.15 2>&1 \ +# RUN: | FileCheck --check-prefix=FAIL %s +# RUN: not lld -flavor darwinnew -platform_version macos -lfoo 10.15 2>&1 \ +# RUN: | FileCheck --check-prefix=FAIL %s +# RUN: not lld -flavor darwinnew -platform_version macos 10.15 10.15.4 2>&1 \ +# RUN: | FileCheck --check-prefix=GOOD %s +# RUN: not lld -flavor darwinnew -platform_version macos 10.15 10.15.4 foobar 2>&1 \ +# RUN: | FileCheck --check-prefix=FAIL_FILE %s + +FAIL: usage: -platform_version platform min_version sdk_version +GOOD: undefined symbol: _main +FAIL_FILE: cannot open foobar diff --git a/lld/test/MachO/silent-ignore.test b/lld/test/MachO/silent-ignore.test index de95cff..ae68dd8 100644 --- a/lld/test/MachO/silent-ignore.test +++ b/lld/test/MachO/silent-ignore.test @@ -3,6 +3,7 @@ RUN: -demangle \ RUN: -dynamic \ RUN: -no_deduplicate \ RUN: -lto_library /lib/foo \ -RUN: -macosx_version_min 0 +RUN: -macosx_version_min 0 \ +RUN: -syslibroot /path/to/MacOSX.platform/Developer/SDKs/MacOSX.sdk RUN: not lld -flavor darwinnew -v --not-an-ignored-argument 2>&1 | FileCheck %s CHECK: error: unknown argument: --not-an-ignored-argument -- 2.7.4