]>
Commit | Line | Data |
---|---|---|
b667dd70 | 1 | //===-- ubsan_flags.cpp ---------------------------------------------------===// |
866e32ad | 2 | // |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
866e32ad KS |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // Runtime flags for UndefinedBehaviorSanitizer. | |
10 | // | |
11 | //===----------------------------------------------------------------------===// | |
12 | ||
696d846a MO |
13 | #include "ubsan_platform.h" |
14 | #if CAN_SANITIZE_UB | |
866e32ad KS |
15 | #include "ubsan_flags.h" |
16 | #include "sanitizer_common/sanitizer_common.h" | |
17 | #include "sanitizer_common/sanitizer_flags.h" | |
696d846a | 18 | #include "sanitizer_common/sanitizer_flag_parser.h" |
866e32ad | 19 | |
eac97531 ML |
20 | #include <stdlib.h> |
21 | ||
866e32ad KS |
22 | namespace __ubsan { |
23 | ||
eac97531 ML |
24 | static const char *GetFlag(const char *flag) { |
25 | // We cannot call getenv() from inside a preinit array initializer | |
26 | if (SANITIZER_CAN_USE_PREINIT_ARRAY) { | |
27 | return GetEnv(flag); | |
28 | } else { | |
29 | return getenv(flag); | |
30 | } | |
31 | } | |
32 | ||
866e32ad KS |
33 | Flags ubsan_flags; |
34 | ||
696d846a MO |
35 | void Flags::SetDefaults() { |
36 | #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue; | |
37 | #include "ubsan_flags.inc" | |
38 | #undef UBSAN_FLAG | |
39 | } | |
40 | ||
41 | void RegisterUbsanFlags(FlagParser *parser, Flags *f) { | |
42 | #define UBSAN_FLAG(Type, Name, DefaultValue, Description) \ | |
43 | RegisterFlag(parser, #Name, Description, &f->Name); | |
44 | #include "ubsan_flags.inc" | |
45 | #undef UBSAN_FLAG | |
866e32ad KS |
46 | } |
47 | ||
48 | void InitializeFlags() { | |
696d846a MO |
49 | SetCommonFlagsDefaults(); |
50 | { | |
51 | CommonFlags cf; | |
52 | cf.CopyFrom(*common_flags()); | |
aaf0f121 | 53 | cf.print_summary = false; |
eac97531 | 54 | cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH"); |
696d846a MO |
55 | OverrideCommonFlags(cf); |
56 | } | |
57 | ||
866e32ad | 58 | Flags *f = flags(); |
696d846a MO |
59 | f->SetDefaults(); |
60 | ||
61 | FlagParser parser; | |
62 | RegisterCommonFlags(&parser); | |
63 | RegisterUbsanFlags(&parser, f); | |
64 | ||
866e32ad | 65 | // Override from user-specified string. |
0b997f6e | 66 | parser.ParseString(__ubsan_default_options()); |
866e32ad | 67 | // Override from environment variable. |
b667dd70 | 68 | parser.ParseStringFromEnv("UBSAN_OPTIONS"); |
10189819 | 69 | InitializeCommonFlags(); |
696d846a MO |
70 | if (Verbosity()) ReportUnrecognizedFlags(); |
71 | ||
72 | if (common_flags()->help) parser.PrintFlagDescriptions(); | |
866e32ad KS |
73 | } |
74 | ||
75 | } // namespace __ubsan | |
76 | ||
5d3805fc JJ |
77 | SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) { |
78 | return ""; | |
79 | } | |
696d846a MO |
80 | |
81 | #endif // CAN_SANITIZE_UB |