[PATCH] Add support for -R driver flag on OpenBSD
Matthew Dempsky
matthew at dempsky.org
Tue Dec 17 15:39:08 PST 2013
On Tue, Dec 17, 2013 at 10:58:30PM +0100, Joerg Sonnenberger wrote:
> Because using -R/usr/local/lib has been actively creating harm.
Can you provide some concrete examples?
Regardless, I've attached a revised patch that emits an error when
-R/usr/local/lib is specified on the command-line but it's not claimed
by the driver. Please review.
-------------- next part --------------
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td (revision 197534)
+++ include/clang/Basic/DiagnosticDriverKinds.td (working copy)
@@ -79,6 +79,8 @@
"invalid deployment target for -stdlib=libc++ (requires %0 or later)">;
def err_drv_malformed_sanitizer_blacklist : Error<
"malformed sanitizer blacklist: '%0'">;
+def err_drv_unused_argument : Error<
+ "argument unused during compilation: '%0'">;
def err_drv_I_dash_not_supported : Error<
"'%0' not supported, please use -iquote instead">;
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td (revision 197534)
+++ include/clang/Driver/Options.td (working copy)
@@ -47,6 +47,9 @@
// NoDriverOption - This option should not be accepted by the driver.
def NoDriverOption : OptionFlag;
+// UnusedError - If this option is unused, report an error instead of a warning.
+def UnusedError : OptionFlag;
+
/////////
// Groups
@@ -246,7 +249,7 @@
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">, Flags<[RenderJoined, UnusedError]>;
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: include/clang/Driver/Options.h
===================================================================
--- include/clang/Driver/Options.h (revision 197534)
+++ include/clang/Driver/Options.h (working copy)
@@ -30,7 +30,8 @@
CoreOption = (1 << 8),
CLOption = (1 << 9),
CC1Option = (1 << 10),
- NoDriverOption = (1 << 11)
+ NoDriverOption = (1 << 11),
+ UnusedError = (1 << 12)
};
enum ID {
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp (revision 197534)
+++ lib/Driver/Driver.cpp (working copy)
@@ -1439,7 +1439,9 @@
continue;
}
- Diag(clang::diag::warn_drv_unused_argument)
+ Diag(A->getOption().hasFlag(options::UnusedError)
+ ? clang::diag::err_drv_unused_argument
+ : clang::diag::warn_drv_unused_argument)
<< A->getAsString(C.getArgs());
}
}
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp (revision 197534)
+++ lib/Driver/Tools.cpp (working copy)
@@ -5598,6 +5598,7 @@
"/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 197534)
+++ 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"
Index: test/Driver/linux-ld.c
===================================================================
--- test/Driver/linux-ld.c (revision 197534)
+++ test/Driver/linux-ld.c (working copy)
@@ -707,3 +707,8 @@
// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>& 1 \
// RUN: | FileCheck --check-prefix=CHECK-PG %s
// CHECK-PG: gcrt1.o
+
+// Check that -R/usr/local/lib triggers an error.
+// RUN: %clang --target=i386-pc-linux -R/usr/local/lib -### %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-REJECT-R %s
+// CHECK-REJECT-R: error: argument unused during compilation: '-R/usr/local/lib'
More information about the cfe-commits
mailing list