r213198 - Typically linker options are protected with -Xlinker or -Wl,

Arthur Marble arthur at info9.net
Wed Jul 16 14:16:17 PDT 2014


Author: bubbles231
Date: Wed Jul 16 16:16:16 2014
New Revision: 213198

URL: http://llvm.org/viewvc/llvm-project?rev=213198&view=rev
Log:
Typically linker options are protected with -Xlinker or -Wl,
however certain sloppy Makefiles pass -z options directly to
the compiler. This patch enables clang to recognize these
options (because -z is not used by clang itself).

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

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=213198&r1=213197&r2=213198&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jul 16 16:16:16 2014
@@ -309,6 +309,8 @@ def Xassembler : Separate<["-"], "Xassem
 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">,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=213198&r1=213197&r2=213198&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Jul 16 16:16:16 2014
@@ -201,8 +201,13 @@ static void AddLinkerInputs(const ToolCh
       TC.AddCXXStdlibLibArgs(Args, CmdArgs);
     else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
       TC.AddCCKextLibArgs(Args, CmdArgs);
-    else
-      A.renderAsInput(Args, CmdArgs);
+    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.

Modified: cfe/trunk/test/Driver/Xlinker-args.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Xlinker-args.c?rev=213198&r1=213197&r2=213198&view=diff
==============================================================================
--- cfe/trunk/test/Driver/Xlinker-args.c (original)
+++ cfe/trunk/test/Driver/Xlinker-args.c Wed Jul 16 16:16:16 2014
@@ -3,17 +3,17 @@
 
 // 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 -### \





More information about the cfe-commits mailing list