| # Copyright 2018 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/config/scudo/scudo.gni") |
| import("//build/toolchain/variant.gni") |
| |
| # This group is added unconditionally by BUILDCONFIG.gn to pick up the |
| # global `use_scudo` build argument. For fine-grained control, leave |
| # `use_scudo=false` and use `select_variant` to choose the `scudo` |
| # variant for some components. |
| # This configuration will apply to the executable alone, and not any of its |
| # deps. (So most code will not be compiled with Scudo, but executables will |
| # be *linked* with it, which is the important thing.) |
| # Enabling Scudo requires both a configuration change and an additional |
| # dependency; we group them together here. |
| group("default_for_executable") { |
| if (use_scudo && is_fuchsia) { |
| public_configs = [ ":scudo" ] |
| deps = [ |
| ":scudo_default_options", |
| ] |
| } |
| } |
| |
| # This defines the //build/config/scudo config that's used separately |
| # when `use_scudo` is set, as well as making that config (along with |
| # the deps to propagate `scudo_default_options`) into a variant. |
| variant("scudo") { |
| # The variant only works by linking Scudo in. |
| # i.e., we don't support code that relies on `#if __has_feature(scudo)`. |
| ldflags = [ "-fsanitize=scudo" ] |
| deps = [ |
| ":scudo_default_options", |
| ] |
| } |
| |
| source_set("scudo_default_options") { |
| visibility = [ ":*" ] |
| if (scudo_default_options != []) { |
| sources = [ |
| "scudo_default_options.c", |
| ] |
| options_string = "" |
| foreach(option, scudo_default_options) { |
| options_string += ":$option" |
| } |
| defines = [ "SCUDO_DEFAULT_OPTIONS=\"${options_string}\"" ] |
| |
| # The Scudo runtime is dynamically linked and needs to have |
| # the __scudo_default_options symbol exported. |
| configs -= [ "//build/config:symbol_visibility_hidden" ] |
| } |
| } |