Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 1 | //===-- ubsan_flags.cc ----------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Runtime flags for UndefinedBehaviorSanitizer. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 14 | #include "ubsan_platform.h" |
| 15 | #if CAN_SANITIZE_UB |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 16 | #include "ubsan_flags.h" |
| 17 | #include "sanitizer_common/sanitizer_common.h" |
| 18 | #include "sanitizer_common/sanitizer_flags.h" |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 19 | #include "sanitizer_common/sanitizer_flag_parser.h" |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 20 | |
| 21 | namespace __ubsan { |
| 22 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 23 | const char *MaybeCallUbsanDefaultOptions() { |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 24 | return (&__ubsan_default_options) ? __ubsan_default_options() : ""; |
| 25 | } |
| 26 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 27 | Flags ubsan_flags; |
| 28 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 29 | void Flags::SetDefaults() { |
| 30 | #define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue; |
| 31 | #include "ubsan_flags.inc" |
| 32 | #undef UBSAN_FLAG |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 33 | } |
| 34 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 35 | void RegisterUbsanFlags(FlagParser *parser, Flags *f) { |
| 36 | #define UBSAN_FLAG(Type, Name, DefaultValue, Description) \ |
| 37 | RegisterFlag(parser, #Name, Description, &f->Name); |
| 38 | #include "ubsan_flags.inc" |
| 39 | #undef UBSAN_FLAG |
| 40 | } |
| 41 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 42 | void InitializeFlags() { |
| 43 | SetCommonFlagsDefaults(); |
| 44 | { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 45 | CommonFlags cf; |
| 46 | cf.CopyFrom(*common_flags()); |
| 47 | cf.print_summary = false; |
| 48 | OverrideCommonFlags(cf); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 51 | Flags *f = flags(); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 52 | f->SetDefaults(); |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 53 | |
| 54 | FlagParser parser; |
| 55 | RegisterCommonFlags(&parser); |
| 56 | RegisterUbsanFlags(&parser, f); |
| 57 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 58 | // Override from user-specified string. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 59 | parser.ParseString(MaybeCallUbsanDefaultOptions()); |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 60 | // Override from environment variable. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 61 | parser.ParseString(GetEnv("UBSAN_OPTIONS")); |
| 62 | SetVerbosity(common_flags()->verbosity); |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace __ubsan |
| 66 | |
| 67 | #if !SANITIZER_SUPPORTS_WEAK_HOOKS |
| 68 | extern "C" { |
| 69 | SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE |
| 70 | const char *__ubsan_default_options() { return ""; } |
| 71 | } // extern "C" |
| 72 | #endif |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 73 | |
| 74 | #endif // CAN_SANITIZE_UB |