[PATCH] GCC compatibility: pass -z linker options to the linker

Arthur arthur at info9.net
Tue Jul 15 17:48:05 PDT 2014


Make the requested changes.

http://reviews.llvm.org/D4393

Files:
  include/clang/Driver/Options.td
  lib/Driver/Tools.cpp
  test/Driver/Xlinker-args.c

Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -309,6 +309,8 @@
 def Xclang : Separate<["-"], "Xclang">,
   HelpText<"Pass <arg> to the clang compiler">, MetaVarName<"<arg>">,
   Flags<[DriverOption, CoreOption]>;
+def z : Separate<["-"], "z">, Flags<[LinkerInput, RenderAsInput]>,
+  HelpText<"Pass -z <arg> to the linker">, MetaVarName<"<arg>">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass <arg> to the linker">, MetaVarName<"<arg>">;
 def Xpreprocessor : Separate<["-"], "Xpreprocessor">,
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -201,10 +201,13 @@
       TC.AddCXXStdlibLibArgs(Args, CmdArgs);
     else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
       TC.AddCCKextLibArgs(Args, CmdArgs);
-    else
+    else if (A.getOption().matches(options::OPT_z)) {
+      // Pass -z prefix for gcc linker compatibility.
+      A.claim(); A.render(Args, CmdArgs);
+    } else {
       A.renderAsInput(Args, CmdArgs);
+    }
   }
-
   // LIBRARY_PATH - included following the user specified library paths.
   //                and only supported on native toolchains.
   if (!TC.isCrossCompiling())
@@ -7599,9 +7602,13 @@
   // Add filenames immediately.
   for (const auto &Input : Inputs)
     if (Input.isFilename())
-      CmdArgs.push_back(Input.getFilename());
-    else
+      CmdArgs.push_back(Input.getFilename()); 
+    else if (Input.getInputArg().getOption().matches(options::OPT_z)) {
+      // Pass -z prefix for gcc linker compatibility.
+      Input.getInputArg().claim(); Input.getInputArg().render(Args, CmdArgs);
+    } else {
       Input.getInputArg().renderAsInput(Args, CmdArgs);
+    }
 
   const char *Exec =
     Args.MakeArgString(getToolChain().GetProgramPath("link.exe"));
Index: test/Driver/Xlinker-args.c
===================================================================
--- test/Driver/Xlinker-args.c
+++ test/Driver/Xlinker-args.c
@@ -3,22 +3,24 @@
 
 // RUN: %clang -target i386-apple-darwin9 -### \
 // RUN:   -Xlinker one -Xlinker --no-demangle \
-// RUN:   -Wl,two,--no-demangle,three -Xlinker four %s 2> %t
+// RUN:   -Wl,two,--no-demangle,three -Xlinker four -z five %s 2> %t
 // RUN: FileCheck -check-prefix=DARWIN < %t %s
 //
 // RUN: %clang -target x86_64-pc-linux-gnu -### \
 // RUN:   -Xlinker one -Xlinker --no-demangle \
-// RUN:   -Wl,two,--no-demangle,three -Xlinker four %s 2> %t
+// RUN:   -Wl,two,--no-demangle,three -Xlinker four -z five %s 2> %t
 // RUN: FileCheck -check-prefix=LINUX < %t %s
 //
 // DARWIN-NOT: --no-demangle
-// DARWIN: "one" "two" "three" "four"
-// LINUX: "--no-demangle" "one" "two" "three" "four"
+// DARWIN: "one" "two" "three" "four" "-z" "five"
+// LINUX: "--no-demangle" "one" "two" "three" "four" "-z" "five"
 
 // Check that we forward '-Xlinker' and '-Wl,' on Windows.
 // RUN: %clang -target i686-pc-win32 -### \
-// RUN:   -Xlinker one -Wl,two %s 2>&1 | \
-// RUN:   FileCheck -check-prefix=WIN %s
+// RUN:   -Xlinker one -Wl,two -z three %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=WIN %s 
 // WIN: link.exe
 // WIN: "one"
 // WIN: "two"
+// WIN: "-z"
+// WIN: "three"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4393.11480.patch
Type: text/x-patch
Size: 3369 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140716/8c79eec5/attachment.bin>


More information about the cfe-commits mailing list