diff --git a/lld/docs/Driver.rst b/lld/docs/Driver.rst --- a/lld/docs/Driver.rst +++ b/lld/docs/Driver.rst @@ -40,7 +40,7 @@ There are two different ways to tell lld which flavor to be. They are checked in order, so the second overrides the first. The first is to symlink :program:`lld` as :program:`lld-{flavor}` or just :program:`{flavor}`. You can also specify -it as the first command line argument using ``-flavor``:: +it as a command line argument using ``-flavor {flavor}``:: $ lld -flavor gnu diff --git a/lld/test/Driver/flavor.test b/lld/test/Driver/flavor.test new file mode 100644 --- /dev/null +++ b/lld/test/Driver/flavor.test @@ -0,0 +1,44 @@ +# RUN: not lld -v -flavor 2>&1 \ +# RUN: | FileCheck --check-prefix=MISSING_ARG %s +# RUN: not lld -flavor 2>&1 \ +# RUN: | FileCheck --check-prefix=MISSING_ARG %s +# RUN: not lld -flavor mystery 2>&1 \ +# RUN: | FileCheck --check-prefix=MYSTERY %s + +# RUN: lld -v -flavor gnu \ +# RUN: | FileCheck --check-prefix=GNU_V %s +# RUN: lld -flavor gnu -v \ +# RUN: | FileCheck --check-prefix=GNU_V %s +# RUN: not lld -flavor gnu 2>&1 \ +# RUN: | FileCheck --check-prefix=NO_INPUT_FILES %s +# RUN: not lld -flavor ld 2>&1 \ +# RUN: | FileCheck --check-prefix=NO_INPUT_FILES %s + +# RUN: not lld -flavor wasm 2>&1 \ +# RUN: | FileCheck --check-prefix=NO_INPUT_FILES %s +# RUN: not lld -flavor ld-wasm 2>&1 \ +# RUN: | FileCheck --check-prefix=NO_INPUT_FILES %s + +# RUN: not lld -flavor link 2>&1 \ +# RUN: | FileCheck --check-prefix=NO_INPUT_FILES %s + +# RUN: not lld -v -flavor darwin 2>&1 \ +# RUN: | FileCheck --check-prefix=ARCH_NOT_SPECD %s +# RUN: not lld -v -flavor ld64 2>&1 \ +# RUN: | FileCheck --check-prefix=ARCH_NOT_SPECD %s + +# RUN: not lld -flavor darwinnew 2>&1 \ +# RUN: | FileCheck --check-prefix=UNDEF_SYM_MAIN %s + +MISSING_ARG: missing arg value for '-flavor' +MYSTERY: Unknown flavor: mystery +NO_INPUT_FILES: lld: error: no input files +UNDEF_SYM_MAIN: lld: error: undefined symbol: _main +ARCH_NOT_SPECD: lld: error: -arch not specified and could not be inferred + +GNU_V: LLD {{[0-9.]+}} (https://github.com/{{.*}}) (compatible with GNU linkers) + +DARWINNEW: LLD {{[0-9.]+}} (https://github.com/{{.*}}) +DARWINNEW: Library search paths: +DARWINNEW: /usr/lib +DARWINNEW: /usr/local/lib diff --git a/lld/tools/lld/lld.cpp b/lld/tools/lld/lld.cpp --- a/lld/tools/lld/lld.cpp +++ b/lld/tools/lld/lld.cpp @@ -111,14 +111,16 @@ static Flavor parseFlavor(std::vector &v) { // Parse -flavor option. - if (v.size() > 1 && v[1] == StringRef("-flavor")) { - if (v.size() <= 2) - die("missing arg value for '-flavor'"); - Flavor f = getFlavor(v[2]); - if (f == Invalid) - die("Unknown flavor: " + StringRef(v[2])); - v.erase(v.begin() + 1, v.begin() + 3); - return f; + for (size_t i = 1; i < v.size(); i++) { + if (v[i] == StringRef("-flavor")) { + if (i + 1 == v.size()) + die("missing arg value for '-flavor'"); + Flavor f = getFlavor(v[i + 1]); + if (f == Invalid) + die("Unknown flavor: " + StringRef(v[i + 1])); + v.erase(v.begin() + i, v.begin() + i + 2); + return f; + } } // Deduct the flavor from argv[0].