PR rtl-optimization/79386
[official-gcc.git] / libsanitizer / tsan / tsan_flags.cc
blob5064a0fe65396252b1dabbd770118b8cfc8a2da4
1 //===-- tsan_flags.cc -----------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
9 //
10 //===----------------------------------------------------------------------===//
12 #include "sanitizer_common/sanitizer_flags.h"
13 #include "sanitizer_common/sanitizer_flag_parser.h"
14 #include "sanitizer_common/sanitizer_libc.h"
15 #include "tsan_flags.h"
16 #include "tsan_rtl.h"
17 #include "tsan_mman.h"
18 #include "ubsan/ubsan_flags.h"
20 namespace __tsan {
22 Flags *flags() {
23 return &ctx->flags;
26 // Can be overriden in frontend.
27 #ifdef TSAN_EXTERNAL_HOOKS
28 extern "C" const char* __tsan_default_options();
29 #else
30 SANITIZER_WEAK_DEFAULT_IMPL
31 const char *__tsan_default_options() {
32 return "";
34 #endif
36 void Flags::SetDefaults() {
37 #define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
38 #include "tsan_flags.inc"
39 #undef TSAN_FLAG
40 // DDFlags
41 second_deadlock_stack = false;
44 void RegisterTsanFlags(FlagParser *parser, Flags *f) {
45 #define TSAN_FLAG(Type, Name, DefaultValue, Description) \
46 RegisterFlag(parser, #Name, Description, &f->Name);
47 #include "tsan_flags.inc"
48 #undef TSAN_FLAG
49 // DDFlags
50 RegisterFlag(parser, "second_deadlock_stack",
51 "Report where each mutex is locked in deadlock reports",
52 &f->second_deadlock_stack);
55 void InitializeFlags(Flags *f, const char *env) {
56 SetCommonFlagsDefaults();
58 // Override some common flags defaults.
59 CommonFlags cf;
60 cf.CopyFrom(*common_flags());
61 cf.allow_addr2line = true;
62 if (SANITIZER_GO) {
63 // Does not work as expected for Go: runtime handles SIGABRT and crashes.
64 cf.abort_on_error = false;
65 // Go does not have mutexes.
66 } else {
67 cf.detect_deadlocks = true;
69 cf.print_suppressions = false;
70 cf.stack_trace_format = " #%n %f %S %M";
71 cf.exitcode = 66;
72 cf.intercept_tls_get_addr = true;
73 OverrideCommonFlags(cf);
76 f->SetDefaults();
78 FlagParser parser;
79 RegisterTsanFlags(&parser, f);
80 RegisterCommonFlags(&parser);
82 #if TSAN_CONTAINS_UBSAN
83 __ubsan::Flags *uf = __ubsan::flags();
84 uf->SetDefaults();
86 FlagParser ubsan_parser;
87 __ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
88 RegisterCommonFlags(&ubsan_parser);
89 #endif
91 // Let a frontend override.
92 parser.ParseString(__tsan_default_options());
93 #if TSAN_CONTAINS_UBSAN
94 const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
95 ubsan_parser.ParseString(ubsan_default_options);
96 #endif
97 // Override from command line.
98 parser.ParseString(env);
99 #if TSAN_CONTAINS_UBSAN
100 ubsan_parser.ParseString(GetEnv("UBSAN_OPTIONS"));
101 #endif
103 // Sanity check.
104 if (!f->report_bugs) {
105 f->report_thread_leaks = false;
106 f->report_destroy_locked = false;
107 f->report_signal_unsafe = false;
110 InitializeCommonFlags();
112 if (Verbosity()) ReportUnrecognizedFlags();
114 if (common_flags()->help) parser.PrintFlagDescriptions();
116 if (f->history_size < 0 || f->history_size > 7) {
117 Printf("ThreadSanitizer: incorrect value for history_size"
118 " (must be [0..7])\n");
119 Die();
122 if (f->io_sync < 0 || f->io_sync > 2) {
123 Printf("ThreadSanitizer: incorrect value for io_sync"
124 " (must be [0..2])\n");
125 Die();
129 } // namespace __tsan