]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/tsan/rtl/tsan_flags.cc
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r306956, and update
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / tsan / rtl / tsan_flags.cc
1 //===-- tsan_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 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "sanitizer_common/sanitizer_flags.h"
15 #include "sanitizer_common/sanitizer_flag_parser.h"
16 #include "sanitizer_common/sanitizer_libc.h"
17 #include "tsan_flags.h"
18 #include "tsan_rtl.h"
19 #include "tsan_mman.h"
20 #include "ubsan/ubsan_flags.h"
21
22 namespace __tsan {
23
24 // Can be overriden in frontend.
25 #ifdef TSAN_EXTERNAL_HOOKS
26 extern "C" const char* __tsan_default_options();
27 #else
28 SANITIZER_WEAK_DEFAULT_IMPL
29 const char *__tsan_default_options() {
30   return "";
31 }
32 #endif
33
34 void Flags::SetDefaults() {
35 #define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
36 #include "tsan_flags.inc"
37 #undef TSAN_FLAG
38   // DDFlags
39   second_deadlock_stack = false;
40 }
41
42 void RegisterTsanFlags(FlagParser *parser, Flags *f) {
43 #define TSAN_FLAG(Type, Name, DefaultValue, Description) \
44   RegisterFlag(parser, #Name, Description, &f->Name);
45 #include "tsan_flags.inc"
46 #undef TSAN_FLAG
47   // DDFlags
48   RegisterFlag(parser, "second_deadlock_stack",
49       "Report where each mutex is locked in deadlock reports",
50       &f->second_deadlock_stack);
51 }
52
53 void InitializeFlags(Flags *f, const char *env) {
54   SetCommonFlagsDefaults();
55   {
56     // Override some common flags defaults.
57     CommonFlags cf;
58     cf.CopyFrom(*common_flags());
59     cf.allow_addr2line = true;
60     if (SANITIZER_GO) {
61       // Does not work as expected for Go: runtime handles SIGABRT and crashes.
62       cf.abort_on_error = false;
63       // Go does not have mutexes.
64     } else {
65       cf.detect_deadlocks = true;
66     }
67     cf.print_suppressions = false;
68     cf.stack_trace_format = "    #%n %f %S %M";
69     cf.exitcode = 66;
70     cf.intercept_tls_get_addr = true;
71     OverrideCommonFlags(cf);
72   }
73
74   f->SetDefaults();
75
76   FlagParser parser;
77   RegisterTsanFlags(&parser, f);
78   RegisterCommonFlags(&parser);
79
80 #if TSAN_CONTAINS_UBSAN
81   __ubsan::Flags *uf = __ubsan::flags();
82   uf->SetDefaults();
83
84   FlagParser ubsan_parser;
85   __ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
86   RegisterCommonFlags(&ubsan_parser);
87 #endif
88
89   // Let a frontend override.
90   parser.ParseString(__tsan_default_options());
91 #if TSAN_CONTAINS_UBSAN
92   const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
93   ubsan_parser.ParseString(ubsan_default_options);
94 #endif
95   // Override from command line.
96   parser.ParseString(env);
97 #if TSAN_CONTAINS_UBSAN
98   ubsan_parser.ParseString(GetEnv("UBSAN_OPTIONS"));
99 #endif
100
101   // Sanity check.
102   if (!f->report_bugs) {
103     f->report_thread_leaks = false;
104     f->report_destroy_locked = false;
105     f->report_signal_unsafe = false;
106   }
107
108   InitializeCommonFlags();
109
110   if (Verbosity()) ReportUnrecognizedFlags();
111
112   if (common_flags()->help) parser.PrintFlagDescriptions();
113
114   if (f->history_size < 0 || f->history_size > 7) {
115     Printf("ThreadSanitizer: incorrect value for history_size"
116            " (must be [0..7])\n");
117     Die();
118   }
119
120   if (f->io_sync < 0 || f->io_sync > 2) {
121     Printf("ThreadSanitizer: incorrect value for io_sync"
122            " (must be [0..2])\n");
123     Die();
124   }
125 }
126
127 }  // namespace __tsan