[compiler-rt] r226563 - [asan] Warn if unsupported flags are used at activation.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Tue Jan 20 04:19:15 PST 2015
Author: eugenis
Date: Tue Jan 20 06:19:14 2015
New Revision: 226563
URL: http://llvm.org/viewvc/llvm-project?rev=226563&view=rev
Log:
[asan] Warn if unsupported flags are used at activation.
Added:
compiler-rt/trunk/lib/asan/asan_activation_flags.inc
Modified:
compiler-rt/trunk/lib/asan/asan_activation.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc
Modified: compiler-rt/trunk/lib/asan/asan_activation.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_activation.cc?rev=226563&r1=226562&r2=226563&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_activation.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_activation.cc Tue Jan 20 06:19:14 2015
@@ -29,12 +29,23 @@ static struct AsanDeactivatedFlags {
bool coverage;
const char *coverage_dir;
+ void RegisterActivationFlags(FlagParser *parser, Flags *f, CommonFlags *cf) {
+#define ASAN_ACTIVATION_FLAG(Type, Name) \
+ RegisterFlag(parser, #Name, "", &f->Name);
+#define COMMON_ACTIVATION_FLAG(Type, Name) \
+ RegisterFlag(parser, #Name, "", &cf->Name);
+#include "asan_activation_flags.inc"
+#undef ASAN_ACTIVATION_FLAG
+#undef COMMON_ACTIVATION_FLAG
+
+ RegisterIncludeFlag(parser, cf);
+ }
+
void OverrideFromActivationFlags() {
Flags f;
CommonFlags cf;
FlagParser parser;
- RegisterAsanFlags(&parser, &f);
- RegisterCommonFlags(&parser, &cf);
+ RegisterActivationFlags(&parser, &f, &cf);
// Copy the current activation flags.
allocator_options.CopyTo(&f, &cf);
@@ -42,10 +53,9 @@ static struct AsanDeactivatedFlags {
f.poison_heap = poison_heap;
cf.coverage = coverage;
cf.coverage_dir = coverage_dir;
+ cf.help = false; // this is activation-specific help
// Check if activation flags need to be overriden.
- // FIXME: Add diagnostic to check that activation flags string doesn't
- // contain any other flags.
if (const char *env = GetEnv("ASAN_ACTIVATION_OPTIONS")) {
parser.ParseString(env);
}
@@ -55,6 +65,10 @@ static struct AsanDeactivatedFlags {
GetExtraActivationFlags(buf, sizeof(buf));
parser.ParseString(buf);
+ if (common_flags()->verbosity) ReportUnrecognizedFlags();
+
+ if (cf.help) parser.PrintFlagDescriptions();
+
allocator_options.SetFrom(&f, &cf);
malloc_context_size = cf.malloc_context_size;
poison_heap = f.poison_heap;
Added: compiler-rt/trunk/lib/asan/asan_activation_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_activation_flags.inc?rev=226563&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_activation_flags.inc (added)
+++ compiler-rt/trunk/lib/asan/asan_activation_flags.inc Tue Jan 20 06:19:14 2015
@@ -0,0 +1,34 @@
+//===-- asan_activation_flags.inc -------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// A subset of ASan (and common) runtime flags supported at activation time.
+//
+//===----------------------------------------------------------------------===//
+#ifndef ASAN_ACTIVATION_FLAG
+# error "Define ASAN_ACTIVATION_FLAG prior to including this file!"
+#endif
+
+#ifndef COMMON_ACTIVATION_FLAG
+# error "Define COMMON_ACTIVATION_FLAG prior to including this file!"
+#endif
+
+// ASAN_ACTIVATION_FLAG(Type, Name)
+// See COMMON_FLAG in sanitizer_flags.inc for more details.
+
+ASAN_ACTIVATION_FLAG(int, redzone)
+ASAN_ACTIVATION_FLAG(int, max_redzone)
+ASAN_ACTIVATION_FLAG(int, quarantine_size_mb)
+ASAN_ACTIVATION_FLAG(bool, alloc_dealloc_mismatch)
+ASAN_ACTIVATION_FLAG(bool, poison_heap)
+
+COMMON_ACTIVATION_FLAG(bool, allocator_may_return_null)
+COMMON_ACTIVATION_FLAG(int, malloc_context_size)
+COMMON_ACTIVATION_FLAG(bool, coverage)
+COMMON_ACTIVATION_FLAG(const char *, coverage_dir)
+COMMON_ACTIVATION_FLAG(bool, help)
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=226563&r1=226562&r2=226563&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Tue Jan 20 06:19:14 2015
@@ -68,16 +68,20 @@ class FlagHandlerInclude : public FlagHa
}
};
+void RegisterIncludeFlag(FlagParser *parser, CommonFlags *cf) {
+ FlagHandlerInclude *fh_include =
+ new (FlagParser::Alloc) FlagHandlerInclude(parser); // NOLINT
+ parser->RegisterHandler("include", fh_include,
+ "read more options from the given file");
+}
+
void RegisterCommonFlags(FlagParser *parser, CommonFlags *cf) {
#define COMMON_FLAG(Type, Name, DefaultValue, Description) \
RegisterFlag(parser, #Name, Description, &cf->Name);
#include "sanitizer_flags.inc"
#undef COMMON_FLAG
- FlagHandlerInclude *fh_include =
- new (FlagParser::Alloc) FlagHandlerInclude(parser); // NOLINT
- parser->RegisterHandler("include", fh_include,
- "read more options from the given file");
+ RegisterIncludeFlag(parser, cf);
}
} // namespace __sanitizer
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h?rev=226563&r1=226562&r2=226563&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Tue Jan 20 06:19:14 2015
@@ -49,6 +49,7 @@ inline void OverrideCommonFlags(const Co
class FlagParser;
void RegisterCommonFlags(FlagParser *parser,
CommonFlags *cf = &common_flags_dont_use);
+void RegisterIncludeFlag(FlagParser *parser, CommonFlags *cf);
} // namespace __sanitizer
#endif // SANITIZER_FLAGS_H
Modified: compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc?rev=226563&r1=226562&r2=226563&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc Tue Jan 20 06:19:14 2015
@@ -6,7 +6,12 @@
// RUN: %clangxx -O0 %s -c -o %t.o
// RUN: %clangxx_asan -O0 %t.o %libdl -o %t
// RUN: ASAN_OPTIONS=start_deactivated=1,allocator_may_return_null=0 \
-// RUN: ASAN_ACTIVATION_OPTIONS=allocator_may_return_null=1 not %run %t 2>&1 | FileCheck %s
+// RUN: ASAN_ACTIVATION_OPTIONS=allocator_may_return_null=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: ASAN_OPTIONS=start_deactivated=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=help=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HELP
+// RUN: ASAN_OPTIONS=start_deactivated=1,verbosity=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
+
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
@@ -75,3 +80,13 @@ extern "C" void do_another_bad_thing() {
printf("%hhx\n", p[105]);
}
#endif // SHARED_LIB
+
+// help=1 in activation flags lists only flags are are supported at activation
+// CHECK-HELP: Available flags for {{.*}}Sanitizer:
+// CHECK-HELP-NOT: handle_segv
+// CHECK-HELP: max_redzone
+// CHECK-HELP-NOT: handle_segv
+
+// unsupported activation flags produce a warning
+// CHECK-UNSUPPORTED: WARNING: found 1 unrecognized
+// CHECK-UNSUPPORTED: handle_segv
More information about the llvm-commits
mailing list