| 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/chrome_build.gni") | 5 import("//build/config/chrome_build.gni") |
| 6 import("//build/config/chromecast_build.gni") | 6 import("//build/config/chromecast_build.gni") |
| 7 import("//build/config/sanitizers/sanitizers.gni") | 7 import("//build/config/sanitizers/sanitizers.gni") |
| 8 | 8 |
| 9 # Contains the dependencies needed for sanitizers to link into executables and | 9 # Contains the dependencies needed for sanitizers to link into executables and |
| 10 # shared_libraries. Unconditionally depend upon this target as it is empty if | 10 # shared_libraries. Unconditionally depend upon this target as it is empty if |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 if (is_msan) { | 86 if (is_msan) { |
| 87 ldflags += [ "-fsanitize=memory" ] | 87 ldflags += [ "-fsanitize=memory" ] |
| 88 } | 88 } |
| 89 if (is_ubsan) { | 89 if (is_ubsan) { |
| 90 ldflags += [ "-fsanitize=undefined" ] | 90 ldflags += [ "-fsanitize=undefined" ] |
| 91 } | 91 } |
| 92 if (is_ubsan_vptr) { | 92 if (is_ubsan_vptr) { |
| 93 ldflags += [ "-fsanitize=vptr" ] | 93 ldflags += [ "-fsanitize=vptr" ] |
| 94 } | 94 } |
| 95 if (is_lto && !is_nacl) { | |
| 96 ldflags += [ "-flto" ] | |
| 97 | 95 |
| 98 # Apply a lower LTO optimization level as the default is too slow. | 96 if (is_cfi && !is_nacl) { |
| 99 if (is_linux) { | 97 ldflags += [ |
| 100 ldflags += [ "-Wl,-plugin-opt,O1" ] | 98 "-fsanitize=cfi-vcall", |
| 101 } else if (is_mac) { | 99 "-fsanitize=cfi-derived-cast", |
| 102 ldflags += [ "-Wl,-mllvm,-O1" ] | 100 "-fsanitize=cfi-unrelated-cast", |
| 103 } | 101 ] |
| 104 | |
| 105 # Work-around for http://openradar.appspot.com/20356002 | |
| 106 if (is_mac) { | |
| 107 ldflags += [ "-Wl,-all_load" ] | |
| 108 } | |
| 109 | |
| 110 # Without this flag, LTO produces a .text section that is larger | |
| 111 # than the maximum call displacement, preventing the linker from | |
| 112 # relocating calls (http://llvm.org/PR22999). | |
| 113 if (current_cpu == "arm") { | |
| 114 ldflags += [ "-Wl,-plugin-opt,-function-sections" ] | |
| 115 } | |
| 116 | |
| 117 if (is_cfi) { | |
| 118 ldflags += [ | |
| 119 "-fsanitize=cfi-vcall", | |
| 120 "-fsanitize=cfi-derived-cast", | |
| 121 "-fsanitize=cfi-unrelated-cast", | |
| 122 ] | |
| 123 } | |
| 124 | |
| 125 if (use_cfi_diag) { | 102 if (use_cfi_diag) { |
| 126 ldflags += [ | 103 ldflags += [ |
| 127 "-fno-sanitize-trap=cfi", | 104 "-fno-sanitize-trap=cfi", |
| 128 "-fsanitize-recover=cfi", | 105 "-fsanitize-recover=cfi", |
| 129 ] | 106 ] |
| 130 } | 107 } |
| 131 } | 108 } |
| 132 } | 109 } |
| 133 } | 110 } |
| 134 | 111 |
| 135 # This config is applied by default to all targets. It sets the compiler flags | 112 # This config is applied by default to all targets. It sets the compiler flags |
| 136 # for sanitizer usage, or, if no sanitizer is set, does nothing. | 113 # for sanitizer usage, or, if no sanitizer is set, does nothing. |
| 137 # | 114 # |
| 138 # This needs to be in a separate config so that targets can opt out of | 115 # This needs to be in a separate config so that targets can opt out of |
| 139 # sanitizers (by removing the config) if they desire. Even if a target | 116 # sanitizers (by removing the config) if they desire. Even if a target |
| 140 # removes this config, executables & shared libraries should still depend on | 117 # removes this config, executables & shared libraries should still depend on |
| 141 # :deps if any of their dependencies have not opted out of sanitizers. | 118 # :deps if any of their dependencies have not opted out of sanitizers. |
| 142 config("default_sanitizer_flags") { | 119 config("default_sanitizer_flags") { |
| 143 cflags = [] | 120 cflags = [] |
| 144 cflags_cc = [] | 121 cflags_cc = [] |
| 145 defines = [] | 122 defines = [] |
| 146 configs = [ ":default_sanitizer_ldflags" ] | 123 configs = [ ":default_sanitizer_ldflags" ] |
| 147 | 124 |
| 148 # Only works on Posix-like platforms. | 125 # Only works on Posix-like platforms. |
| 149 # FIXME: this is not true, remove the conditional. | 126 # FIXME: this is not true, remove the conditional. |
| 150 if (is_posix) { | 127 if (is_posix) { |
| 151 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, | 128 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, |
| 152 # MemorySanitizer and non-official CFI builds. | 129 # MemorySanitizer and non-official CFI builds. |
| 153 if (using_sanitizer || (is_lto && !is_official_build)) { | 130 if (using_sanitizer || (is_cfi && !is_official_build)) { |
| 154 cflags += [ | 131 cflags += [ |
| 155 "-fno-omit-frame-pointer", | 132 "-fno-omit-frame-pointer", |
| 156 "-gline-tables-only", | 133 "-gline-tables-only", |
| 157 ] | 134 ] |
| 158 } | 135 } |
| 159 if (is_asan) { | 136 if (is_asan) { |
| 160 asan_blacklist_path = | 137 asan_blacklist_path = |
| 161 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) | 138 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir) |
| 162 cflags += [ | 139 cflags += [ |
| 163 "-fsanitize=address", | 140 "-fsanitize=address", |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 216 } |
| 240 } | 217 } |
| 241 if (is_ubsan_vptr) { | 218 if (is_ubsan_vptr) { |
| 242 ubsan_vptr_blacklist_path = | 219 ubsan_vptr_blacklist_path = |
| 243 rebase_path("//tools/ubsan/vptr_blacklist.txt", root_build_dir) | 220 rebase_path("//tools/ubsan/vptr_blacklist.txt", root_build_dir) |
| 244 cflags += [ | 221 cflags += [ |
| 245 "-fsanitize=vptr", | 222 "-fsanitize=vptr", |
| 246 "-fsanitize-blacklist=$ubsan_vptr_blacklist_path", | 223 "-fsanitize-blacklist=$ubsan_vptr_blacklist_path", |
| 247 ] | 224 ] |
| 248 } | 225 } |
| 249 if (is_lto && !is_nacl) { | |
| 250 cflags += [ "-flto" ] | |
| 251 | 226 |
| 252 if (is_cfi) { | 227 if (is_cfi && !is_nacl) { |
| 253 cfi_blacklist_path = | 228 cfi_blacklist_path = |
| 254 rebase_path("//tools/cfi/blacklist.txt", root_build_dir) | 229 rebase_path("//tools/cfi/blacklist.txt", root_build_dir) |
| 255 cflags += [ | 230 cflags += [ |
| 256 "-fsanitize=cfi-vcall", | 231 "-fsanitize=cfi-vcall", |
| 257 "-fsanitize=cfi-derived-cast", | 232 "-fsanitize=cfi-derived-cast", |
| 258 "-fsanitize=cfi-unrelated-cast", | 233 "-fsanitize=cfi-unrelated-cast", |
| 259 "-fsanitize-blacklist=$cfi_blacklist_path", | 234 "-fsanitize-blacklist=$cfi_blacklist_path", |
| 260 ] | 235 ] |
| 261 } | |
| 262 | 236 |
| 263 if (use_cfi_diag) { | 237 if (use_cfi_diag) { |
| 264 cflags += [ | 238 cflags += [ |
| 265 "-fno-sanitize-trap=cfi", | 239 "-fno-sanitize-trap=cfi", |
| 266 "-fsanitize-recover=cfi", | 240 "-fsanitize-recover=cfi", |
| 267 "-fno-inline-functions", | 241 "-fno-inline-functions", |
| 268 "-fno-inline", | 242 "-fno-inline", |
| 269 "-fno-omit-frame-pointer", | 243 "-fno-omit-frame-pointer", |
| 270 "-O1", | 244 "-O1", |
| 271 ] | 245 ] |
| (...skipping 15 matching lines...) Expand all Loading... |
| 287 } | 261 } |
| 288 | 262 |
| 289 config("default_sanitizer_coverage_flags") { | 263 config("default_sanitizer_coverage_flags") { |
| 290 cflags = [] | 264 cflags = [] |
| 291 | 265 |
| 292 if (use_sanitizer_coverage) { | 266 if (use_sanitizer_coverage) { |
| 293 # FIXME: make this configurable. | 267 # FIXME: make this configurable. |
| 294 cflags += [ "-fsanitize-coverage=edge,indirect-calls,8bit-counters" ] | 268 cflags += [ "-fsanitize-coverage=edge,indirect-calls,8bit-counters" ] |
| 295 } | 269 } |
| 296 } | 270 } |
| OLD | NEW |