| # Copyright 2017 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//build/toolchain/variant.gni") |
| |
| config("frame_pointers") { |
| cflags = [ "-fno-omit-frame-pointer" ] |
| ldflags = cflags |
| } |
| |
| declare_args() { |
| # Default [AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html) |
| # options (before the `ASAN_OPTIONS` environment variable is read at |
| # runtime). This can be set as a build argument to affect most "asan" |
| # variants in `known_variants` (which see), or overridden in |
| # toolchain_args in one of those variants. Note that setting this |
| # nonempty may conflict with programs that define their own |
| # `__asan_default_options` C function. |
| asan_default_options = "" |
| |
| # Default [UndefinedBehaviorSanitizer](https://llvm.org/docs/UndefinedBehaviorSanitizer.html) |
| # options (before the `UBSAN_OPTIONS` environment variable is read at |
| # runtime). This can be set as a build argument to affect most "ubsan" |
| # variants in `known_variants` (which see), or overridden in |
| # toolchain_args in one of those variants. Note that setting this |
| # nonempty may conflict with programs that define their own |
| # `__ubsan_default_options` C function. |
| ubsan_default_options = "print_stacktrace=1" |
| } |
| |
| variant("asan") { |
| common_flags = [ "-fsanitize=address" ] |
| |
| # ASan wants frame pointers because it captures stack traces |
| # on allocations and such, not just on errors. |
| configs = [ ":frame_pointers" ] |
| |
| if (asan_default_options != "") { |
| deps = [ |
| ":asan_default_options", |
| ] |
| } |
| } |
| |
| if (asan_default_options != "") { |
| source_set("asan_default_options") { |
| visibility = [ ":*" ] |
| sources = [ |
| "asan_default_options.c", |
| ] |
| defines = [ "ASAN_DEFAULT_OPTIONS=\"${asan_default_options}\"" ] |
| |
| # On Fuchsia, the ASan runtime is dynamically linked and needs to have |
| # the __asan_default_options symbol exported. On systems where the |
| # ASan runtime is statically linked, it doesn't matter either way. |
| configs -= [ "//build/config:symbol_visibility_hidden" ] |
| } |
| } |
| |
| variant("ubsan") { |
| common_flags = [ "-fsanitize=undefined" ] |
| if (toolchain_variant.name == "asan-ubsan") { |
| ldflags = [ "-Wl,-dynamic-linker,asan-ubsan/ld.so.1" ] |
| } |
| |
| if (ubsan_default_options != "") { |
| deps = [ |
| ":ubsan_default_options", |
| ] |
| } |
| } |
| |
| if (ubsan_default_options != "") { |
| source_set("ubsan_default_options") { |
| visibility = [ ":*" ] |
| sources = [ |
| "ubsan_default_options.c", |
| ] |
| defines = [ "UBSAN_DEFAULT_OPTIONS=\"${ubsan_default_options}\"" ] |
| |
| # On Fuchsia, the UBSan runtime is dynamically linked and needs to have |
| # the __ubsan_default_options symbol exported. On systems where the |
| # UBSan runtime is statically linked, it doesn't matter either way. |
| configs -= [ "//build/config:symbol_visibility_hidden" ] |
| } |
| } |
| |
| variant("fuzzer") { |
| common_flags = [ "-fsanitize=fuzzer" ] |
| |
| # TODO (TC-251): This shouldn't be necessary, but libzircon isn't currently |
| # linked into libFuzzer on Fuchsia. |
| if (is_fuchsia) { |
| libs = [ "zircon" ] |
| } |
| } |
| |
| variant("sancov") { |
| common_flags = [ "-fsanitize-coverage=trace-pc-guard" ] |
| } |