1*8975f5c5SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors
2*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
4*8975f5c5SAndroid Build Coastguard Worker //
5*8975f5c5SAndroid Build Coastguard Worker // This file contains the default options for various compiler-based dynamic
6*8975f5c5SAndroid Build Coastguard Worker // tools.
7*8975f5c5SAndroid Build Coastguard Worker
8*8975f5c5SAndroid Build Coastguard Worker #include "build/build_config.h"
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
11*8975f5c5SAndroid Build Coastguard Worker defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
12*8975f5c5SAndroid Build Coastguard Worker defined(UNDEFINED_SANITIZER)
13*8975f5c5SAndroid Build Coastguard Worker // The callbacks we define here will be called from the sanitizer runtime, but
14*8975f5c5SAndroid Build Coastguard Worker // aren't referenced from the Chrome executable. We must ensure that those
15*8975f5c5SAndroid Build Coastguard Worker // callbacks are not sanitizer-instrumented, and that they aren't stripped by
16*8975f5c5SAndroid Build Coastguard Worker // the linker.
17*8975f5c5SAndroid Build Coastguard Worker #define SANITIZER_HOOK_ATTRIBUTE \
18*8975f5c5SAndroid Build Coastguard Worker extern "C" \
19*8975f5c5SAndroid Build Coastguard Worker __attribute__((no_sanitize("address", "memory", "thread", "undefined"))) \
20*8975f5c5SAndroid Build Coastguard Worker __attribute__((visibility("default"))) \
21*8975f5c5SAndroid Build Coastguard Worker __attribute__((used))
22*8975f5c5SAndroid Build Coastguard Worker
23*8975f5c5SAndroid Build Coastguard Worker // Functions returning default options are declared weak in the tools' runtime
24*8975f5c5SAndroid Build Coastguard Worker // libraries. To make the linker pick the strong replacements for those
25*8975f5c5SAndroid Build Coastguard Worker // functions from this module, we explicitly force its inclusion by passing
26*8975f5c5SAndroid Build Coastguard Worker // -Wl,-u_sanitizer_options_link_helper
27*8975f5c5SAndroid Build Coastguard Worker // SANITIZER_HOOK_ATTRIBUTE instead of just `extern "C"` solely to make the
28*8975f5c5SAndroid Build Coastguard Worker // symbol externally visible, for ToolsSanityTest.LinksSanitizerOptions.
_sanitizer_options_link_helper()29*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE void _sanitizer_options_link_helper() {}
30*8975f5c5SAndroid Build Coastguard Worker #endif
31*8975f5c5SAndroid Build Coastguard Worker
32*8975f5c5SAndroid Build Coastguard Worker #if defined(ADDRESS_SANITIZER)
33*8975f5c5SAndroid Build Coastguard Worker // Default options for AddressSanitizer in various configurations:
34*8975f5c5SAndroid Build Coastguard Worker // strip_path_prefix=/../../ - prefixes up to and including this
35*8975f5c5SAndroid Build Coastguard Worker // substring will be stripped from source file paths in symbolized reports
36*8975f5c5SAndroid Build Coastguard Worker // fast_unwind_on_fatal=1 - use the fast (frame-pointer-based) stack unwinder
37*8975f5c5SAndroid Build Coastguard Worker // to print error reports. V8 doesn't generate debug info for the JIT code,
38*8975f5c5SAndroid Build Coastguard Worker // so the slow unwinder may not work properly.
39*8975f5c5SAndroid Build Coastguard Worker // detect_stack_use_after_return=1 - use fake stack to delay the reuse of
40*8975f5c5SAndroid Build Coastguard Worker // stack allocations and detect stack-use-after-return errors.
41*8975f5c5SAndroid Build Coastguard Worker // symbolize=1 - enable in-process symbolization.
42*8975f5c5SAndroid Build Coastguard Worker // external_symbolizer_path=... - provides the path to llvm-symbolizer
43*8975f5c5SAndroid Build Coastguard Worker // relative to the main executable
44*8975f5c5SAndroid Build Coastguard Worker #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) | BUILDFLAG(IS_APPLE)
45*8975f5c5SAndroid Build Coastguard Worker const char kAsanDefaultOptions[] =
46*8975f5c5SAndroid Build Coastguard Worker "strip_path_prefix=/../../ fast_unwind_on_fatal=1 "
47*8975f5c5SAndroid Build Coastguard Worker "detect_stack_use_after_return=1 symbolize=1 detect_leaks=0 "
48*8975f5c5SAndroid Build Coastguard Worker "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
49*8975f5c5SAndroid Build Coastguard Worker "bin/llvm-symbolizer";
50*8975f5c5SAndroid Build Coastguard Worker #elif BUILDFLAG(IS_WIN)
51*8975f5c5SAndroid Build Coastguard Worker const char* kAsanDefaultOptions =
52*8975f5c5SAndroid Build Coastguard Worker "strip_path_prefix=\\..\\..\\ fast_unwind_on_fatal=1 "
53*8975f5c5SAndroid Build Coastguard Worker "detect_stack_use_after_return=1 symbolize=1 "
54*8975f5c5SAndroid Build Coastguard Worker "external_symbolizer_path=%d/../../third_party/"
55*8975f5c5SAndroid Build Coastguard Worker "llvm-build/Release+Asserts/bin/llvm-symbolizer.exe";
56*8975f5c5SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_APPLE)
57*8975f5c5SAndroid Build Coastguard Worker
58*8975f5c5SAndroid Build Coastguard Worker #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_APPLE) || \
59*8975f5c5SAndroid Build Coastguard Worker BUILDFLAG(IS_WIN)
60*8975f5c5SAndroid Build Coastguard Worker // Allow NaCl to override the default asan options.
61*8975f5c5SAndroid Build Coastguard Worker extern const char* kAsanDefaultOptionsNaCl;
62*8975f5c5SAndroid Build Coastguard Worker __attribute__((weak)) const char* kAsanDefaultOptionsNaCl = nullptr;
63*8975f5c5SAndroid Build Coastguard Worker
__asan_default_options()64*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_options() {
65*8975f5c5SAndroid Build Coastguard Worker if (kAsanDefaultOptionsNaCl)
66*8975f5c5SAndroid Build Coastguard Worker return kAsanDefaultOptionsNaCl;
67*8975f5c5SAndroid Build Coastguard Worker return kAsanDefaultOptions;
68*8975f5c5SAndroid Build Coastguard Worker }
69*8975f5c5SAndroid Build Coastguard Worker
70*8975f5c5SAndroid Build Coastguard Worker extern char kASanDefaultSuppressions[];
71*8975f5c5SAndroid Build Coastguard Worker
__asan_default_suppressions()72*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_suppressions() {
73*8975f5c5SAndroid Build Coastguard Worker return kASanDefaultSuppressions;
74*8975f5c5SAndroid Build Coastguard Worker }
75*8975f5c5SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_APPLE)
76*8975f5c5SAndroid Build Coastguard Worker // || BUILDFLAG(IS_WIN)
77*8975f5c5SAndroid Build Coastguard Worker #endif // ADDRESS_SANITIZER
78*8975f5c5SAndroid Build Coastguard Worker
79*8975f5c5SAndroid Build Coastguard Worker #if defined(THREAD_SANITIZER) && (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
80*8975f5c5SAndroid Build Coastguard Worker // Default options for ThreadSanitizer in various configurations:
81*8975f5c5SAndroid Build Coastguard Worker // second_deadlock_stack=1 - more verbose deadlock reports.
82*8975f5c5SAndroid Build Coastguard Worker // report_signal_unsafe=0 - do not report async-signal-unsafe functions
83*8975f5c5SAndroid Build Coastguard Worker // called from signal handlers.
84*8975f5c5SAndroid Build Coastguard Worker // report_thread_leaks=0 - do not report unjoined threads at the end of
85*8975f5c5SAndroid Build Coastguard Worker // the program execution.
86*8975f5c5SAndroid Build Coastguard Worker // print_suppressions=1 - print the list of matched suppressions.
87*8975f5c5SAndroid Build Coastguard Worker // history_size=7 - make the history buffer proportional to 2^7 (the maximum
88*8975f5c5SAndroid Build Coastguard Worker // value) to keep more stack traces.
89*8975f5c5SAndroid Build Coastguard Worker // strip_path_prefix=/../../ - prefixes up to and including this
90*8975f5c5SAndroid Build Coastguard Worker // substring will be stripped from source file paths in symbolized reports.
91*8975f5c5SAndroid Build Coastguard Worker // external_symbolizer_path=... - provides the path to llvm-symbolizer
92*8975f5c5SAndroid Build Coastguard Worker // relative to the main executable
93*8975f5c5SAndroid Build Coastguard Worker const char kTsanDefaultOptions[] =
94*8975f5c5SAndroid Build Coastguard Worker "second_deadlock_stack=1 report_signal_unsafe=0 "
95*8975f5c5SAndroid Build Coastguard Worker "report_thread_leaks=0 print_suppressions=1 history_size=7 "
96*8975f5c5SAndroid Build Coastguard Worker "strip_path_prefix=/../../ external_symbolizer_path=%d/../../third_party/"
97*8975f5c5SAndroid Build Coastguard Worker "llvm-build/Release+Asserts/bin/llvm-symbolizer";
98*8975f5c5SAndroid Build Coastguard Worker
__tsan_default_options()99*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_options() {
100*8975f5c5SAndroid Build Coastguard Worker return kTsanDefaultOptions;
101*8975f5c5SAndroid Build Coastguard Worker }
102*8975f5c5SAndroid Build Coastguard Worker
103*8975f5c5SAndroid Build Coastguard Worker extern char kTSanDefaultSuppressions[];
104*8975f5c5SAndroid Build Coastguard Worker
__tsan_default_suppressions()105*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_suppressions() {
106*8975f5c5SAndroid Build Coastguard Worker return kTSanDefaultSuppressions;
107*8975f5c5SAndroid Build Coastguard Worker }
108*8975f5c5SAndroid Build Coastguard Worker
109*8975f5c5SAndroid Build Coastguard Worker #endif // defined(THREAD_SANITIZER) && (BUILDFLAG(IS_LINUX) ||
110*8975f5c5SAndroid Build Coastguard Worker // BUILDFLAG(IS_CHROMEOS))
111*8975f5c5SAndroid Build Coastguard Worker
112*8975f5c5SAndroid Build Coastguard Worker #if defined(MEMORY_SANITIZER)
113*8975f5c5SAndroid Build Coastguard Worker // Default options for MemorySanitizer:
114*8975f5c5SAndroid Build Coastguard Worker // strip_path_prefix=/../../ - prefixes up to and including this
115*8975f5c5SAndroid Build Coastguard Worker // substring will be stripped from source file paths in symbolized reports.
116*8975f5c5SAndroid Build Coastguard Worker // external_symbolizer_path=... - provides the path to llvm-symbolizer
117*8975f5c5SAndroid Build Coastguard Worker // relative to the main executable
118*8975f5c5SAndroid Build Coastguard Worker const char kMsanDefaultOptions[] =
119*8975f5c5SAndroid Build Coastguard Worker "strip_path_prefix=/../../ "
120*8975f5c5SAndroid Build Coastguard Worker "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
121*8975f5c5SAndroid Build Coastguard Worker "bin/llvm-symbolizer";
122*8975f5c5SAndroid Build Coastguard Worker
__msan_default_options()123*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char *__msan_default_options() {
124*8975f5c5SAndroid Build Coastguard Worker return kMsanDefaultOptions;
125*8975f5c5SAndroid Build Coastguard Worker }
126*8975f5c5SAndroid Build Coastguard Worker
127*8975f5c5SAndroid Build Coastguard Worker #endif // MEMORY_SANITIZER
128*8975f5c5SAndroid Build Coastguard Worker
129*8975f5c5SAndroid Build Coastguard Worker #if defined(LEAK_SANITIZER)
130*8975f5c5SAndroid Build Coastguard Worker // Default options for LeakSanitizer:
131*8975f5c5SAndroid Build Coastguard Worker // strip_path_prefix=/../../ - prefixes up to and including this
132*8975f5c5SAndroid Build Coastguard Worker // substring will be stripped from source file paths in symbolized reports.
133*8975f5c5SAndroid Build Coastguard Worker // external_symbolizer_path=... - provides the path to llvm-symbolizer
134*8975f5c5SAndroid Build Coastguard Worker // relative to the main executable
135*8975f5c5SAndroid Build Coastguard Worker // use_poisoned=1 - Scan poisoned memory. This is useful for Oilpan (C++
136*8975f5c5SAndroid Build Coastguard Worker // garbage collection) which wants to exclude its managed memory from being
137*8975f5c5SAndroid Build Coastguard Worker // reported as leaks (through root regions) and also temporarily poisons
138*8975f5c5SAndroid Build Coastguard Worker // memory regions before calling destructors of objects to avoid destructors
139*8975f5c5SAndroid Build Coastguard Worker // cross-referencing memory in other objects. Main thread termination in
140*8975f5c5SAndroid Build Coastguard Worker // Blink is not graceful and leak checks may be emitted at any time, which
141*8975f5c5SAndroid Build Coastguard Worker // means that the garbage collector may be in a state with poisoned memory,
142*8975f5c5SAndroid Build Coastguard Worker // leading to false-positive reports.
143*8975f5c5SAndroid Build Coastguard Worker const char kLsanDefaultOptions[] =
144*8975f5c5SAndroid Build Coastguard Worker "strip_path_prefix=/../../ use_poisoned=1 "
145*8975f5c5SAndroid Build Coastguard Worker
146*8975f5c5SAndroid Build Coastguard Worker #if !BUILDFLAG(IS_FUCHSIA)
147*8975f5c5SAndroid Build Coastguard Worker "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
148*8975f5c5SAndroid Build Coastguard Worker "bin/llvm-symbolizer "
149*8975f5c5SAndroid Build Coastguard Worker #endif
150*8975f5c5SAndroid Build Coastguard Worker
151*8975f5c5SAndroid Build Coastguard Worker #if defined(ARCH_CPU_64_BITS)
152*8975f5c5SAndroid Build Coastguard Worker // When pointer compression in V8 is enabled the external pointers in the
153*8975f5c5SAndroid Build Coastguard Worker // heap are guaranteed to be only 4 bytes aligned. So we need this option
154*8975f5c5SAndroid Build Coastguard Worker // in order to ensure that LSAN will find all the external pointers.
155*8975f5c5SAndroid Build Coastguard Worker // TODO(crbug.com/40344974): see updates from 2019.
156*8975f5c5SAndroid Build Coastguard Worker "use_unaligned=1 "
157*8975f5c5SAndroid Build Coastguard Worker #endif // ARCH_CPU_64_BITS
158*8975f5c5SAndroid Build Coastguard Worker ;
159*8975f5c5SAndroid Build Coastguard Worker
__lsan_default_options()160*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_options() {
161*8975f5c5SAndroid Build Coastguard Worker return kLsanDefaultOptions;
162*8975f5c5SAndroid Build Coastguard Worker }
163*8975f5c5SAndroid Build Coastguard Worker
164*8975f5c5SAndroid Build Coastguard Worker // TODO(https://fxbug.dev/102967): Remove when Fuchsia supports
165*8975f5c5SAndroid Build Coastguard Worker // module-name-based and function-name-based suppression.
166*8975f5c5SAndroid Build Coastguard Worker #if !BUILDFLAG(IS_FUCHSIA)
167*8975f5c5SAndroid Build Coastguard Worker
168*8975f5c5SAndroid Build Coastguard Worker extern char kLSanDefaultSuppressions[];
169*8975f5c5SAndroid Build Coastguard Worker
__lsan_default_suppressions()170*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_suppressions() {
171*8975f5c5SAndroid Build Coastguard Worker return kLSanDefaultSuppressions;
172*8975f5c5SAndroid Build Coastguard Worker }
173*8975f5c5SAndroid Build Coastguard Worker
174*8975f5c5SAndroid Build Coastguard Worker #endif // !BUILDFLAG(IS_FUCHSIA)
175*8975f5c5SAndroid Build Coastguard Worker #endif // LEAK_SANITIZER
176*8975f5c5SAndroid Build Coastguard Worker
177*8975f5c5SAndroid Build Coastguard Worker #if defined(UNDEFINED_SANITIZER)
178*8975f5c5SAndroid Build Coastguard Worker // Default options for UndefinedBehaviorSanitizer:
179*8975f5c5SAndroid Build Coastguard Worker // print_stacktrace=1 - print the stacktrace when UBSan reports an error.
180*8975f5c5SAndroid Build Coastguard Worker const char kUbsanDefaultOptions[] =
181*8975f5c5SAndroid Build Coastguard Worker "print_stacktrace=1 strip_path_prefix=/../../ "
182*8975f5c5SAndroid Build Coastguard Worker "external_symbolizer_path=%d/../../third_party/llvm-build/Release+Asserts/"
183*8975f5c5SAndroid Build Coastguard Worker "bin/llvm-symbolizer";
184*8975f5c5SAndroid Build Coastguard Worker
__ubsan_default_options()185*8975f5c5SAndroid Build Coastguard Worker SANITIZER_HOOK_ATTRIBUTE const char* __ubsan_default_options() {
186*8975f5c5SAndroid Build Coastguard Worker return kUbsanDefaultOptions;
187*8975f5c5SAndroid Build Coastguard Worker }
188*8975f5c5SAndroid Build Coastguard Worker
189*8975f5c5SAndroid Build Coastguard Worker #endif // UNDEFINED_SANITIZER
190