[compiler-rt] r218137 - [UBSan] Introduce more flexible __ubsan_default_options function instead of UBSAN_DEFAULT_OPTIONS compile definition
Alexey Samsonov
vonosmas at gmail.com
Fri Sep 19 11:54:52 PDT 2014
Author: samsonov
Date: Fri Sep 19 13:54:52 2014
New Revision: 218137
URL: http://llvm.org/viewvc/llvm-project?rev=218137&view=rev
Log:
[UBSan] Introduce more flexible __ubsan_default_options function instead of UBSAN_DEFAULT_OPTIONS compile definition
Modified:
compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
compiler-rt/trunk/lib/ubsan/ubsan_flags.h
compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp
Modified: compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.cc?rev=218137&r1=218136&r2=218137&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.cc Fri Sep 19 13:54:52 2014
@@ -17,23 +17,16 @@
namespace __ubsan {
-static const char *GetRuntimeFlagsFromCompileDefinition() {
-#ifdef UBSAN_DEFAULT_OPTIONS
-// Stringize the macro value
-# define UBSAN_STRINGIZE(x) #x
-# define UBSAN_STRINGIZE_OPTIONS(options) UBSAN_STRINGIZE(options)
- return UBSAN_STRINGIZE_OPTIONS(UBSAN_DEFAULT_OPTIONS);
-#else
- return "";
-#endif
+static const char *MaybeCallUbsanDefaultOptions() {
+ return (&__ubsan_default_options) ? __ubsan_default_options() : "";
}
void InitializeCommonFlags() {
CommonFlags *cf = common_flags();
SetCommonFlagsDefaults(cf);
cf->print_summary = false;
- // Override from compile definition.
- ParseCommonFlagsFromString(cf, GetRuntimeFlagsFromCompileDefinition());
+ // Override from user-specified string.
+ ParseCommonFlagsFromString(cf, MaybeCallUbsanDefaultOptions());
// Override from environment variable.
ParseCommonFlagsFromString(cf, GetEnv("UBSAN_OPTIONS"));
}
@@ -54,10 +47,17 @@ void InitializeFlags() {
// Default values.
f->halt_on_error = false;
f->print_stacktrace = false;
- // Override from compile definition.
- ParseFlagsFromString(f, GetRuntimeFlagsFromCompileDefinition());
+ // Override from user-specified string.
+ ParseFlagsFromString(f, MaybeCallUbsanDefaultOptions());
// Override from environment variable.
ParseFlagsFromString(f, GetEnv("UBSAN_OPTIONS"));
}
} // namespace __ubsan
+
+#if !SANITIZER_SUPPORTS_WEAK_HOOKS
+extern "C" {
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
+const char *__ubsan_default_options() { return ""; }
+} // extern "C"
+#endif
Modified: compiler-rt/trunk/lib/ubsan/ubsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.h?rev=218137&r1=218136&r2=218137&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.h Fri Sep 19 13:54:52 2014
@@ -13,6 +13,8 @@
#ifndef UBSAN_FLAGS_H
#define UBSAN_FLAGS_H
+#include "sanitizer_common/sanitizer_internal_defs.h"
+
namespace __ubsan {
struct Flags {
@@ -28,4 +30,11 @@ void InitializeFlags();
} // namespace __ubsan
+extern "C" {
+// Users may provide their own implementation of __ubsan_default_options to
+// override the default flag values.
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
+const char *__ubsan_default_options();
+} // extern "C"
+
#endif // UBSAN_FLAGS_H
Modified: compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp?rev=218137&r1=218136&r2=218137&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp Fri Sep 19 13:54:52 2014
@@ -2,14 +2,14 @@
// RUN: %run %t rT && %run %t mT && %run %t fT && %run %t cT
// RUN: %run %t rU && %run %t mU && %run %t fU && %run %t cU
// RUN: %run %t rS && %run %t rV && %run %t oV
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t mS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --strict-whitespace
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t fS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t cS 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --strict-whitespace
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t mV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --strict-whitespace
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t fV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t cV 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --strict-whitespace
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t oU 2>&1 | FileCheck %s --check-prefix=CHECK-OFFSET --strict-whitespace
-// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL-MEMBER --strict-whitespace
+// RUN: %run %t mS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --strict-whitespace
+// RUN: %run %t fS 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
+// RUN: %run %t cS 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --strict-whitespace
+// RUN: %run %t mV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMBER --strict-whitespace
+// RUN: %run %t fV 2>&1 | FileCheck %s --check-prefix=CHECK-MEMFUN --strict-whitespace
+// RUN: %run %t cV 2>&1 | FileCheck %s --check-prefix=CHECK-DOWNCAST --strict-whitespace
+// RUN: %run %t oU 2>&1 | FileCheck %s --check-prefix=CHECK-OFFSET --strict-whitespace
+// RUN: %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL-MEMBER --strict-whitespace
// RUN: (echo "vptr_check:S"; echo "vptr_check:T"; echo "vptr_check:U") > %t.supp
// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t mS 2>&1
@@ -26,6 +26,12 @@
// FIXME: This test produces linker errors on Darwin.
// XFAIL: darwin
+extern "C" {
+const char *__ubsan_default_options() {
+ return "print_stacktrace=1";
+}
+}
+
struct S {
S() : a(0) {}
~S() {}
More information about the llvm-commits
mailing list