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