]> granicus.if.org Git - clang/commitdiff
Driver: Dissect -Wl, and -Xlinker arguments to remove --no-demangle, which was a
authorDaniel Dunbar <daniel@zuster.org>
Mon, 14 Jun 2010 21:23:12 +0000 (21:23 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 14 Jun 2010 21:23:12 +0000 (21:23 +0000)
collect2 option that is passed by some projects (notably WebKit).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105964 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Arg.h
include/clang/Driver/Options.td
lib/Driver/Driver.cpp
test/Driver/Xlinker-args.c [new file with mode: 0644]

index 590bbd6981df19872206cbc19697fe4ab72ffc24..a52789e699290e8fb39741c14f28c4955428f88a 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "Util.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 #include <vector>
 #include <string>
 
@@ -91,6 +92,13 @@ namespace driver {
       return Values;
     }
 
+    bool containsValue(llvm::StringRef Value) const {
+      for (unsigned i = 0, e = getNumValues(); i != e; ++i)
+        if (Values[i] == Value)
+          return true;
+      return false;
+    }
+
     /// render - Append the argument onto the given array as strings.
     void render(const ArgList &Args, ArgStringList &Output) const;
 
index 68604aaf7119493e68667deb0e96f75f6892629a..d5d649b0b8f6fe63b576e36cd27efa950d74c3a4 100644 (file)
@@ -715,3 +715,6 @@ def _warn_ : Joined<"--warn-">, Alias<W_Joined>;
 def _write_dependencies : Flag<"--write-dependencies">, Alias<MD>;
 def _write_user_dependencies : Flag<"--write-user-dependencies">, Alias<MMD>;
 def _ : Joined<"--">, Flags<[Unsupported]>;
+
+// Special internal option to handle -Xlinker --no-demangle.
+def Z_Xlinker__no_demangle : Flag<"-Z-Xlinker-no-demangle">, Flags<[Unsupported]>;
index 2ca30f1bacafc2cd3df72475d50ab516cab90f30..43514339456a7a030c92ff135858a239738f8ac2 100644 (file)
@@ -114,8 +114,32 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
   DerivedArgList *DAL = new DerivedArgList(Args);
 
   for (ArgList::const_iterator it = Args.begin(),
-         ie = Args.end(); it != ie; ++it)
+         ie = Args.end(); it != ie; ++it) {
+    const Arg *A = *it;
+
+    // Unfortunately, we have to parse some forwarding options (-Xassembler,
+    // -Xlinker, -Xpreprocessor) because we either integrate their functionality
+    // (assembler and preprocessor), or bypass a previous driver ('collect2').
+    if (A->getOption().matches(options::OPT_Xlinker) &&
+        A->getValue(Args) == llvm::StringRef("--no-demangle")) {
+      DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_Xlinker__no_demangle));
+      continue;
+    } else if (A->getOption().matches(options::OPT_Wl_COMMA) &&
+               A->containsValue("--no-demangle")) {
+      // Add the rewritten no-demangle argument.
+      DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_Xlinker__no_demangle));
+
+      // Add the remaining values as Xlinker arguments.
+      for (unsigned i = 0, e = A->getNumValues(); i != e; ++i)
+        if (llvm::StringRef(A->getValue(Args, i)) != "--no-demangle")
+          DAL->AddSeparateArg(A, Opts->getOption(options::OPT_Xlinker),
+                              A->getValue(Args, i));
+
+      continue;
+    }
+
     DAL->append(*it);
+  }
 
   return DAL;
 }
@@ -322,7 +346,7 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
     llvm::outs() << CLANG_VERSION_STRING "\n";
     return false;
   }
-  
+
   if (C.getArgs().hasArg(options::OPT__print_diagnostic_categories)) {
     PrintDiagnosticCategories(llvm::outs());
     return false;
@@ -1230,7 +1254,7 @@ const HostInfo *Driver::GetHostInfo(const char *TripleStr) const {
 
   // TCE is an osless target
   if (Triple.getArchName() == "tce")
-    return createTCEHostInfo(*this, Triple); 
+    return createTCEHostInfo(*this, Triple);
 
   switch (Triple.getOS()) {
   case llvm::Triple::AuroraUX:
diff --git a/test/Driver/Xlinker-args.c b/test/Driver/Xlinker-args.c
new file mode 100644 (file)
index 0000000..fff8fa0
--- /dev/null
@@ -0,0 +1,9 @@
+// Check that we extract --no-demangle from '-Xlinker' and '-Wl,', since that
+// was a collect2 argument.
+
+// RUN: %clang --ccc-host-triple i386-apple-darwin9 -### \
+// RUN:   -Xlinker one -Xlinker --no-demangle \
+// RUN:   -Wl,two,--no-demangle,three -Xlinker four %s 2> %t
+// RUN: FileCheck < %t %s
+//
+// CHECK: "one" "two" "three" "four"