blob: 46204d12c4901417abb0e6a48f82b11b75f1bee0 [file] [log] [blame]
# Copyright 2019 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("../libc.gni")
if (zircon_toolchain != false) {
source_set("sanitizers") {
deps = [
":backtrace",
"//sdk/lib/fidl_base",
"//zircon/system/ulib/zircon-internal",
"//zircon/system/ulib/zx",
"//zircon/third_party/ulib/musl:musl_internal",
]
sources = [
"__asan_early_init.c",
"__sanitizer_fast_backtrace.cc",
"asan-stubs.c",
"debugdata.cc",
"hooks.c",
"hwasan-stubs.cc",
"log.c",
"memory-snapshot.cc",
"ubsan-stubs.cc",
]
# There is no '#if __has_feature(coverage)', so this has to be excluded
# from the build entirely when not in use. Each variant that includes
# some -fsanitize-coverage=... switches in its configs must use the
# "sancov" tag so this code can detect it.
if (toolchain_variant.tags + [ "sancov" ] - [ "sancov" ] !=
toolchain_variant.tags) {
deps += [ ":sancov-stubs" ]
}
}
# This code is only needed when compiling for sancov, but the file itself
# must be compiled without instrumentation of any kind.
source_set("sancov-stubs") {
visibility = [ ":*" ]
sources = [ "sancov-stubs.cc" ]
configs += [ "//build/config/sanitizers:no_sanitizers" ]
}
}
libc_source_set("backtrace") {
sources = [ "backtrace.cc" ]
public = [ "backtrace.h" ]
public_deps = [ "//sdk/lib/stdcompat" ]
deps = [
"//zircon/kernel/lib/arch",
"//zircon/third_party/ulib/musl:musl_internal",
]
# Always compile with frame pointers so that BacktraceByFramePointer reliably
# has one for its own caller's frame to show up in the backtrace.
if (defined(configs)) {
configs -= [ "//build/config:default_frame_pointers" ]
} else {
configs = []
}
remove_configs = [ "//build/config:default_frame_pointers" ]
configs += [ "//build/config:frame_pointers" ]
}
libc_test("unittests") {
sources = [ "backtrace-tests.cc" ]
remove_configs = [ "//build/config:default_frame_pointers" ]
configs = [ "//build/config:frame_pointers" ]
deps = [
":backtrace.testonly",
"//zircon/system/ulib/zxtest",
]
# This is hack! Approximate guess for whether zxtest and libc will have been
# compiled with frame pointers.
incomplete_fp = !is_debug
defines = [ "INCOMPLETE_FRAME_POINTERS=$incomplete_fp" ]
}