[PATCH] D80184: [lld] Accept -flavor FLAVOR anywhere on the command line
Greg McGary via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 19 09:17:06 PDT 2020
gkm updated this revision to Diff 264941.
gkm removed a subscriber: grimar.
gkm added a comment.
Herald added a subscriber: aheejin.
Add lld Driver tests
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80184/new/
https://reviews.llvm.org/D80184
Files:
lld/docs/Driver.rst
lld/test/Driver/flavor.test
lld/tools/lld/lld.cpp
Index: lld/tools/lld/lld.cpp
===================================================================
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -111,14 +111,16 @@
static Flavor parseFlavor(std::vector<const char *> &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].
Index: lld/test/Driver/flavor.test
===================================================================
--- /dev/null
+++ 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
Index: lld/docs/Driver.rst
===================================================================
--- lld/docs/Driver.rst
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80184.264941.patch
Type: text/x-patch
Size: 3327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200519/0b99c0d4/attachment.bin>
More information about the llvm-commits
mailing list