Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / build / sanitizers / sanitizer_options.cc
blob33090fb94b792a69ac88d550ef396662ea898677
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.
8 #include "build/build_config.h"
10 #if defined(ADDRESS_SANITIZER) && defined(OS_MACOSX)
11 #include <crt_externs.h> // for _NSGetArgc, _NSGetArgv
12 #include <string.h>
13 #endif // ADDRESS_SANITIZER && OS_MACOSX
15 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
16 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER)
17 // Functions returning default options are declared weak in the tools' runtime
18 // libraries. To make the linker pick the strong replacements for those
19 // functions from this module, we explicitly force its inclusion by passing
20 // -Wl,-u_sanitizer_options_link_helper
21 extern "C"
22 void _sanitizer_options_link_helper() { }
24 // The callbacks we define here will be called from the sanitizer runtime, but
25 // aren't referenced from the Chrome executable. We must ensure that those
26 // callbacks are not sanitizer-instrumented, and that they aren't stripped by
27 // the linker.
28 #define SANITIZER_HOOK_ATTRIBUTE \
29 extern "C" \
30 __attribute__((no_sanitize_address)) \
31 __attribute__((no_sanitize_memory)) \
32 __attribute__((no_sanitize_thread)) \
33 __attribute__((visibility("default"))) \
34 __attribute__((used))
35 #endif
37 #if defined(ADDRESS_SANITIZER)
38 // Default options for AddressSanitizer in various configurations:
39 // strict_memcmp=1 - disable the strict memcmp() checking
40 // (http://crbug.com/178677 and http://crbug.com/178404).
41 // malloc_context_size=5 - limit the size of stack traces collected by ASan
42 // for each malloc/free by 5 frames. These stack traces tend to accumulate
43 // very fast in applications using JIT (v8 in Chrome's case), see
44 // https://code.google.com/p/address-sanitizer/issues/detail?id=177
45 // symbolize=false - disable the in-process symbolization, which isn't 100%
46 // compatible with the existing sandboxes and doesn't make much sense for
47 // stripped official binaries.
48 // legacy_pthread_cond=1 - run in the libpthread 2.2.5 compatibility mode to
49 // work around libGL.so using the obsolete API, see
50 // http://crbug.com/341805. This may break if pthread_cond_t objects are
51 // accessed by both instrumented and non-instrumented binaries (e.g. if
52 // they reside in shared memory). This option is going to be deprecated in
53 // upstream AddressSanitizer and must not be used anywhere except the
54 // official builds.
55 // replace_intrin=0 - do not intercept memcpy(), memmove() and memset() to
56 // work around http://crbug.com/162461 (ASan report in OpenCL on Mac).
57 // check_printf=1 - check the memory accesses to printf (and other formatted
58 // output routines) arguments.
59 // use_sigaltstack=1 - handle signals on an alternate signal stack. Useful
60 // for stack overflow detection.
61 // strip_path_prefix=Release/../../ - prefixes up to and including this
62 // substring will be stripped from source file paths in symbolized reports
63 // (if symbolize=true, which is set when running with LeakSanitizer).
64 // fast_unwind_on_fatal=1 - use the fast (frame-pointer-based) stack unwinder
65 // to print error reports. V8 doesn't generate debug info for the JIT code,
66 // so the slow unwinder may not work properly.
67 // detect_stack_use_after_return=1 - use fake stack to delay the reuse of
68 // stack allocations and detect stack-use-after-return errors.
69 // detect_container_overflow=0 - do not detect overflows in containers
70 // until crbug.com/459632 is fixed.
71 #if defined(OS_LINUX)
72 #if defined(GOOGLE_CHROME_BUILD)
73 // Default AddressSanitizer options for the official build. These do not affect
74 // tests on buildbots (which don't set GOOGLE_CHROME_BUILD) or non-official
75 // Chromium builds.
76 const char kAsanDefaultOptions[] =
77 "legacy_pthread_cond=1 malloc_context_size=5 strict_memcmp=0 "
78 "symbolize=false check_printf=1 use_sigaltstack=1 detect_leaks=0 "
79 "strip_path_prefix=Release/../../ fast_unwind_on_fatal=1 "
80 "detect_container_overflow=0 ";
81 #else
82 // Default AddressSanitizer options for buildbots and non-official builds.
83 const char *kAsanDefaultOptions =
84 "strict_memcmp=0 symbolize=false check_printf=1 use_sigaltstack=1 "
85 "detect_leaks=0 strip_path_prefix=Release/../../ fast_unwind_on_fatal=1 "
86 "detect_stack_use_after_return=1 detect_container_overflow=0 ";
87 #endif // GOOGLE_CHROME_BUILD
89 #elif defined(OS_MACOSX)
90 const char *kAsanDefaultOptions =
91 "strict_memcmp=0 replace_intrin=0 check_printf=1 use_sigaltstack=1 "
92 "strip_path_prefix=Release/../../ fast_unwind_on_fatal=1 "
93 "detect_stack_use_after_return=1 detect_odr_violation=0 "
94 "detect_container_overflow=0 ";
95 static const char kNaClDefaultOptions[] = "handle_segv=0";
96 static const char kNaClFlag[] = "--type=nacl-loader";
97 #endif // OS_LINUX
99 #if defined(OS_LINUX) || defined(OS_MACOSX)
100 SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_options() {
101 #if defined(OS_MACOSX)
102 char*** argvp = _NSGetArgv();
103 int* argcp = _NSGetArgc();
104 if (!argvp || !argcp) return kAsanDefaultOptions;
105 char** argv = *argvp;
106 int argc = *argcp;
107 for (int i = 0; i < argc; ++i) {
108 if (strcmp(argv[i], kNaClFlag) == 0) {
109 return kNaClDefaultOptions;
112 #endif
113 return kAsanDefaultOptions;
115 #endif // OS_LINUX || OS_MACOSX
116 #endif // ADDRESS_SANITIZER
118 #if defined(THREAD_SANITIZER) && defined(OS_LINUX)
119 // Default options for ThreadSanitizer in various configurations:
120 // detect_deadlocks=1 - enable deadlock (lock inversion) detection.
121 // second_deadlock_stack=1 - more verbose deadlock reports.
122 // report_signal_unsafe=0 - do not report async-signal-unsafe functions
123 // called from signal handlers.
124 // report_thread_leaks=0 - do not report unjoined threads at the end of
125 // the program execution.
126 // print_suppressions=1 - print the list of matched suppressions.
127 // history_size=7 - make the history buffer proportional to 2^7 (the maximum
128 // value) to keep more stack traces.
129 // strip_path_prefix=Release/../../ - prefixes up to and including this
130 // substring will be stripped from source file paths in symbolized reports.
131 const char kTsanDefaultOptions[] =
132 "detect_deadlocks=1 second_deadlock_stack=1 report_signal_unsafe=0 "
133 "report_thread_leaks=0 print_suppressions=1 history_size=7 "
134 "strip_path_prefix=Release/../../ ";
136 SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_options() {
137 return kTsanDefaultOptions;
140 extern "C" char kTSanDefaultSuppressions[];
142 SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_suppressions() {
143 return kTSanDefaultSuppressions;
146 #endif // THREAD_SANITIZER && OS_LINUX
148 #if defined(LEAK_SANITIZER)
149 // Default options for LeakSanitizer:
150 // print_suppressions=1 - print the list of matched suppressions.
151 // strip_path_prefix=Release/../../ - prefixes up to and including this
152 // substring will be stripped from source file paths in symbolized reports.
153 const char kLsanDefaultOptions[] =
154 "print_suppressions=1 strip_path_prefix=Release/../../ ";
156 SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_options() {
157 return kLsanDefaultOptions;
160 extern "C" char kLSanDefaultSuppressions[];
162 SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_suppressions() {
163 return kLSanDefaultSuppressions;
166 #endif // LEAK_SANITIZER