| Index: build/config/sanitizers/BUILD.gn
|
| diff --git a/build/config/sanitizers/BUILD.gn b/build/config/sanitizers/BUILD.gn
|
| index 319c272f2380e6a363ccf4d523d98c7477fc5472..65bdbe419fd407b0831dee47339f6e028a582e61 100644
|
| --- a/build/config/sanitizers/BUILD.gn
|
| +++ b/build/config/sanitizers/BUILD.gn
|
| @@ -48,6 +48,11 @@ source_set("options_sources") {
|
| "//build/sanitizers/sanitizer_options.cc",
|
| ]
|
|
|
| + # Don't compile this target with any sanitizer code. It can be called from
|
| + # the sanitizer runtimes, so instrumenting these functions could cause
|
| + # recursive calls into the runtime if there is an error.
|
| + configs -= [ "//build/config/sanitizers:default_sanitizer_flags" ]
|
| +
|
| if (is_asan) {
|
| sources += [ "//build/sanitizers/asan_suppressions.cc" ]
|
| }
|
| @@ -60,3 +65,118 @@ source_set("options_sources") {
|
| sources += [ "//build/sanitizers/tsan_suppressions.cc" ]
|
| }
|
| }
|
| +
|
| +# This config is applied by default to all targets. It sets the compiler flags
|
| +# for sanitizer usage, or, if no sanitizer is set, does nothing.
|
| +#
|
| +# This needs to be in a separate config so that targets can opt out of
|
| +# sanitizers if they desire.
|
| +config("default_sanitizer_flags") {
|
| + cflags = []
|
| + cflags_cc = []
|
| + ldflags = []
|
| + defines = []
|
| +
|
| + # Only works on Posix-like platforms.
|
| + if (is_posix) {
|
| + # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer,
|
| + # MemorySanitizer and non-official CFI builds.
|
| + if (using_sanitizer || (is_cfi && !is_official_build)) {
|
| + cflags += [
|
| + "-fno-omit-frame-pointer",
|
| + "-gline-tables-only",
|
| + ]
|
| + }
|
| + if (is_asan) {
|
| + asan_blacklist_path =
|
| + rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir)
|
| + cflags += [
|
| + "-fsanitize=address",
|
| + "-fsanitize-blacklist=$asan_blacklist_path",
|
| + ]
|
| + if (is_mac) {
|
| + cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
|
| + # TODO(GYP): deal with mac_bundles.
|
| + }
|
| + }
|
| + if (is_lsan) {
|
| + cflags += [ "-fsanitize=leak" ]
|
| + }
|
| + if (is_tsan) {
|
| + tsan_blacklist_path =
|
| + rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir)
|
| + cflags += [
|
| + "-fsanitize=thread",
|
| + "-fsanitize-blacklist=$tsan_blacklist_path",
|
| + ]
|
| + }
|
| + if (is_msan) {
|
| + msan_blacklist_path =
|
| + rebase_path("//tools/msan/blacklist.txt", root_build_dir)
|
| + cflags += [
|
| + "-fsanitize=memory",
|
| + "-fsanitize-memory-track-origins=$msan_track_origins",
|
| + "-fsanitize-blacklist=$msan_blacklist_path",
|
| + ]
|
| + }
|
| + if (is_cfi && !is_nacl) {
|
| + cfi_blacklist_path =
|
| + rebase_path("//tools/cfi/blacklist.txt", root_build_dir)
|
| + cflags += [
|
| + "-flto",
|
| + "-fsanitize=cfi-vcall",
|
| + "-fsanitize=cfi-derived-cast",
|
| + "-fsanitize=cfi-unrelated-cast",
|
| + "-fsanitize-blacklist=$cfi_blacklist_path",
|
| + ]
|
| + ldflags += [
|
| + "-flto",
|
| + "-fsanitize=cfi-vcall",
|
| + "-fsanitize=cfi-derived-cast",
|
| + "-fsanitize=cfi-unrelated-cast",
|
| + ]
|
| +
|
| + # Apply a lower LTO optimization level in non-official builds.
|
| + if (!is_official_build) {
|
| + if (is_linux) {
|
| + ldflags += [ "-Wl,-plugin-opt,O1" ]
|
| + } else if (is_mac) {
|
| + ldflags += [ "-Wl,-mllvm,-O1" ]
|
| + }
|
| + }
|
| +
|
| + # Work-around for http://openradar.appspot.com/20356002
|
| + if (is_mac) {
|
| + ldflags += [ "-Wl,-all_load" ]
|
| + }
|
| +
|
| + # Without this flag, LTO produces a .text section that is larger
|
| + # than the maximum call displacement, preventing the linker from
|
| + # relocating calls (http://llvm.org/PR22999).
|
| + if (current_cpu == "arm") {
|
| + ldflags += [ "-Wl,-plugin-opt,-function-sections" ]
|
| + }
|
| +
|
| + if (use_cfi_diag) {
|
| + cflags += [
|
| + "-fno-sanitize-trap=cfi",
|
| + "-fsanitize-recover=cfi",
|
| + ]
|
| + ldflags += [
|
| + "-fno-sanitize-trap=cfi",
|
| + "-fsanitize-recover=cfi",
|
| + ]
|
| + } else {
|
| + defines += [ "CFI_ENFORCEMENT" ]
|
| + }
|
| + }
|
| +
|
| + if (use_custom_libcxx) {
|
| + cflags_cc += [ "-nostdinc++" ]
|
| + include_dirs = [
|
| + "//buildtools/third_party/libc++/trunk/include",
|
| + "//buildtools/third_party/libc++abi/trunk/include",
|
| + ]
|
| + }
|
| + }
|
| +}
|
|
|