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