]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/tsan/rtl/tsan_flags.cc
Update compiler-rt to 3.7.0 release. This also includes the sanitizer
[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 Flags *flags() {
25   return &ctx->flags;
26 }
27
28 // Can be overriden in frontend.
29 #ifdef TSAN_EXTERNAL_HOOKS
30 extern "C" const char* __tsan_default_options();
31 #else
32 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
33 const char *WEAK __tsan_default_options() {
34   return "";
35 }
36 #endif
37
38 void Flags::SetDefaults() {
39 #define TSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
40 #include "tsan_flags.inc"
41 #undef TSAN_FLAG
42   // DDFlags
43   second_deadlock_stack = false;
44 }
45
46 void RegisterTsanFlags(FlagParser *parser, Flags *f) {
47 #define TSAN_FLAG(Type, Name, DefaultValue, Description) \
48   RegisterFlag(parser, #Name, Description, &f->Name);
49 #include "tsan_flags.inc"
50 #undef TSAN_FLAG
51   // DDFlags
52   RegisterFlag(parser, "second_deadlock_stack",
53       "Report where each mutex is locked in deadlock reports",
54       &f->second_deadlock_stack);
55 }
56
57 void InitializeFlags(Flags *f, const char *env) {
58   SetCommonFlagsDefaults();
59   {
60     // Override some common flags defaults.
61     CommonFlags cf;
62     cf.CopyFrom(*common_flags());
63     cf.allow_addr2line = true;
64 #ifndef SANITIZER_GO
65     cf.detect_deadlocks = true;
66 #endif
67     cf.print_suppressions = false;
68     cf.stack_trace_format = "    #%n %f %S %M";
69     OverrideCommonFlags(cf);
70   }
71
72   f->SetDefaults();
73
74   FlagParser parser;
75   RegisterTsanFlags(&parser, f);
76   RegisterCommonFlags(&parser);
77
78 #if TSAN_CONTAINS_UBSAN
79   __ubsan::Flags *uf = __ubsan::flags();
80   uf->SetDefaults();
81
82   FlagParser ubsan_parser;
83   __ubsan::RegisterUbsanFlags(&ubsan_parser, uf);
84   RegisterCommonFlags(&ubsan_parser);
85 #endif
86
87   // Let a frontend override.
88   parser.ParseString(__tsan_default_options());
89 #if TSAN_CONTAINS_UBSAN
90   const char *ubsan_default_options = __ubsan::MaybeCallUbsanDefaultOptions();
91   ubsan_parser.ParseString(ubsan_default_options);
92 #endif
93   // Override from command line.
94   parser.ParseString(env);
95 #if TSAN_CONTAINS_UBSAN
96   ubsan_parser.ParseString(GetEnv("UBSAN_OPTIONS"));
97 #endif
98
99   // Sanity check.
100   if (!f->report_bugs) {
101     f->report_thread_leaks = false;
102     f->report_destroy_locked = false;
103     f->report_signal_unsafe = false;
104   }
105
106   SetVerbosity(common_flags()->verbosity);
107
108   if (Verbosity()) ReportUnrecognizedFlags();
109
110   if (common_flags()->help) parser.PrintFlagDescriptions();
111
112   if (f->history_size < 0 || f->history_size > 7) {
113     Printf("ThreadSanitizer: incorrect value for history_size"
114            " (must be [0..7])\n");
115     Die();
116   }
117
118   if (f->io_sync < 0 || f->io_sync > 2) {
119     Printf("ThreadSanitizer: incorrect value for io_sync"
120            " (must be [0..2])\n");
121     Die();
122   }
123 }
124
125 }  // namespace __tsan