• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // This file contains the default options for various compiler-based dynamic
6 // tools.
7 
8 
9 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) ||  \
10     defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
11     defined(UNDEFINED_SANITIZER)
12 // Functions returning default options are declared weak in the tools' runtime
13 // libraries. To make the linker pick the strong replacements for those
14 // functions from this module, we explicitly force its inclusion by passing
15 // -Wl,-u_sanitizer_options_link_helper
16 extern "C"
_sanitizer_options_link_helper()17 void _sanitizer_options_link_helper() { }
18 
19 // The callbacks we define here will be called from the sanitizer runtime, but
20 // aren't referenced from the Chrome executable. We must ensure that those
21 // callbacks are not sanitizer-instrumented, and that they aren't stripped by
22 // the linker.
23 #define SANITIZER_HOOK_ATTRIBUTE                                             \
24     extern "C"                                                               \
25     __attribute__((no_sanitize("address", "memory", "thread", "undefined"))) \
26     __attribute__((visibility("default")))                                   \
27     __attribute__((used))
28 #endif
29 
30 #if defined(ADDRESS_SANITIZER)
31 // Default options for AddressSanitizer in various configurations:
32 //   malloc_context_size=5 - limit the size of stack traces collected by ASan
33 //     for each malloc/free by 5 frames. These stack traces tend to accumulate
34 //     very fast in applications using JIT (v8 in Chrome's case), see
35 //     https://code.google.com/p/address-sanitizer/issues/detail?id=177
36 //   symbolize=1 - enable in-process symbolization.
37 //   legacy_pthread_cond=1 - run in the libpthread 2.2.5 compatibility mode to
38 //     work around libGL.so using the obsolete API, see
39 //     http://crbug.com/341805. This may break if pthread_cond_t objects are
40 //     accessed by both instrumented and non-instrumented binaries (e.g. if
41 //     they reside in shared memory). This option is going to be deprecated in
42 //     upstream AddressSanitizer and must not be used anywhere except the
43 //     official builds.
44 //   check_printf=1 - check the memory accesses to printf (and other formatted
45 //     output routines) arguments.
46 //   use_sigaltstack=1 - handle signals on an alternate signal stack. Useful
47 //     for stack overflow detection.
48 //   strip_path_prefix=/../../ - prefixes up to and including this
49 //     substring will be stripped from source file paths in symbolized reports
50 //   fast_unwind_on_fatal=1 - use the fast (frame-pointer-based) stack unwinder
51 //     to print error reports. V8 doesn't generate debug info for the JIT code,
52 //     so the slow unwinder may not work properly.
53 //   detect_stack_use_after_return=1 - use fake stack to delay the reuse of
54 //     stack allocations and detect stack-use-after-return errors.
55 #if defined(OS_LINUX)
56 #if defined(GOOGLE_CHROME_BUILD)
57 // Default AddressSanitizer options for the official build. These do not affect
58 // tests on buildbots (which don't set GOOGLE_CHROME_BUILD) or non-official
59 // Chromium builds.
60 const char kAsanDefaultOptions[] =
61     "legacy_pthread_cond=1 malloc_context_size=5 "
62     "symbolize=1 check_printf=1 use_sigaltstack=1 detect_leaks=0 "
63     "strip_path_prefix=/../../ fast_unwind_on_fatal=1 "
64     "allow_user_segv_handler=1 ";
65 #else
66 // Default AddressSanitizer options for buildbots and non-official builds.
67 const char* kAsanDefaultOptions =
68     "symbolize=1 check_printf=1 use_sigaltstack=1 "
69     "detect_leaks=0 strip_path_prefix=/../../ fast_unwind_on_fatal=1 "
70     "detect_stack_use_after_return=1 "
71     "allow_user_segv_handler=1 ";
72 #endif  // GOOGLE_CHROME_BUILD
73 
74 #elif defined(OS_MACOSX)
75 const char *kAsanDefaultOptions =
76     "check_printf=1 use_sigaltstack=1 "
77     "strip_path_prefix=/../../ fast_unwind_on_fatal=1 "
78     "detect_stack_use_after_return=1 detect_odr_violation=0 ";
79 #endif  // OS_LINUX
80 
81 #if defined(OS_LINUX) || defined(OS_MACOSX)
82 // Allow NaCl to override the default asan options.
83 extern const char* kAsanDefaultOptionsNaCl;
84 __attribute__((weak)) const char* kAsanDefaultOptionsNaCl = nullptr;
85 
__asan_default_options()86 SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_options() {
87     if (kAsanDefaultOptionsNaCl)
88         return kAsanDefaultOptionsNaCl;
89     return kAsanDefaultOptions;
90 }
91 
92 extern char kASanDefaultSuppressions[];
93 
__asan_default_suppressions()94 SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_suppressions() {
95     return kASanDefaultSuppressions;
96 }
97 #endif  // OS_LINUX || OS_MACOSX
98 #endif  // ADDRESS_SANITIZER
99 
100 #if defined(THREAD_SANITIZER) && defined(OS_LINUX)
101 // Default options for ThreadSanitizer in various configurations:
102 //   detect_deadlocks=1 - enable deadlock (lock inversion) detection.
103 //   second_deadlock_stack=1 - more verbose deadlock reports.
104 //   report_signal_unsafe=0 - do not report async-signal-unsafe functions
105 //     called from signal handlers.
106 //   report_thread_leaks=0 - do not report unjoined threads at the end of
107 //     the program execution.
108 //   print_suppressions=1 - print the list of matched suppressions.
109 //   history_size=7 - make the history buffer proportional to 2^7 (the maximum
110 //     value) to keep more stack traces.
111 //   strip_path_prefix=/../../ - prefixes up to and including this
112 //     substring will be stripped from source file paths in symbolized reports.
113 const char kTsanDefaultOptions[] =
114     "detect_deadlocks=1 second_deadlock_stack=1 report_signal_unsafe=0 "
115     "report_thread_leaks=0 print_suppressions=1 history_size=7 "
116     "strict_memcmp=0 strip_path_prefix=/../../ ";
117 
__tsan_default_options()118 SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_options() {
119     return kTsanDefaultOptions;
120 }
121 
122 extern char kTSanDefaultSuppressions[];
123 
__tsan_default_suppressions()124 SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_suppressions() {
125     return kTSanDefaultSuppressions;
126 }
127 
128 #endif  // THREAD_SANITIZER && OS_LINUX
129 
130 #if defined(MEMORY_SANITIZER)
131 // Default options for MemorySanitizer:
132 //   intercept_memcmp=0 - do not detect uninitialized memory in memcmp() calls.
133 //     Pending cleanup, see http://crbug.com/523428
134 //   strip_path_prefix=/../../ - prefixes up to and including this
135 //     substring will be stripped from source file paths in symbolized reports.
136 const char kMsanDefaultOptions[] =
137     "intercept_memcmp=0 strip_path_prefix=/../../ ";
138 
__msan_default_options()139 SANITIZER_HOOK_ATTRIBUTE const char *__msan_default_options() {
140     return kMsanDefaultOptions;
141 }
142 
143 #endif  // MEMORY_SANITIZER
144 
145 #if defined(LEAK_SANITIZER)
146 // Default options for LeakSanitizer:
147 //   print_suppressions=1 - print the list of matched suppressions.
148 //   strip_path_prefix=/../../ - prefixes up to and including this
149 //     substring will be stripped from source file paths in symbolized reports.
150 const char kLsanDefaultOptions[] =
151     "print_suppressions=1 strip_path_prefix=/../../ ";
152 
__lsan_default_options()153 SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_options() {
154     return kLsanDefaultOptions;
155 }
156 
157 extern char kLSanDefaultSuppressions[];
158 
__lsan_default_suppressions()159 SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_suppressions() {
160     return kLSanDefaultSuppressions;
161 }
162 
163 #endif  // LEAK_SANITIZER
164 
165 #if defined(UNDEFINED_SANITIZER)
166 // Default options for UndefinedBehaviorSanitizer:
167 //   print_stacktrace=1 - print the stacktrace when UBSan reports an error.
168 const char kUbsanDefaultOptions[] =
169     "print_stacktrace=1 strip_path_prefix=/../../ ";
170 
__ubsan_default_options()171 SANITIZER_HOOK_ATTRIBUTE const char* __ubsan_default_options() {
172     return kUbsanDefaultOptions;
173 }
174 
175 #endif  // UNDEFINED_SANITIZER
176