[PATCH] clang-cl: Support the /link option and hard-code the target triple

Hans Wennborg hans at chromium.org
Tue Aug 13 14:18:06 PDT 2013


Hi rnk,

This adds support for the /link option, which forwards subsequent arguments to the linker.

The test for this will only work when targeting win32. Since that's the only target where clang-cl makes sense, let's hard-code it.

http://llvm-reviews.chandlerc.com/D1388

Files:
  include/clang/Driver/CLCompatOptions.td
  lib/Driver/Driver.cpp
  lib/Driver/Tools.cpp
  test/Driver/cl-link.c

Index: include/clang/Driver/CLCompatOptions.td
===================================================================
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -32,6 +32,9 @@
 class CLJoinedOrSeparate<string name> : Option<["/", "-"], name,
   KIND_JOINED_OR_SEPARATE>, Group<cl_Group>, Flags<[CLOption, DriverOption]>;
 
+class CLRemainingArgs<string name> : Option<["/", "-"], name,
+  KIND_REMAINING_ARGS>, Group<cl_Group>, Flags<[CLOption, DriverOption]>;
+
 // Aliases:
 
 def _SLASH_c : CLFlag<"c">, HelpText<"Compile only">, Alias<c>;
@@ -96,6 +99,8 @@
 def _SLASH_Fo : CLJoined<"Fo">,
   HelpText<"Set output object file, or directory (ends in / or \\)">,
   MetaVarName<"<file or directory>">;
+def _SLASH_link : CLRemainingArgs<"link">,
+  HelpText<"Forward options to the linker">, MetaVarName<"<options>">;
 def _SLASH_MD : CLFlag<"MD">,
   HelpText<"Use DLL run-time">;
 def _SLASH_MDd : CLFlag<"MDd">,
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -335,6 +335,8 @@
                             options::OPT_ccc_pch_is_pth);
   // FIXME: DefaultTargetTriple is used by the target-prefixed calls to as/ld
   // and getToolChain is const.
+  if (IsCLMode())
+    DefaultTargetTriple = "i686-pc-win32";
   if (const Arg *A = Args->getLastArg(options::OPT_target))
     DefaultTargetTriple = A->getValue();
   if (const Arg *A = Args->getLastArg(options::OPT_ccc_install_dir))
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6593,6 +6593,7 @@
   CmdArgs.push_back("-nologo");
 
   Args.AddAllArgValues(CmdArgs, options::OPT_l);
+  Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
 
   // Add filenames immediately.
   for (InputInfoList::const_iterator
Index: test/Driver/cl-link.c
===================================================================
--- /dev/null
+++ test/Driver/cl-link.c
@@ -0,0 +1,12 @@
+// Don't attempt slash switches on msys bash.
+// REQUIRES: shell-preserves-root
+
+// Note: %s must be preceded by -- or bound to another option, otherwise it may
+// be interpreted as a command-line option, e.g. on Mac where %s is commonly
+// under /Users.
+
+// RUN: %clang_cl /Tc%s -### /link foo bar baz 2>&1 | FileCheck %s
+// CHECK: link.exe
+// CHECK: "foo"
+// CHECK: "bar"
+// CHECK: "baz"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1388.1.patch
Type: text/x-patch
Size: 2480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130813/23622785/attachment.bin>


More information about the cfe-commits mailing list