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 // 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() { } |
| 23 |
| 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 |
| 36 |
| 37 #if defined(ADDRESS_SANITIZER) |
| 38 // Default options for AddressSanitizer in various configurations: |
| 39 // malloc_context_size=5 - limit the size of stack traces collected by ASan |
| 40 // for each malloc/free by 5 frames. These stack traces tend to accumulate |
| 41 // very fast in applications using JIT (v8 in Chrome's case), see |
| 42 // https://code.google.com/p/address-sanitizer/issues/detail?id=177 |
| 43 // symbolize=false - disable the in-process symbolization, which isn't 100% |
| 44 // compatible with the existing sandboxes and doesn't make much sense for |
| 45 // stripped official binaries. |
| 46 // legacy_pthread_cond=1 - run in the libpthread 2.2.5 compatibility mode to |
| 47 // work around libGL.so using the obsolete API, see |
| 48 // http://crbug.com/341805. This may break if pthread_cond_t objects are |
| 49 // accessed by both instrumented and non-instrumented binaries (e.g. if |
| 50 // they reside in shared memory). This option is going to be deprecated in |
| 51 // upstream AddressSanitizer and must not be used anywhere except the |
| 52 // official builds. |
| 53 // check_printf=1 - check the memory accesses to printf (and other formatted |
| 54 // output routines) arguments. |
| 55 // use_sigaltstack=1 - handle signals on an alternate signal stack. Useful |
| 56 // for stack overflow detection. |
| 57 // strip_path_prefix=Release/../../ - prefixes up to and including this |
| 58 // substring will be stripped from source file paths in symbolized reports |
| 59 // (if symbolize=true, which is set when running with LeakSanitizer). |
| 60 // fast_unwind_on_fatal=1 - use the fast (frame-pointer-based) stack unwinder |
| 61 // to print error reports. V8 doesn't generate debug info for the JIT code, |
| 62 // so the slow unwinder may not work properly. |
| 63 // detect_stack_use_after_return=1 - use fake stack to delay the reuse of |
| 64 // stack allocations and detect stack-use-after-return errors. |
| 65 #if defined(OS_LINUX) |
| 66 #if defined(GOOGLE_CHROME_BUILD) |
| 67 // Default AddressSanitizer options for the official build. These do not affect |
| 68 // tests on buildbots (which don't set GOOGLE_CHROME_BUILD) or non-official |
| 69 // Chromium builds. |
| 70 const char kAsanDefaultOptions[] = |
| 71 "legacy_pthread_cond=1 malloc_context_size=5 " |
| 72 "symbolize=false check_printf=1 use_sigaltstack=1 detect_leaks=0 " |
| 73 "strip_path_prefix=Release/../../ fast_unwind_on_fatal=1"; |
| 74 #else |
| 75 // Default AddressSanitizer options for buildbots and non-official builds. |
| 76 const char *kAsanDefaultOptions = |
| 77 "symbolize=false check_printf=1 use_sigaltstack=1 " |
| 78 "detect_leaks=0 strip_path_prefix=Release/../../ fast_unwind_on_fatal=1 " |
| 79 "detect_stack_use_after_return=1 "; |
| 80 #endif // GOOGLE_CHROME_BUILD |
| 81 |
| 82 #elif defined(OS_MACOSX) |
| 83 const char *kAsanDefaultOptions = |
| 84 "check_printf=1 use_sigaltstack=1 " |
| 85 "strip_path_prefix=Release/../../ fast_unwind_on_fatal=1 " |
| 86 "detect_stack_use_after_return=1 detect_odr_violation=0 "; |
| 87 static const char kNaClDefaultOptions[] = "handle_segv=0"; |
| 88 static const char kNaClFlag[] = "--type=nacl-loader"; |
| 89 #endif // OS_LINUX |
| 90 |
| 91 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 92 SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_options() { |
| 93 #if defined(OS_MACOSX) |
| 94 char*** argvp = _NSGetArgv(); |
| 95 int* argcp = _NSGetArgc(); |
| 96 if (!argvp || !argcp) return kAsanDefaultOptions; |
| 97 char** argv = *argvp; |
| 98 int argc = *argcp; |
| 99 for (int i = 0; i < argc; ++i) { |
| 100 if (strcmp(argv[i], kNaClFlag) == 0) { |
| 101 return kNaClDefaultOptions; |
| 102 } |
| 103 } |
| 104 #endif |
| 105 return kAsanDefaultOptions; |
| 106 } |
| 107 |
| 108 extern "C" char kASanDefaultSuppressions[]; |
| 109 |
| 110 SANITIZER_HOOK_ATTRIBUTE const char *__asan_default_suppressions() { |
| 111 return kASanDefaultSuppressions; |
| 112 } |
| 113 #endif // OS_LINUX || OS_MACOSX |
| 114 #endif // ADDRESS_SANITIZER |
| 115 |
| 116 #if defined(THREAD_SANITIZER) && defined(OS_LINUX) |
| 117 // Default options for ThreadSanitizer in various configurations: |
| 118 // detect_deadlocks=1 - enable deadlock (lock inversion) detection. |
| 119 // second_deadlock_stack=1 - more verbose deadlock reports. |
| 120 // report_signal_unsafe=0 - do not report async-signal-unsafe functions |
| 121 // called from signal handlers. |
| 122 // report_thread_leaks=0 - do not report unjoined threads at the end of |
| 123 // the program execution. |
| 124 // print_suppressions=1 - print the list of matched suppressions. |
| 125 // history_size=7 - make the history buffer proportional to 2^7 (the maximum |
| 126 // value) to keep more stack traces. |
| 127 // strip_path_prefix=Release/../../ - prefixes up to and including this |
| 128 // substring will be stripped from source file paths in symbolized reports. |
| 129 const char kTsanDefaultOptions[] = |
| 130 "detect_deadlocks=1 second_deadlock_stack=1 report_signal_unsafe=0 " |
| 131 "report_thread_leaks=0 print_suppressions=1 history_size=7 " |
| 132 "strip_path_prefix=Release/../../ "; |
| 133 |
| 134 SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_options() { |
| 135 return kTsanDefaultOptions; |
| 136 } |
| 137 |
| 138 extern "C" char kTSanDefaultSuppressions[]; |
| 139 |
| 140 SANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_suppressions() { |
| 141 return kTSanDefaultSuppressions; |
| 142 } |
| 143 |
| 144 #endif // THREAD_SANITIZER && OS_LINUX |
| 145 |
| 146 #if defined(LEAK_SANITIZER) |
| 147 // Default options for LeakSanitizer: |
| 148 // print_suppressions=1 - print the list of matched suppressions. |
| 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 kLsanDefaultOptions[] = |
| 152 "print_suppressions=1 strip_path_prefix=Release/../../ "; |
| 153 |
| 154 SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_options() { |
| 155 return kLsanDefaultOptions; |
| 156 } |
| 157 |
| 158 extern "C" char kLSanDefaultSuppressions[]; |
| 159 |
| 160 SANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_suppressions() { |
| 161 return kLSanDefaultSuppressions; |
| 162 } |
| 163 |
| 164 #endif // LEAK_SANITIZER |
OLD | NEW |