[PATCH] Add support for -R driver flag on OpenBSD

Matthew Dempsky matthew at dempsky.org
Mon Dec 16 17:06:11 PST 2013


On OpenBSD, GCC accepts "-R${dir}" and "-R ${dir}" and passes them to
the linker.  Attached patch adds similar support to Clang, and
includes a regress test.  See also bug 18164.

I'd appreciate if a CFE developer would commit this patch for me.

Thanks!

(Looking at GCC 4.2.1's source code, it appears that GCC accepts the
same flag on FreeBSD, NetBSD, and Solaris too, but I don't have any of
those available to test against.)
-------------- next part --------------
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td	(revision 197438)
+++ include/clang/Driver/Options.td	(working copy)
@@ -246,7 +246,7 @@ def Qn : Flag<["-"], "Qn">;
 def Qunused_arguments : Flag<["-"], "Qunused-arguments">, Flags<[DriverOption, CoreOption]>,
   HelpText<"Don't emit warning for unused driver arguments">;
 def Q : Flag<["-"], "Q">;
-def R : Flag<["-"], "R">;
+def R : JoinedOrSeparate<["-"], "R">;
 def S : Flag<["-"], "S">, Flags<[DriverOption,CC1Option]>, Group<Action_Group>,
   HelpText<"Only run preprocess and compilation steps">;
 def Tbss : JoinedOrSeparate<["-"], "Tbss">, Group<T_Group>;
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 197438)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -5596,6 +5596,7 @@ void openbsd::Link::ConstructJob(Compilation &C, c
                                        "/4.2.1"));
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
+  Args.AddAllArgs(CmdArgs, options::OPT_R);
   Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
   Args.AddAllArgs(CmdArgs, options::OPT_e);
   Args.AddAllArgs(CmdArgs, options::OPT_s);
Index: test/Driver/openbsd.c
===================================================================
--- test/Driver/openbsd.c	(revision 197438)
+++ test/Driver/openbsd.c	(working copy)
@@ -15,6 +15,10 @@
 // RUN:   | FileCheck --check-prefix=CHECK-LD-S %s
 // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -t %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-T %s
+// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -R /foo %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-BIGR %s
+// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -R/foo %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LD-BIGR %s
 // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -Z %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-Z %s
 // RUN: %clang -no-canonical-prefixes -target mips64-unknown-openbsd %s -### 2>&1 \
@@ -27,6 +31,8 @@
 // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
 // CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-T: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-t" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
+// CHECK-LD-BIGR: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
+// CHECK-LD-BIGR: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-R" "/foo" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
 // CHECK-LD-Z: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"
 // CHECK-LD-Z: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-Z" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o"
 // CHECK-MIPS64-LD: clang{{.*}}" "-cc1" "-triple" "mips64-unknown-openbsd"


More information about the cfe-commits mailing list