15f9996aaSopenharmony_ci// Copyright 2014 The Chromium Authors. All rights reserved. 25f9996aaSopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 35f9996aaSopenharmony_ci// found in the LICENSE file. 45f9996aaSopenharmony_ci// 55f9996aaSopenharmony_ci// This file contains the default options for various compiler-based dynamic 65f9996aaSopenharmony_ci// tools. 75f9996aaSopenharmony_ci 85f9996aaSopenharmony_ci 95f9996aaSopenharmony_ci#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ 105f9996aaSopenharmony_ci defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ 115f9996aaSopenharmony_ci defined(UNDEFINED_SANITIZER) 125f9996aaSopenharmony_ci// Functions returning default options are declared weak in the tools' runtime 135f9996aaSopenharmony_ci// libraries. To make the linker pick the strong replacements for those 145f9996aaSopenharmony_ci// functions from this module, we explicitly force its inclusion by passing 155f9996aaSopenharmony_ci// -Wl,-u_sanitizer_options_link_helper 165f9996aaSopenharmony_ciextern "C" 175f9996aaSopenharmony_civoid _sanitizer_options_link_helper() { } 185f9996aaSopenharmony_ci 195f9996aaSopenharmony_ci// The callbacks we define here will be called from the sanitizer runtime, but 205f9996aaSopenharmony_ci// aren't referenced from the Chrome executable. We must ensure that those 215f9996aaSopenharmony_ci// callbacks are not sanitizer-instrumented, and that they aren't stripped by 225f9996aaSopenharmony_ci// the linker. 235f9996aaSopenharmony_ci#define SANITIZER_HOOK_ATTRIBUTE \ 245f9996aaSopenharmony_ci extern "C" \ 255f9996aaSopenharmony_ci __attribute__((no_sanitize("address", "memory", "thread", "undefined"))) \ 265f9996aaSopenharmony_ci __attribute__((visibility("default"))) \ 275f9996aaSopenharmony_ci __attribute__((used)) 285f9996aaSopenharmony_ci#endif 295f9996aaSopenharmony_ci 305f9996aaSopenharmony_ci#if defined(ADDRESS_SANITIZER) 315f9996aaSopenharmony_ci// Default options for AddressSanitizer in various configurations: 325f9996aaSopenharmony_ci// malloc_context_size=5 - limit the size of stack traces collected by ASan 335f9996aaSopenharmony_ci// for each malloc/free by 5 frames. These stack traces tend to accumulate 345f9996aaSopenharmony_ci// very fast in applications using JIT (v8 in Chrome's case), see 355f9996aaSopenharmony_ci// https://code.google.com/p/address-sanitizer/issues/detail?id=177 365f9996aaSopenharmony_ci// symbolize=1 - enable in-process symbolization. 375f9996aaSopenharmony_ci// legacy_pthread_cond=1 - run in the libpthread 2.2.5 compatibility mode to 385f9996aaSopenharmony_ci// work around libGL.so using the obsolete API, see 395f9996aaSopenharmony_ci// http://crbug.com/341805. This may break if pthread_cond_t objects are 405f9996aaSopenharmony_ci// accessed by both instrumented and non-instrumented binaries (e.g. if 415f9996aaSopenharmony_ci// they reside in shared memory). This option is going to be deprecated in 425f9996aaSopenharmony_ci// upstream AddressSanitizer and must not be used anywhere except the 435f9996aaSopenharmony_ci// official builds. 445f9996aaSopenharmony_ci// check_printf=1 - check the memory accesses to printf (and other formatted 455f9996aaSopenharmony_ci// output routines) arguments. 465f9996aaSopenharmony_ci// use_sigaltstack=1 - handle signals on an alternate signal stack. Useful 475f9996aaSopenharmony_ci// for stack overflow detection. 485f9996aaSopenharmony_ci// strip_path_prefix=/../../ - prefixes up to and including this 495f9996aaSopenharmony_ci// substring will be stripped from source file paths in symbolized reports 505f9996aaSopenharmony_ci// fast_unwind_on_fatal=1 - use the fast (frame-pointer-based) stack unwinder 515f9996aaSopenharmony_ci// to print error reports. V8 doesn't generate debug info for the JIT code, 525f9996aaSopenharmony_ci// so the slow unwinder may not work properly. 535f9996aaSopenharmony_ci// detect_stack_use_after_return=1 - use fake stack to delay the reuse of 545f9996aaSopenharmony_ci// stack allocations and detect stack-use-after-return errors. 555f9996aaSopenharmony_ci#if defined(OS_LINUX) 565f9996aaSopenharmony_ci#if defined(GOOGLE_CHROME_BUILD) 575f9996aaSopenharmony_ci// Default AddressSanitizer options for the official build. These do not affect 585f9996aaSopenharmony_ci// tests on buildbots (which don't set GOOGLE_CHROME_BUILD) or non-official 595f9996aaSopenharmony_ci// Chromium builds. 605f9996aaSopenharmony_ciconst char kAsanDefaultOptions[] = 615f9996aaSopenharmony_ci "legacy_pthread_cond=1 malloc_context_size=5 " 625f9996aaSopenharmony_ci "symbolize=1 check_printf=1 use_sigaltstack=1 detect_leaks=0 " 635f9996aaSopenharmony_ci "strip_path_prefix=/../../ fast_unwind_on_fatal=1 " 645f9996aaSopenharmony_ci "allow_user_segv_handler=1 "; 655f9996aaSopenharmony_ci#else 665f9996aaSopenharmony_ci// Default AddressSanitizer options for buildbots and non-official builds. 675f9996aaSopenharmony_ciconst char* kAsanDefaultOptions = 685f9996aaSopenharmony_ci "symbolize=1 check_printf=1 use_sigaltstack=1 " 695f9996aaSopenharmony_ci "detect_leaks=0 strip_path_prefix=/../../ fast_unwind_on_fatal=1 " 705f9996aaSopenharmony_ci "detect_stack_use_after_return=1 " 715f9996aaSopenharmony_ci "allow_user_segv_handler=1 "; 725f9996aaSopenharmony_ci#endif // GOOGLE_CHROME_BUILD 735f9996aaSopenharmony_ci 745f9996aaSopenharmony_ci#elif defined(OS_MACOSX) 755f9996aaSopenharmony_ciconst char *kAsanDefaultOptions = 765f9996aaSopenharmony_ci "check_printf=1 use_sigaltstack=1 " 775f9996aaSopenharmony_ci "strip_path_prefix=/../../ fast_unwind_on_fatal=1 " 785f9996aaSopenharmony_ci "detect_stack_use_after_return=1 detect_odr_violation=0 "; 795f9996aaSopenharmony_ci#endif // OS_LINUX 805f9996aaSopenharmony_ci 815f9996aaSopenharmony_ci#if defined(OS_LINUX) || defined(OS_MACOSX) 825f9996aaSopenharmony_ci// Allow NaCl to override the default asan options. 835f9996aaSopenharmony_ciextern const char* kAsanDefaultOptionsNaCl; 845f9996aaSopenharmony_ci__attribute__((weak)) const char* kAsanDefaultOptionsNaCl = nullptr; 855f9996aaSopenharmony_ci 865f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char *__asan_default_options() { 875f9996aaSopenharmony_ci if (kAsanDefaultOptionsNaCl) 885f9996aaSopenharmony_ci return kAsanDefaultOptionsNaCl; 895f9996aaSopenharmony_ci return kAsanDefaultOptions; 905f9996aaSopenharmony_ci} 915f9996aaSopenharmony_ci 925f9996aaSopenharmony_ciextern char kASanDefaultSuppressions[]; 935f9996aaSopenharmony_ci 945f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char *__asan_default_suppressions() { 955f9996aaSopenharmony_ci return kASanDefaultSuppressions; 965f9996aaSopenharmony_ci} 975f9996aaSopenharmony_ci#endif // OS_LINUX || OS_MACOSX 985f9996aaSopenharmony_ci#endif // ADDRESS_SANITIZER 995f9996aaSopenharmony_ci 1005f9996aaSopenharmony_ci#if defined(THREAD_SANITIZER) && defined(OS_LINUX) 1015f9996aaSopenharmony_ci// Default options for ThreadSanitizer in various configurations: 1025f9996aaSopenharmony_ci// detect_deadlocks=1 - enable deadlock (lock inversion) detection. 1035f9996aaSopenharmony_ci// second_deadlock_stack=1 - more verbose deadlock reports. 1045f9996aaSopenharmony_ci// report_signal_unsafe=0 - do not report async-signal-unsafe functions 1055f9996aaSopenharmony_ci// called from signal handlers. 1065f9996aaSopenharmony_ci// report_thread_leaks=0 - do not report unjoined threads at the end of 1075f9996aaSopenharmony_ci// the program execution. 1085f9996aaSopenharmony_ci// print_suppressions=1 - print the list of matched suppressions. 1095f9996aaSopenharmony_ci// history_size=7 - make the history buffer proportional to 2^7 (the maximum 1105f9996aaSopenharmony_ci// value) to keep more stack traces. 1115f9996aaSopenharmony_ci// strip_path_prefix=/../../ - prefixes up to and including this 1125f9996aaSopenharmony_ci// substring will be stripped from source file paths in symbolized reports. 1135f9996aaSopenharmony_ciconst char kTsanDefaultOptions[] = 1145f9996aaSopenharmony_ci "detect_deadlocks=1 second_deadlock_stack=1 report_signal_unsafe=0 " 1155f9996aaSopenharmony_ci "report_thread_leaks=0 print_suppressions=1 history_size=7 " 1165f9996aaSopenharmony_ci "strict_memcmp=0 strip_path_prefix=/../../ "; 1175f9996aaSopenharmony_ci 1185f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_options() { 1195f9996aaSopenharmony_ci return kTsanDefaultOptions; 1205f9996aaSopenharmony_ci} 1215f9996aaSopenharmony_ci 1225f9996aaSopenharmony_ciextern char kTSanDefaultSuppressions[]; 1235f9996aaSopenharmony_ci 1245f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char *__tsan_default_suppressions() { 1255f9996aaSopenharmony_ci return kTSanDefaultSuppressions; 1265f9996aaSopenharmony_ci} 1275f9996aaSopenharmony_ci 1285f9996aaSopenharmony_ci#endif // THREAD_SANITIZER && OS_LINUX 1295f9996aaSopenharmony_ci 1305f9996aaSopenharmony_ci#if defined(MEMORY_SANITIZER) 1315f9996aaSopenharmony_ci// Default options for MemorySanitizer: 1325f9996aaSopenharmony_ci// intercept_memcmp=0 - do not detect uninitialized memory in memcmp() calls. 1335f9996aaSopenharmony_ci// Pending cleanup, see http://crbug.com/523428 1345f9996aaSopenharmony_ci// strip_path_prefix=/../../ - prefixes up to and including this 1355f9996aaSopenharmony_ci// substring will be stripped from source file paths in symbolized reports. 1365f9996aaSopenharmony_ciconst char kMsanDefaultOptions[] = 1375f9996aaSopenharmony_ci "intercept_memcmp=0 strip_path_prefix=/../../ "; 1385f9996aaSopenharmony_ci 1395f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char *__msan_default_options() { 1405f9996aaSopenharmony_ci return kMsanDefaultOptions; 1415f9996aaSopenharmony_ci} 1425f9996aaSopenharmony_ci 1435f9996aaSopenharmony_ci#endif // MEMORY_SANITIZER 1445f9996aaSopenharmony_ci 1455f9996aaSopenharmony_ci#if defined(LEAK_SANITIZER) 1465f9996aaSopenharmony_ci// Default options for LeakSanitizer: 1475f9996aaSopenharmony_ci// print_suppressions=1 - print the list of matched suppressions. 1485f9996aaSopenharmony_ci// strip_path_prefix=/../../ - prefixes up to and including this 1495f9996aaSopenharmony_ci// substring will be stripped from source file paths in symbolized reports. 1505f9996aaSopenharmony_ciconst char kLsanDefaultOptions[] = 1515f9996aaSopenharmony_ci "print_suppressions=1 strip_path_prefix=/../../ "; 1525f9996aaSopenharmony_ci 1535f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_options() { 1545f9996aaSopenharmony_ci return kLsanDefaultOptions; 1555f9996aaSopenharmony_ci} 1565f9996aaSopenharmony_ci 1575f9996aaSopenharmony_ciextern char kLSanDefaultSuppressions[]; 1585f9996aaSopenharmony_ci 1595f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char *__lsan_default_suppressions() { 1605f9996aaSopenharmony_ci return kLSanDefaultSuppressions; 1615f9996aaSopenharmony_ci} 1625f9996aaSopenharmony_ci 1635f9996aaSopenharmony_ci#endif // LEAK_SANITIZER 1645f9996aaSopenharmony_ci 1655f9996aaSopenharmony_ci#if defined(UNDEFINED_SANITIZER) 1665f9996aaSopenharmony_ci// Default options for UndefinedBehaviorSanitizer: 1675f9996aaSopenharmony_ci// print_stacktrace=1 - print the stacktrace when UBSan reports an error. 1685f9996aaSopenharmony_ciconst char kUbsanDefaultOptions[] = 1695f9996aaSopenharmony_ci "print_stacktrace=1 strip_path_prefix=/../../ "; 1705f9996aaSopenharmony_ci 1715f9996aaSopenharmony_ciSANITIZER_HOOK_ATTRIBUTE const char* __ubsan_default_options() { 1725f9996aaSopenharmony_ci return kUbsanDefaultOptions; 1735f9996aaSopenharmony_ci} 1745f9996aaSopenharmony_ci 1755f9996aaSopenharmony_ci#endif // UNDEFINED_SANITIZER 176