BUILD.gn (22283B)
1 # Copyright 2014 The Chromium Authors 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import("//chromium/build/config/cast.gni") 6 import("//chromium/build/config/chrome_build.gni") 7 import("//chromium/build/config/clang/clang.gni") 8 import("//chromium/build/config/rust.gni") 9 import("//chromium/build/config/sanitizers/sanitizers.gni") 10 import("//chromium/build/toolchain/toolchain.gni") 11 import("//build_overrides/build.gni") 12 13 if (is_ios) { 14 import("//chromium/build/config/apple/mobile_config.gni") 15 } 16 17 declare_args() { 18 # Allow building official with ASAN enabled to help with 19 # debugging https://crbug.com/371135823. 20 ios_allow_asan_for_official_to_debug_371135823 = false 21 } 22 23 # libfuzzer can't cope with shared objects being unloaded, which sometimes 24 # occurs for large fuzzers that involve our graphics stack. Shim out dlclose 25 # so that this doesn't occur. 26 # 27 # dlclose() is defined by POSIX, making `is_posix` a tempting condition to use. 28 # However the linker does not necessarily support `-wrap` on all POSIX 29 # platforms, hence the restriction to Linux and ChromeOS. We might eventually 30 # want to disable shared library unloading on all platforms, but we have not 31 # noticed a need for it as the known-affected large fuzzers only run on Linux. 32 use_dlcloseshim = use_libfuzzer && (is_linux || is_chromeos) 33 34 # Contains the dependencies needed for sanitizers to link into executables and 35 # shared_libraries. 36 group("deps") { 37 deps = [] 38 data = [] 39 if (using_sanitizer) { 40 public_configs = [ 41 # Even when a target removes default_sanitizer_flags, it may be depending 42 # on a library that did not remove default_sanitizer_flags. Thus, we need 43 # to add the ldflags here as well as in default_sanitizer_flags. 44 ":default_sanitizer_ldflags", 45 ] 46 if (!is_fuchsia) { 47 if (is_win) { 48 exe = ".exe" 49 } else { 50 exe = "" 51 } 52 data += [ 53 "//tools/valgrind/asan/", 54 "$clang_base_path/bin/llvm-symbolizer${exe}", 55 ] 56 } 57 if (is_asan || is_lsan || is_msan || is_tsan || is_ubsan_any) { 58 public_configs += [ ":sanitizer_options_link_helper" ] 59 deps += [ ":options_sources" ] 60 } 61 if (use_prebuilt_instrumented_libraries || 62 use_locally_built_instrumented_libraries) { 63 deps += [ "//third_party/instrumented_libs:deps" ] 64 } 65 } 66 if (fail_on_san_warnings) { 67 data += [ "//tools/memory/sanitizer/escalate_sanitizer_warnings.py" ] 68 } 69 if (is_asan || is_ubsan_any) { 70 if (is_win || is_apple) { 71 data_deps = [ ":copy_sanitizer_runtime" ] 72 } 73 if (is_apple) { 74 public_deps = [ ":sanitizer_runtime_bundle_data" ] 75 } 76 } 77 if (use_centipede || enable_fuzztest_fuzz) { 78 # For executables which aren't actual fuzzers, we need stubs for 79 # the sanitizer coverage symbols, because we'll still be generating 80 # .o files which depend on them. 81 deps += [ "//third_party/fuzztest:centipede_weak_sancov_stubs" ] 82 } 83 } 84 85 assert(!(is_win && is_asan && target_cpu == "x86"), 86 "ASan is only supported in 64-bit builds on Windows.") 87 88 if ((is_apple || is_win) && (is_asan || is_ubsan_any)) { 89 if (is_mac || (is_ios && target_environment == "catalyst")) { 90 if (is_asan) { 91 _clang_rt_dso_path = "darwin/libclang_rt.asan_osx_dynamic.dylib" 92 } else { 93 assert(is_ubsan_any) 94 _clang_rt_dso_path = "darwin/libclang_rt.ubsan_osx_dynamic.dylib" 95 } 96 } else if (is_ios) { 97 if (is_asan) { 98 if (target_environment == "simulator") { 99 _clang_rt_dso_path = "darwin/libclang_rt.asan_iossim_dynamic.dylib" 100 } else { 101 _clang_rt_dso_path = "darwin/libclang_rt.asan_ios_dynamic.dylib" 102 } 103 } else { 104 assert(is_ubsan_any) 105 _clang_rt_dso_path = "darwin/libclang_rt.ubsan_iossim_dynamic.dylib" 106 } 107 } else if (is_win && target_cpu == "x64") { 108 if (is_asan) { 109 _clang_rt_dso_path = "windows/clang_rt.asan_dynamic-x86_64.dll" 110 } else { 111 assert(is_ubsan_any) 112 _clang_rt_dso_path = "windows/clang_rt.ubsan_dynamic-x86_64.dll" 113 } 114 } 115 116 _clang_rt_dso_full_path = 117 "$clang_base_path/lib/clang/$clang_version/lib/$_clang_rt_dso_path" 118 119 if (!is_ios) { 120 copy("copy_sanitizer_runtime") { 121 sources = [ _clang_rt_dso_full_path ] 122 outputs = [ "$root_out_dir/{{source_file_part}}" ] 123 } 124 } else { 125 # On iOS, the runtime library need to be code signed (adhoc signature) 126 # starting with Xcode 8, so use an action instead of a copy on iOS. 127 action("copy_sanitizer_runtime") { 128 script = "//chromium/build/config/apple/codesign.py" 129 sources = [ _clang_rt_dso_full_path ] 130 outputs = [ "$root_out_dir/" + get_path_info(sources[0], "file") ] 131 args = [ 132 "code-sign-file", 133 "--identity=" + ios_code_signing_identity, 134 "--output=" + rebase_path(outputs[0], root_build_dir), 135 rebase_path(sources[0], root_build_dir), 136 ] 137 } 138 } 139 140 if (is_apple) { 141 bundle_data("sanitizer_runtime_bundle_data") { 142 sources = get_target_outputs(":copy_sanitizer_runtime") 143 outputs = [ "{{bundle_executable_dir}}/{{source_file_part}}" ] 144 public_deps = [ ":copy_sanitizer_runtime" ] 145 } 146 } 147 } 148 149 config("sanitizer_options_link_helper") { 150 if (is_apple) { 151 ldflags = [ "-Wl,-u,__sanitizer_options_link_helper" ] 152 } else if (!is_win) { 153 ldflags = [ "-Wl,-u_sanitizer_options_link_helper" ] 154 } 155 } 156 157 static_library("options_sources") { 158 # This is a static_library instead of a source_set, as it shouldn't be 159 # unconditionally linked into targets. 160 visibility = [ 161 ":deps", 162 "//:gn_all", 163 ] 164 sources = [ "//chromium/build/sanitizers/sanitizer_options.cc" ] 165 166 # Don't compile this target with any sanitizer code. It can be called from 167 # the sanitizer runtimes, so instrumenting these functions could cause 168 # recursive calls into the runtime if there is an error. 169 configs -= [ "//chromium/build/config/sanitizers:default_sanitizer_flags" ] 170 171 if (is_asan) { 172 if (!defined(asan_suppressions_file)) { 173 asan_suppressions_file = "//chromium/build/sanitizers/asan_suppressions.cc" 174 } 175 sources += [ asan_suppressions_file ] 176 } 177 178 if (is_lsan) { 179 if (!defined(lsan_suppressions_file)) { 180 lsan_suppressions_file = "//chromium/build/sanitizers/lsan_suppressions.cc" 181 } 182 sources += [ lsan_suppressions_file ] 183 } 184 185 if (is_tsan) { 186 if (!defined(tsan_suppressions_file)) { 187 tsan_suppressions_file = "//chromium/build/sanitizers/tsan_suppressions.cc" 188 } 189 sources += [ tsan_suppressions_file ] 190 } 191 } 192 193 if (use_dlcloseshim) { 194 source_set("dlclose_shim") { 195 sources = [ "//chromium/build/sanitizers/dlcloseshim.c" ] 196 } 197 } else { 198 group("dlclose_shim") { 199 deps = [] 200 } 201 } 202 203 # Applies linker flags necessary when either :deps or :default_sanitizer_flags 204 # are used. 205 config("default_sanitizer_ldflags") { 206 visibility = [ 207 ":default_sanitizer_flags", 208 ":deps", 209 210 # https://crbug.com/360158. 211 "//tools/ipc_fuzzer/fuzzer:ipc_fuzzer", 212 ] 213 214 if (is_posix || is_fuchsia) { 215 sanitizers = [] # sanitizers applicable to both clang and rustc 216 ldflags = [] 217 rustflags = [] 218 if (is_asan) { 219 sanitizers += [ "address" ] 220 } 221 if (is_hwasan) { 222 sanitizers += [ "hwaddress" ] 223 } 224 if (is_lsan) { 225 # In Chromium, is_lsan always implies is_asan. ASAN includes LSAN. 226 # It seems harmless to pass both options to clang, but it doesn't 227 # work on rustc, so apply this option to clang only. 228 ldflags += [ "-fsanitize=leak" ] 229 } 230 if (is_tsan) { 231 sanitizers += [ "thread" ] 232 } 233 if (is_msan) { 234 sanitizers += [ "memory" ] 235 } 236 if (is_ubsan || is_ubsan_security) { 237 ldflags += [ "-fsanitize=undefined" ] 238 } 239 if (is_ubsan_vptr) { 240 ldflags += [ "-fsanitize=vptr" ] 241 } 242 foreach(sanitizer, sanitizers) { 243 ldflags += [ "-fsanitize=$sanitizer" ] 244 rustflags += [ "-Zsanitizer=$sanitizer" ] 245 } 246 247 if (use_sanitizer_coverage) { 248 if (use_libfuzzer) { 249 ldflags += [ "-fsanitize=fuzzer-no-link" ] 250 if (is_mac) { 251 # TODO(crbug.com/40611636): on macOS, dead code stripping does not work 252 # well with `pc-table` instrumentation enabled by `fuzzer-no-link`. 253 ldflags += [ "-fno-sanitize-coverage=pc-table" ] 254 } 255 } else { 256 ldflags += [ "-fsanitize-coverage=$sanitizer_coverage_flags" ] 257 } 258 if (is_mac && use_centipede) { 259 # OS X linking doesn't allow undefined symbols at link time 260 # and in a component build, component shared objects will 261 # need to use this symbol to report control flow coverage 262 # to the main binary 263 ldflags += [ "-Wl,-undefined,dynamic_lookup" ] 264 } 265 } 266 267 if (is_cfi && current_toolchain == default_toolchain) { 268 ldflags += [ "-fsanitize=cfi-vcall" ] 269 if (use_cfi_cast) { 270 ldflags += [ 271 "-fsanitize=cfi-derived-cast", 272 "-fsanitize=cfi-unrelated-cast", 273 ] 274 } 275 if (use_cfi_icall) { 276 ldflags += [ "-fsanitize=cfi-icall" ] 277 } 278 if (use_cfi_diag) { 279 ldflags += [ "-fno-sanitize-trap=cfi" ] 280 if (use_cfi_recover) { 281 ldflags += [ "-fsanitize-recover=cfi" ] 282 } 283 } 284 } 285 } else if (is_win) { 286 # Windows directly calls link.exe instead of the compiler driver when 287 # linking. Hence, pass the runtime libraries instead of -fsanitize=address 288 # or -fsanitize=fuzzer. 289 ldflags = [] 290 if (is_asan) { 291 assert(target_cpu == "x64", "WinASan unsupported architecture") 292 libs = [ "clang_rt.asan_dynamic-x86_64.lib" ] 293 if (is_component_build) { 294 ldflags += 295 [ "-wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib" ] 296 } else { 297 ldflags += 298 [ "-wholearchive:clang_rt.asan_static_runtime_thunk-x86_64.lib" ] 299 } 300 } 301 if (use_libfuzzer) { 302 assert(target_cpu == "x64", "LibFuzzer unsupported architecture") 303 assert(!is_component_build, 304 "LibFuzzer only supports non-component builds on Windows") 305 306 # Incremental linking causes padding that messes up SanitizerCoverage. 307 # Don't do it. 308 ldflags += [ "/INCREMENTAL:NO" ] 309 } 310 } 311 if (use_dlcloseshim) { 312 ldflags += [ "-Wl,-wrap,dlclose" ] 313 } 314 } 315 316 config("common_sanitizer_flags") { 317 cflags = [] 318 319 if (using_sanitizer) { 320 assert(is_clang, "sanitizers only supported with clang") 321 322 if (!is_ios || !ios_allow_asan_for_official_to_debug_371135823) { 323 # Allow non-default toolchains to enable sanitizers in toolchain_args even 324 # in official builds. 325 assert(current_toolchain != default_toolchain || !is_official_build, 326 "sanitizers not supported in official builds") 327 } 328 329 cflags += [ 330 # Column info in debug data confuses Visual Studio's debugger, so don't 331 # use this by default. However, clusterfuzz needs it for good 332 # attribution of reports to CLs, so turn it on there. 333 "-gcolumn-info", 334 ] 335 336 # Frame pointers are controlled in //build/config/compiler:default_stack_frames 337 } 338 } 339 340 config("asan_flags") { 341 cflags = [] 342 rustflags = [] 343 if (is_asan) { 344 cflags += [ "-fsanitize=address" ] 345 rustflags += [ "-Zsanitizer=address" ] 346 if (!is_win && !is_apple && !is_fuchsia) { 347 # TODO(crbug.com/1459233, crbug.com/1462248): This causes asan 348 # odr-violation errors in rust code, and link failures for cros/asan. 349 # Clang recently turned it on by default for all ELF targets (it was 350 # already on for Fuchsia). Pass the flag to turn it back off. 351 cflags += [ "-fno-sanitize-address-globals-dead-stripping" ] 352 } 353 if (is_win) { 354 if (!defined(asan_win_blocklist_path)) { 355 asan_win_blocklist_path = 356 rebase_path("//tools/memory/asan/blocklist_win.txt", root_build_dir) 357 } 358 cflags += [ "-fsanitize-ignorelist=$asan_win_blocklist_path" ] 359 } 360 } 361 } 362 363 config("cfi_flags") { 364 cflags = [] 365 rustflags = [] 366 if (is_cfi && current_toolchain == default_toolchain) { 367 if (!defined(cfi_ignorelist_path)) { 368 cfi_ignorelist_path = 369 rebase_path("//tools/cfi/ignores.txt", root_build_dir) 370 } 371 cflags += [ 372 "-fsanitize=cfi-vcall", 373 "-fsanitize-ignorelist=$cfi_ignorelist_path", 374 ] 375 376 if (toolchain_supports_rust_thin_lto) { 377 # sanitize=cfi implies -fsplit-lto-unit, and Rust needs to match 378 # behaviour. Rust needs to know the linker will be doing LTO in this case 379 # or it rejects the Zsplit-lto-unit flag. 380 # TODO(crbug.com/40266913): Add -Zsanitize=cfi instead. 381 rustflags += [ 382 "-Zsplit-lto-unit", 383 "-Clinker-plugin-lto=yes", 384 ] 385 } else { 386 # Don't include bitcode if it won't be used. 387 rustflags += [ "-Cembed-bitcode=no" ] 388 } 389 390 if (use_cfi_cast) { 391 cflags += [ 392 "-fsanitize=cfi-derived-cast", 393 "-fsanitize=cfi-unrelated-cast", 394 ] 395 } 396 397 if (use_cfi_icall) { 398 cflags += [ "-fsanitize=cfi-icall" ] 399 # TODO(crbug.com/40266913): Add cflags += [ 400 # "-fsanitize-cfi-icall-experimental-normalize-integers" ] 401 # TODO(crbug.com/40266913): Add rustflags += [ 402 # "-Zsanitizer-cfi-normalize-integers" ]. 403 } 404 405 if (use_cfi_diag) { 406 cflags += [ "-fno-sanitize-trap=cfi" ] 407 if (is_win) { 408 cflags += [ 409 "/Oy-", 410 "/Ob0", 411 ] 412 } else { 413 cflags += [ 414 "-fno-inline-functions", 415 "-fno-inline", 416 "-fno-omit-frame-pointer", 417 "-O1", 418 ] 419 } 420 if (use_cfi_recover) { 421 cflags += [ "-fsanitize-recover=cfi" ] 422 } 423 } 424 } 425 } 426 427 # crbug.com/785442: Fix cfi-icall failures for code that casts pointer argument 428 # types in function pointer type signatures. 429 config("cfi_icall_generalize_pointers") { 430 if (is_clang && is_cfi && use_cfi_icall) { 431 cflags = [ "-fsanitize-cfi-icall-generalize-pointers" ] 432 } 433 } 434 435 config("cfi_icall_disable") { 436 if (is_clang && is_cfi && use_cfi_icall) { 437 cflags = [ "-fno-sanitize=cfi-icall" ] 438 } 439 } 440 441 config("coverage_flags") { 442 cflags = [] 443 if (use_sanitizer_coverage) { 444 # Used by sandboxing code to allow coverage dump to be written on the disk. 445 defines = [ "SANITIZER_COVERAGE" ] 446 447 if (use_libfuzzer) { 448 cflags += [ "-fsanitize=fuzzer-no-link" ] 449 if (is_mac) { 450 # TODO(crbug.com/40611636): on macOS, dead code stripping does not work 451 # well with `pc-table` instrumentation enabled by `fuzzer-no-link`. 452 cflags += [ "-fno-sanitize-coverage=pc-table" ] 453 } 454 } else { 455 cflags += [ 456 "-fsanitize-coverage=$sanitizer_coverage_flags", 457 "-mllvm", 458 "-sanitizer-coverage-prune-blocks=1", 459 ] 460 if (target_cpu == "arm") { 461 # http://crbug.com/517105 462 cflags += [ 463 "-mllvm", 464 "-sanitizer-coverage-block-threshold=0", 465 ] 466 } 467 } 468 if (sanitizer_coverage_allowlist != "") { 469 cflags += [ "-fsanitize-coverage-allowlist=" + 470 rebase_path(sanitizer_coverage_allowlist, root_build_dir) ] 471 } 472 } 473 if (use_centipede) { 474 # Centipede intercepts calls such as memcmp and memcpy in order to improve 475 # its testcase generation. 476 # 477 # We explicitly list the intercepted calls instead of opting out of all 478 # builtins to work around a miscompile (crbug.com/380508212). 479 cflags += [ 480 "-fno-builtin-memcmp", 481 "-fno-builtin-pthread_create", 482 "-fno-builtin-strcmp", 483 "-fno-builtin-strncmp", 484 ] 485 } 486 } 487 488 config("hwasan_flags") { 489 if (is_hwasan) { 490 asmflags = [ "-fsanitize=hwaddress" ] 491 cflags = [ "-fsanitize=hwaddress" ] 492 } 493 } 494 495 config("lsan_flags") { 496 if (is_lsan) { 497 cflags = [ "-fsanitize=leak" ] 498 } 499 } 500 501 config("msan_flags") { 502 if (is_msan) { 503 assert(is_linux || is_chromeos, 504 "msan only supported on linux x86_64/ChromeOS") 505 if (!defined(msan_ignorelist_path)) { 506 msan_ignorelist_path = 507 rebase_path("//tools/msan/ignorelist.txt", root_build_dir) 508 } 509 cflags = [ 510 "-fsanitize=memory", 511 "-fsanitize-memory-track-origins=$msan_track_origins", 512 "-fsanitize-ignorelist=$msan_ignorelist_path", 513 ] 514 515 if (!msan_check_use_after_dtor) { 516 # TODO(crbug.com/40222690): evaluate and possibly enable 517 cflags += [ "-fno-sanitize-memory-use-after-dtor" ] 518 } 519 520 if (!msan_eager_checks) { 521 cflags += [ "-fno-sanitize-memory-param-retval" ] 522 } 523 } 524 } 525 526 config("tsan_flags") { 527 if (is_tsan) { 528 assert(is_linux || is_chromeos, "tsan only supported on linux x86_64") 529 if (!defined(tsan_ignorelist_path)) { 530 tsan_ignorelist_path = 531 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir) 532 } 533 cflags = [ 534 "-fsanitize=thread", 535 "-fsanitize-ignorelist=$tsan_ignorelist_path", 536 ] 537 } 538 } 539 540 config("ubsan_flags") { 541 cflags = [] 542 if (is_ubsan) { 543 if (!defined(ubsan_ignorelist_path)) { 544 ubsan_ignorelist_path = 545 rebase_path("//tools/ubsan/ignorelist.txt", root_build_dir) 546 } 547 548 # TODO(crbug.com/40942951): Enable all of -fsanitize=undefined. Note that 549 # both this list and Clang's defaults omit -fsanitize=float-divide-by-zero. 550 # C and C++ leave it undefined to accommodate non-IEEE floating point, but 551 # we assume the compiler implements IEEE floating point, which does define 552 # division by zero. 553 cflags += [ 554 "-fsanitize=alignment", 555 "-fsanitize=bool", 556 "-fsanitize=bounds", 557 "-fsanitize=builtin", 558 "-fsanitize=integer-divide-by-zero", 559 "-fsanitize=null", 560 "-fsanitize=nonnull-attribute", 561 "-fsanitize=object-size", 562 "-fsanitize=pointer-overflow", 563 "-fsanitize=return", 564 "-fsanitize=returns-nonnull-attribute", 565 "-fsanitize=shift", 566 "-fsanitize=signed-integer-overflow", 567 "-fsanitize=unreachable", 568 "-fsanitize=vla-bound", 569 "-fsanitize-ignorelist=$ubsan_ignorelist_path", 570 ] 571 } 572 } 573 574 config("ubsan_no_recover") { 575 if (is_ubsan_no_recover) { 576 cflags = [ "-fno-sanitize-recover=undefined" ] 577 } 578 } 579 580 config("ubsan_security_flags") { 581 if (is_ubsan_security) { 582 if (!defined(ubsan_security_ignorelist_path)) { 583 ubsan_security_ignorelist_path = 584 rebase_path("//tools/ubsan/security_ignorelist.txt", root_build_dir) 585 } 586 cflags = [ 587 "-fsanitize=function", 588 "-fsanitize=shift", 589 "-fsanitize=signed-integer-overflow", 590 "-fsanitize=vla-bound", 591 "-fsanitize-ignorelist=$ubsan_security_ignorelist_path", 592 ] 593 } 594 } 595 596 config("ubsan_vptr_flags") { 597 if (is_ubsan_vptr) { 598 if (!defined(ubsan_vptr_ignorelist_path)) { 599 ubsan_vptr_ignorelist_path = 600 rebase_path("//tools/ubsan/vptr_ignorelist.txt", root_build_dir) 601 } 602 cflags = [ 603 "-fsanitize=vptr", 604 "-fsanitize-ignorelist=$ubsan_vptr_ignorelist_path", 605 ] 606 } 607 } 608 609 config("fuzzing_build_mode") { 610 if (use_fuzzing_engine) { 611 defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ] 612 rustflags = [ "--cfg=FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ] 613 } 614 } 615 616 all_sanitizer_configs = [ 617 ":common_sanitizer_flags", 618 ":coverage_flags", 619 ":default_sanitizer_ldflags", 620 ":asan_flags", 621 ":cfi_flags", 622 ":hwasan_flags", 623 ":lsan_flags", 624 ":msan_flags", 625 ":tsan_flags", 626 ":ubsan_flags", 627 ":ubsan_no_recover", 628 ":ubsan_security_flags", 629 ":ubsan_vptr_flags", 630 ":fuzzing_build_mode", 631 ] 632 633 # This config is applied by default to all targets. It sets the compiler flags 634 # for sanitizer usage, or, if no sanitizer is set, does nothing. 635 # 636 # This needs to be in a separate config so that targets can opt out of 637 # sanitizers (by removing the config) if they desire. Even if a target 638 # removes this config, executables & shared libraries should still depend on 639 # :deps if any of their dependencies have not opted out of sanitizers. 640 # Keep this list in sync with default_sanitizer_flags_but_ubsan_vptr. 641 config("default_sanitizer_flags") { 642 configs = all_sanitizer_configs 643 644 if (use_sanitizer_configs_without_instrumentation) { 645 configs = [] 646 } 647 } 648 649 # This config is equivalent to default_sanitizer_flags, but excludes ubsan_vptr. 650 # This allows to selectively disable ubsan_vptr, when needed. In particular, 651 # if some third_party code is required to be compiled without rtti, which 652 # is a requirement for ubsan_vptr. 653 config("default_sanitizer_flags_but_ubsan_vptr") { 654 configs = all_sanitizer_configs - [ ":ubsan_vptr_flags" ] 655 656 if (use_sanitizer_configs_without_instrumentation) { 657 configs = [] 658 } 659 } 660 661 config("default_sanitizer_flags_but_coverage") { 662 configs = all_sanitizer_configs - [ ":coverage_flags" ] 663 664 if (use_sanitizer_configs_without_instrumentation) { 665 configs = [] 666 } 667 } 668 669 # This config is used by parts of code that aren't targeted in fuzzers and 670 # therefore don't need coverage instrumentation and possibly wont need 671 # sanitizer instrumentation either. The config also tells the compiler to 672 # perform additional optimizations on the configured code and ensures that 673 # linking it to the rest of the binary which is instrumented with sanitizers 674 # works. The config only does anything if the build is a fuzzing build. 675 config("not_fuzzed") { 676 if (use_fuzzing_engine) { 677 # Since we aren't instrumenting with coverage, code size is less of a 678 # concern, so use a more aggressive optimization level than 679 # optimize_for_fuzzing (-O1). When given multiple optimization flags, clang 680 # obeys the last one, so as long as this flag comes after -O1, it should work. 681 # Since this config will always be depended on after 682 # "//chromium/build/config/compiler:default_optimization" (which adds -O1 when 683 # optimize_for_fuzzing is true), -O2 should always be the second flag. Even 684 # though this sounds fragile, it isn't a big deal if it breaks, since proto 685 # fuzzers will still work, they will just be slightly slower. 686 cflags = [ "-O2" ] 687 688 # We need to include this config when we remove default_sanitizer_flags or 689 # else there will be linking errors. We would remove default_sanitizer_flags 690 # here as well, but gn doesn't permit this. 691 if (!is_msan) { 692 # We don't actually remove sanitization when MSan is being used so there 693 # is no need to add default_sanitizer_ldflags in that case 694 configs = [ ":default_sanitizer_ldflags" ] 695 } 696 } 697 }