| 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/sanitizers/sanitizers.gni") | 6 import("//build/config/sanitizers/sanitizers.gni") |
| 7 | 7 |
| 8 # Contains the dependencies needed for sanitizers to link into executables and | 8 # Contains the dependencies needed for sanitizers to link into executables and |
| 9 # shared_libraries. Unconditionally depend upon this target as it is empty if | 9 # shared_libraries. Unconditionally depend upon this target as it is empty if |
| 10 # |is_asan|, |is_lsan|, |is_tsan|, |is_msan| and |use_custom_libcxx| are false. | 10 # |is_asan|, |is_lsan|, |is_tsan|, |is_msan| and |use_custom_libcxx| are false. |
| 11 group("deps") { | 11 group("deps") { |
| 12 if (using_sanitizer) { | 12 if (using_sanitizer) { |
| 13 public_configs = [ ":sanitizer_options_link_helper" ] | 13 public_configs = [ |
| 14 ":sanitizer_options_link_helper", |
| 15 |
| 16 # Even when a target removes default_sanitizer_flags, it may be depending |
| 17 # on a library that did not remove default_sanitizer_flags. Thus, we need |
| 18 # to add the ldflags here as well as in default_sanitizer_flags. |
| 19 ":default_sanitizer_ldflags", |
| 20 ] |
| 14 deps = [ | 21 deps = [ |
| 15 ":options_sources", | 22 ":options_sources", |
| 16 ] | 23 ] |
| 17 | 24 |
| 18 if (use_prebuilt_instrumented_libraries) { | 25 if (use_prebuilt_instrumented_libraries) { |
| 19 deps += [ "//third_party/instrumented_libraries:deps" ] | 26 deps += [ "//third_party/instrumented_libraries:deps" ] |
| 20 } | 27 } |
| 21 if (use_custom_libcxx) { | 28 if (use_custom_libcxx) { |
| 22 deps += [ "//buildtools/third_party/libc++:libcxx_proxy" ] | 29 deps += [ "//buildtools/third_party/libc++:libcxx_proxy" ] |
| 23 } | 30 } |
| 24 } | 31 } |
| 25 } | 32 } |
| 26 | 33 |
| 27 config("sanitizer_options_link_helper") { | 34 config("sanitizer_options_link_helper") { |
| 28 ldflags = [ "-Wl,-u_sanitizer_options_link_helper" ] | 35 ldflags = [ "-Wl,-u_sanitizer_options_link_helper" ] |
| 29 if (is_asan) { | |
| 30 ldflags += [ "-fsanitize=address" ] | |
| 31 } | |
| 32 if (is_lsan) { | |
| 33 ldflags += [ "-fsanitize=leak" ] | |
| 34 } | |
| 35 if (is_tsan) { | |
| 36 ldflags += [ "-fsanitize=thread" ] | |
| 37 } | |
| 38 if (is_msan) { | |
| 39 ldflags += [ "-fsanitize=memory" ] | |
| 40 } | |
| 41 if (is_ubsan) { | |
| 42 ldflags += [ "-fsanitize=undefined" ] | |
| 43 } | |
| 44 if (is_ubsan_vptr) { | |
| 45 ldflags += [ "-fsanitize=vptr" ] | |
| 46 } | |
| 47 } | 36 } |
| 48 | 37 |
| 49 source_set("options_sources") { | 38 source_set("options_sources") { |
| 50 visibility = [ | 39 visibility = [ |
| 51 ":deps", | 40 ":deps", |
| 52 "//:gn_visibility", | 41 "//:gn_visibility", |
| 53 ] | 42 ] |
| 54 sources = [ | 43 sources = [ |
| 55 "//build/sanitizers/sanitizer_options.cc", | 44 "//build/sanitizers/sanitizer_options.cc", |
| 56 ] | 45 ] |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 | 56 |
| 68 if (is_lsan) { | 57 if (is_lsan) { |
| 69 sources += [ "//build/sanitizers/lsan_suppressions.cc" ] | 58 sources += [ "//build/sanitizers/lsan_suppressions.cc" ] |
| 70 } | 59 } |
| 71 | 60 |
| 72 if (is_tsan) { | 61 if (is_tsan) { |
| 73 sources += [ "//build/sanitizers/tsan_suppressions.cc" ] | 62 sources += [ "//build/sanitizers/tsan_suppressions.cc" ] |
| 74 } | 63 } |
| 75 } | 64 } |
| 76 | 65 |
| 66 # Applies linker flags necessary when either :deps or :default_sanitizer_flags |
| 67 # are used. |
| 68 config("default_sanitizer_ldflags") { |
| 69 visibility = [ |
| 70 ":default_sanitizer_flags", |
| 71 ":deps", |
| 72 ] |
| 73 |
| 74 if (is_posix) { |
| 75 ldflags = [] |
| 76 if (is_asan) { |
| 77 ldflags += [ "-fsanitize=address" ] |
| 78 } |
| 79 if (is_lsan) { |
| 80 ldflags += [ "-fsanitize=leak" ] |
| 81 } |
| 82 if (is_tsan) { |
| 83 ldflags += [ "-fsanitize=thread" ] |
| 84 } |
| 85 if (is_msan) { |
| 86 ldflags += [ "-fsanitize=memory" ] |
| 87 } |
| 88 if (is_ubsan) { |
| 89 ldflags += [ "-fsanitize=undefined" ] |
| 90 } |
| 91 if (is_ubsan_vptr) { |
| 92 ldflags += [ "-fsanitize=vptr" ] |
| 93 } |
| 94 if (is_cfi && !is_nacl) { |
| 95 ldflags += [ |
| 96 "-flto", |
| 97 "-fsanitize=cfi-vcall", |
| 98 "-fsanitize=cfi-derived-cast", |
| 99 "-fsanitize=cfi-unrelated-cast", |
| 100 ] |
| 101 |
| 102 # Apply a lower LTO optimization level as the default is too slow. |
| 103 if (is_linux) { |
| 104 ldflags += [ "-Wl,-plugin-opt,O1" ] |
| 105 } else if (is_mac) { |
| 106 ldflags += [ "-Wl,-mllvm,-O1" ] |
| 107 } |
| 108 |
| 109 # Work-around for http://openradar.appspot.com/20356002 |
| 110 if (is_mac) { |
| 111 ldflags += [ "-Wl,-all_load" ] |
| 112 } |
| 113 |
| 114 # Without this flag, LTO produces a .text section that is larger |
| 115 # than the maximum call displacement, preventing the linker from |
| 116 # relocating calls (http://llvm.org/PR22999). |
| 117 if (current_cpu == "arm") { |
| 118 ldflags += [ "-Wl,-plugin-opt,-function-sections" ] |
| 119 } |
| 120 |
| 121 if (use_cfi_diag) { |
| 122 ldflags += [ |
| 123 "-fno-sanitize-trap=cfi", |
| 124 "-fsanitize-recover=cfi", |
| 125 ] |
| 126 } |
| 127 } |
| 128 } |
| 129 } |
| 130 |
| 77 # This config is applied by default to all targets. It sets the compiler flags | 131 # This config is applied by default to all targets. It sets the compiler flags |
| 78 # for sanitizer usage, or, if no sanitizer is set, does nothing. | 132 # for sanitizer usage, or, if no sanitizer is set, does nothing. |
| 79 # | 133 # |
| 80 # This needs to be in a separate config so that targets can opt out of | 134 # This needs to be in a separate config so that targets can opt out of |
| 81 # sanitizers if they desire. | 135 # sanitizers (by removing the config) if they desire. Even if a target |
| 136 # removes this config, executables & shared libraries should still depend on |
| 137 # :deps if any of their dependencies have not opted out of sanitizers. |
| 82 config("default_sanitizer_flags") { | 138 config("default_sanitizer_flags") { |
| 83 cflags = [] | 139 cflags = [] |
| 84 cflags_cc = [] | 140 cflags_cc = [] |
| 85 ldflags = [] | |
| 86 defines = [] | 141 defines = [] |
| 142 configs = [ ":default_sanitizer_ldflags" ] |
| 87 | 143 |
| 88 # Only works on Posix-like platforms. | 144 # Only works on Posix-like platforms. |
| 89 # FIXME: this is not true, remove the conditional. | 145 # FIXME: this is not true, remove the conditional. |
| 90 if (is_posix) { | 146 if (is_posix) { |
| 91 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, | 147 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer, |
| 92 # MemorySanitizer and non-official CFI builds. | 148 # MemorySanitizer and non-official CFI builds. |
| 93 if (using_sanitizer || (is_cfi && !is_official_build)) { | 149 if (using_sanitizer || (is_cfi && !is_official_build)) { |
| 94 cflags += [ | 150 cflags += [ |
| 95 "-fno-omit-frame-pointer", | 151 "-fno-omit-frame-pointer", |
| 96 "-gline-tables-only", | 152 "-gline-tables-only", |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 if (is_cfi && !is_nacl) { | 239 if (is_cfi && !is_nacl) { |
| 184 cfi_blacklist_path = | 240 cfi_blacklist_path = |
| 185 rebase_path("//tools/cfi/blacklist.txt", root_build_dir) | 241 rebase_path("//tools/cfi/blacklist.txt", root_build_dir) |
| 186 cflags += [ | 242 cflags += [ |
| 187 "-flto", | 243 "-flto", |
| 188 "-fsanitize=cfi-vcall", | 244 "-fsanitize=cfi-vcall", |
| 189 "-fsanitize=cfi-derived-cast", | 245 "-fsanitize=cfi-derived-cast", |
| 190 "-fsanitize=cfi-unrelated-cast", | 246 "-fsanitize=cfi-unrelated-cast", |
| 191 "-fsanitize-blacklist=$cfi_blacklist_path", | 247 "-fsanitize-blacklist=$cfi_blacklist_path", |
| 192 ] | 248 ] |
| 193 ldflags += [ | |
| 194 "-flto", | |
| 195 "-fsanitize=cfi-vcall", | |
| 196 "-fsanitize=cfi-derived-cast", | |
| 197 "-fsanitize=cfi-unrelated-cast", | |
| 198 ] | |
| 199 | |
| 200 # Apply a lower LTO optimization level as the default is too slow. | |
| 201 if (is_linux) { | |
| 202 ldflags += [ "-Wl,-plugin-opt,O1" ] | |
| 203 } else if (is_mac) { | |
| 204 ldflags += [ "-Wl,-mllvm,-O1" ] | |
| 205 } | |
| 206 | |
| 207 # Work-around for http://openradar.appspot.com/20356002 | |
| 208 if (is_mac) { | |
| 209 ldflags += [ "-Wl,-all_load" ] | |
| 210 } | |
| 211 | |
| 212 # Without this flag, LTO produces a .text section that is larger | |
| 213 # than the maximum call displacement, preventing the linker from | |
| 214 # relocating calls (http://llvm.org/PR22999). | |
| 215 if (current_cpu == "arm") { | |
| 216 ldflags += [ "-Wl,-plugin-opt,-function-sections" ] | |
| 217 } | |
| 218 | 249 |
| 219 if (use_cfi_diag) { | 250 if (use_cfi_diag) { |
| 220 cflags += [ | 251 cflags += [ |
| 221 "-fno-sanitize-trap=cfi", | 252 "-fno-sanitize-trap=cfi", |
| 222 "-fsanitize-recover=cfi", | 253 "-fsanitize-recover=cfi", |
| 223 ] | 254 ] |
| 224 ldflags += [ | |
| 225 "-fno-sanitize-trap=cfi", | |
| 226 "-fsanitize-recover=cfi", | |
| 227 ] | |
| 228 } else { | 255 } else { |
| 229 defines += [ "CFI_ENFORCEMENT" ] | 256 defines += [ "CFI_ENFORCEMENT" ] |
| 230 } | 257 } |
| 231 } | 258 } |
| 232 | 259 |
| 233 if (use_custom_libcxx) { | 260 if (use_custom_libcxx) { |
| 234 prefix = "//buildtools/third_party" | 261 prefix = "//buildtools/third_party" |
| 235 include = "trunk/include" | 262 include = "trunk/include" |
| 236 cflags_cc += [ | 263 cflags_cc += [ |
| 237 "-nostdinc++", | 264 "-nostdinc++", |
| 238 "-isystem" + rebase_path("$prefix/libc++/$include", root_build_dir), | 265 "-isystem" + rebase_path("$prefix/libc++/$include", root_build_dir), |
| 239 "-isystem" + rebase_path("$prefix/libc++abi/$include", root_build_dir), | 266 "-isystem" + rebase_path("$prefix/libc++abi/$include", root_build_dir), |
| 240 ] | 267 ] |
| 241 } | 268 } |
| 242 } | 269 } |
| 243 } | 270 } |
| 244 | 271 |
| 245 config("default_sanitizer_coverage_flags") { | 272 config("default_sanitizer_coverage_flags") { |
| 246 cflags = [] | 273 cflags = [] |
| 247 | 274 |
| 248 if (use_sanitizer_coverage) { | 275 if (use_sanitizer_coverage) { |
| 249 # FIXME: make this configurable. | 276 # FIXME: make this configurable. |
| 250 cflags += | 277 cflags += |
| 251 [ "-fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp" ] | 278 [ "-fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp" ] |
| 252 } | 279 } |
| 253 } | 280 } |
| OLD | NEW |