[PATCH] D80184: [lld] Accept -flavor FLAVOR anywhere on the command line

Greg McGary via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 18 22:45:11 PDT 2020


gkm created this revision.
gkm added reviewers: ruiu, pcc, MaskRay, smeenai, int3, Ktwu, alexshap, christylee.
Herald added a project: LLVM.
gkm added a comment.

Do I need a test for this change?


While developing the new MachO port of lld, we wish to select it via `clang -Wl,-flavor,darwinnew ...`. The compiler driver does not place `-Wl,...` args at the front of the lld command line, so lld must accept it at locations beyond `argv[1]`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80184

Files:
  lld/docs/Driver.rst
  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/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.264793.patch
Type: text/x-patch
Size: 1500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200519/fa1778b8/attachment-0001.bin>


More information about the llvm-commits mailing list