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