OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//build/config/sanitizers/sanitizers.gni") | 5 import("//build/config/sanitizers/sanitizers.gni") |
6 | 6 |
7 # Contains the dependencies needed for sanitizers to link into executables and | 7 # Contains the dependencies needed for sanitizers to link into executables and |
8 # shared_libraries. Unconditionally depend upon this target as it is empty if | 8 # shared_libraries. Unconditionally depend upon this target as it is empty if |
9 # |is_asan|, |is_lsan|, |is_tsan|, |is_msan| and |use_custom_libcxx| are false. | 9 # |is_asan|, |is_lsan|, |is_tsan|, |is_msan| and |use_custom_libcxx| are false. |
10 group("deps") { | 10 group("deps") { |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 source_set("options_sources") { | 42 source_set("options_sources") { |
43 visibility = [ | 43 visibility = [ |
44 ":deps", | 44 ":deps", |
45 "//:gn_visibility", | 45 "//:gn_visibility", |
46 ] | 46 ] |
47 sources = [ | 47 sources = [ |
48 "//build/sanitizers/sanitizer_options.cc", | 48 "//build/sanitizers/sanitizer_options.cc", |
49 ] | 49 ] |
50 | 50 |
| 51 # Don't compile this target with any sanitizer code. It can be called from |
| 52 # the sanitizer runtimes, so instrumenting these functions could cause |
| 53 # recursive calls into the runtime if there is an error. |
| 54 configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ] |
| 55 |
51 if (is_asan) { | 56 if (is_asan) { |
52 sources += [ "//build/sanitizers/asan_suppressions.cc" ] | 57 sources += [ "//build/sanitizers/asan_suppressions.cc" ] |
53 } | 58 } |
54 | 59 |
55 if (is_lsan) { | 60 if (is_lsan) { |
56 sources += [ "//build/sanitizers/lsan_suppressions.cc" ] | 61 sources += [ "//build/sanitizers/lsan_suppressions.cc" ] |
57 } | 62 } |
58 | 63 |
59 if (is_tsan) { | 64 if (is_tsan) { |
60 sources += [ "//build/sanitizers/tsan_suppressions.cc" ] | 65 sources += [ "//build/sanitizers/tsan_suppressions.cc" ] |
61 } | 66 } |
62 } | 67 } |
| 68 |
| 69 # This config is applied by default to all targets. It sets the compiler flags |
| 70 # for sanitizer usage, or, if no sanitizer is set, does nothing. |
| 71 # |
| 72 # This needs to be in a separate config so that targets can opt out of |
| 73 # sanitizers if they desire. |
| 74 config("default_sanitizer_flags") { |
| 75 cflags = [] |
| 76 cflags_cc = [] |
| 77 ldflags = [] |
| 78 defines = [] |
| 79 |
| 80 # Only works on Posix-like platforms. |
| 81 if (is_posix) { |
| 82 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, |
| 83 # MemorySanitizer and non-official CFI builds. |
| 84 if (using_sanitizer || (is_cfi && !is_official_build)) { |
| 85 cflags += [ |
| 86 "-fno-omit-frame-pointer", |
| 87 "-gline-tables-only", |
| 88 ] |
| 89 } |
| 90 if (is_asan) { |
| 91 asan_blacklist_path = |
| 92 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) |
| 93 cflags += [ |
| 94 "-fsanitize=address", |
| 95 "-fsanitize-blacklist=$asan_blacklist_path", |
| 96 ] |
| 97 if (is_mac) { |
| 98 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073 |
| 99 # TODO(GYP): deal with mac_bundles. |
| 100 } |
| 101 } |
| 102 if (is_lsan) { |
| 103 cflags += [ "-fsanitize=leak" ] |
| 104 } |
| 105 if (is_tsan) { |
| 106 tsan_blacklist_path = |
| 107 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir) |
| 108 cflags += [ |
| 109 "-fsanitize=thread", |
| 110 "-fsanitize-blacklist=$tsan_blacklist_path", |
| 111 ] |
| 112 } |
| 113 if (is_msan) { |
| 114 msan_blacklist_path = |
| 115 rebase_path("//tools/msan/blacklist.txt", root_build_dir) |
| 116 cflags += [ |
| 117 "-fsanitize=memory", |
| 118 "-fsanitize-memory-track-origins=$msan_track_origins", |
| 119 "-fsanitize-blacklist=$msan_blacklist_path", |
| 120 ] |
| 121 } |
| 122 if (is_cfi && !is_nacl) { |
| 123 cfi_blacklist_path = |
| 124 rebase_path("//tools/cfi/blacklist.txt", root_build_dir) |
| 125 cflags += [ |
| 126 "-flto", |
| 127 "-fsanitize=cfi-vcall", |
| 128 "-fsanitize=cfi-derived-cast", |
| 129 "-fsanitize=cfi-unrelated-cast", |
| 130 "-fsanitize-blacklist=$cfi_blacklist_path", |
| 131 ] |
| 132 ldflags += [ |
| 133 "-flto", |
| 134 "-fsanitize=cfi-vcall", |
| 135 "-fsanitize=cfi-derived-cast", |
| 136 "-fsanitize=cfi-unrelated-cast", |
| 137 ] |
| 138 |
| 139 # Apply a lower LTO optimization level in non-official builds. |
| 140 if (!is_official_build) { |
| 141 if (is_linux) { |
| 142 ldflags += [ "-Wl,-plugin-opt,O1" ] |
| 143 } else if (is_mac) { |
| 144 ldflags += [ "-Wl,-mllvm,-O1" ] |
| 145 } |
| 146 } |
| 147 |
| 148 # Work-around for http://openradar.appspot.com/20356002 |
| 149 if (is_mac) { |
| 150 ldflags += [ "-Wl,-all_load" ] |
| 151 } |
| 152 |
| 153 # Without this flag, LTO produces a .text section that is larger |
| 154 # than the maximum call displacement, preventing the linker from |
| 155 # relocating calls (http://llvm.org/PR22999). |
| 156 if (current_cpu == "arm") { |
| 157 ldflags += [ "-Wl,-plugin-opt,-function-sections" ] |
| 158 } |
| 159 |
| 160 if (use_cfi_diag) { |
| 161 cflags += [ |
| 162 "-fno-sanitize-trap=cfi", |
| 163 "-fsanitize-recover=cfi", |
| 164 ] |
| 165 ldflags += [ |
| 166 "-fno-sanitize-trap=cfi", |
| 167 "-fsanitize-recover=cfi", |
| 168 ] |
| 169 } else { |
| 170 defines += [ "CFI_ENFORCEMENT" ] |
| 171 } |
| 172 } |
| 173 |
| 174 if (use_custom_libcxx) { |
| 175 cflags_cc += [ "-nostdinc++" ] |
| 176 include_dirs = [ |
| 177 "//buildtools/third_party/libc++/trunk/include", |
| 178 "//buildtools/third_party/libc++abi/trunk/include", |
| 179 ] |
| 180 } |
| 181 } |
| 182 } |
OLD | NEW |