| # 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. |
| |
| 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. |
| asan_default_options = "detect_leaks=1" |
| |
| # Default [UndefinedBehaviorSanitizer](https://clang.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:halt_on_error=1" |
| } |
| |
| template("sanitizer") { |
| config(target_name) { |
| forward_variables_from(invoker, "*", ["deps"]) |
| |
| asmflags = common_flags |
| cflags = common_flags |
| ldflags = common_flags |
| } |
| |
| if (defined(invoker.deps)) { |
| group("${target_name}_deps") { |
| deps = invoker.deps |
| } |
| } |
| } |
| |
| config("frame_pointers") { |
| cflags = [ "-fno-omit-frame-pointer" ] |
| ldflags = cflags |
| } |
| |
| sanitizer("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" ] |
| |
| deps = [ ":asan_default_options" ] |
| } |
| |
| source_set("asan_default_options") { |
| visibility = [ ":*" ] |
| sources = [ "asan_default_options.c" ] |
| defines = [ "ASAN_DEFAULT_OPTIONS=\"${asan_default_options}\"" ] |
| } |
| |
| sanitizer("ubsan") { |
| common_flags = [ |
| "-fsanitize=undefined", |
| |
| # vptr sanitizer is not compatible with no_rtti. |
| "-fno-sanitize=vptr", |
| |
| # The protoc has some of these, disabling for now. |
| "-fno-sanitize=nonnull-attribute", |
| ] |
| |
| deps = [ ":ubsan_default_options" ] |
| } |
| |
| source_set("ubsan_default_options") { |
| visibility = [ ":*" ] |
| sources = [ "ubsan_default_options.c" ] |
| defines = [ "UBSAN_DEFAULT_OPTIONS=\"${ubsan_default_options}\"" ] |
| } |
| |
| sanitizer("sancov") { |
| common_flags = [ "-fsanitize-coverage=trace-pc-guard" ] |
| } |