blob: ae15fd389b14b5b456f9e8fbab543d111b6ca45b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
//===-- ubsan_flags.cc ----------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Runtime flags for UndefinedBehaviorSanitizer.
//
//===----------------------------------------------------------------------===//
#include "ubsan_flags.h"
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_flags.h"
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 void InitializeCommonFlags() {
CommonFlags *cf = common_flags();
SetCommonFlagsDefaults(cf);
cf->print_summary = false;
// Override from compile definition.
ParseCommonFlagsFromString(cf, GetRuntimeFlagsFromCompileDefinition());
// Override from environment variable.
ParseCommonFlagsFromString(cf, GetEnv("UBSAN_OPTIONS"));
}
Flags ubsan_flags;
static void ParseFlagsFromString(Flags *f, const char *str) {
if (!str)
return;
ParseFlag(str, &f->halt_on_error, "halt_on_error",
"Crash the program after printing the first error report");
ParseFlag(str, &f->print_stacktrace, "print_stacktrace",
"Include full stacktrace into an error report");
}
void InitializeFlags() {
InitializeCommonFlags();
Flags *f = flags();
// Default values.
f->halt_on_error = false;
f->print_stacktrace = false;
// Override from compile definition.
ParseFlagsFromString(f, GetRuntimeFlagsFromCompileDefinition());
// Override from environment variable.
ParseFlagsFromString(f, GetEnv("UBSAN_OPTIONS"));
}
} // namespace __ubsan
|