blob: 870b1092bd524316d6e55e8e70e3c88d5b6bf0bc [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("//build/test.gni")
import("//build/zircon/migrated_targets.gni")
import("//src/sys/build/fuchsia_unittest_package.gni")
import("$zx/vdso/vdso.gni")
import("$zx_build_config/standard.gni")
import("libc.gni")
assert(libc == get_path_info(get_path_info(".", "abspath"), "dir"),
get_path_info(get_path_info(".", "abspath"), "dir"))
# Each subdirectory listed provides some pieces of libc in a uniform way. The
# main target is a source_set() for libc proper and the "unittests" target is a
# libc_test() suitable for inclusion in libc-unittests and Zircon's core-tests.
libc_components = [
"$zx/third_party/scudo",
"ctype",
]
group("components") {
visibility = [ ":*" ]
deps = libc_components
}
group("unittests") {
testonly = true
deps = []
foreach(subdir, libc_components) {
deps += [ "$subdir:unittests" ]
}
}
# libc.gni uses these configs.
config("internal.config") {
visibility = [ "./*" ]
configs = [ "$zx/third_party/ulib/musl:headers" ]
include_dirs = [ llvm_libc ]
}
config("testonly.config") {
visibility = [ "./*" ]
defines = [ "LLVM_LIBC_TEST_USE_FUCHSIA=1" ]
}
config("llvm-libc-export.config") {
visibility = [ "./*" ]
defines = [
"LLVM_LIBC_PUBLIC_PACKAGING=1",
"LLVM_LIBC_FUNCTION_ATTR=[[gnu::visibility(\"default\")]]",
]
}
if (zx != "/") {
import("//build/toolchain/zircon/zircon_toolchain_suite.gni")
if (current_toolchain == default_toolchain) {
# This introduces a new toolchain suite to mimic the Zircon "user"
# toolchain. Howver, it will only be used to build the C library, so
# is named "user.libc" instead.
foreach(cpu, standard_fuchsia_cpus) {
zircon_toolchain_suite("user.libc_$cpu") {
cpu = cpu
os = "fuchsia"
environment = "user"
with_shared = false
is_pic_default = true
strip = "--strip-sections"
configs = [ "//zircon/system/ulib/c:libc_config" ]
# NOTE: kernel artifacts currently do not build under fuzzer
# variants. This was also true with the Zircon build, but
# the Fuchsia build never invoked it with corresponding
# variant selectors. Using an exclude_variant_tag is
# enough to fix the issue.
exclude_variant_tags = [ "fuzzer" ]
# The Asan-based variants are needed to generate binaries for the SDK.
enable_variants = [
"asan",
"asan-ubsan",
]
}
}
} else if (toolchain_variant.base ==
"//zircon/system/ulib/c:user.libc_$target_cpu") {
config("libc_config") {
configs = [
"$zx_build_config:user",
"$zx_build_config:shared_library_config",
"$zx_build_config:no_undefined_symbols",
]
}
group("libc_config_deps") {
}
}
}
# When built with the default/user Fuchsia toolchain, zx_library()
# will not create a :headers sub-target for zx_library("c") below,
# so add one manually as a special case.
if (zx != "/" && zircon_toolchain == false) {
group("headers") {
public_configs = [
":headers.config",
"$zx/third_party/ulib/musl:headers",
]
}
config("headers.config") {
include_dirs = [ "include" ]
}
}
if (zx != "/" && zircon_toolchain == false) {
import("libc_toolchain.gni")
# When in a toolchain variant of the Fuchsia base toolchain, find the
# corresponding toolchain variant of user.libc_$target_cpu to build
# the C library with it.
_libc_toolchain = sysroot_libc_base_toolchain
if (toolchain_variant.suffix != "") {
_libc_toolchain += string_replace(toolchain_variant.suffix, "-fuzzer", "")
} else {
_libc_toolchain = system_libc_toolchain
}
group("c") {
public_deps = [ ":c($_libc_toolchain)" ]
}
} else {
zx_library("c") {
shared = true
static = false
sdk = "shared"
sdk_headers = []
sdk_migrated = true
# At link time and in DT_SONAME, musl is known as libc.so. But the
# (only) place it needs to be installed at runtime is where the
# PT_INTERP strings embedded in executables point, which is ld.so.1.
install_name = "ld.so.1"
metadata = {
runtime_deps_manifest_lines =
[ "lib/${toolchain.libprefix}ld.so.1=" +
rebase_path("$root_out_dir/libc.so", root_build_dir) ]
}
public_configs = [ "$zx/third_party/ulib/musl:headers" ]
# The code comes from musl, where a source_set is defined.
sources = []
deps = [
":components",
":exit",
"$zx/system/ulib/zx-panic-libc:as_source",
"$zx/third_party/ulib/musl",
"sanitizers",
"setjmp",
"stubs",
"zircon",
]
# Don't link against the shared libc++.
configs += [ "$zx_build_config:static-libc++" ]
}
}
source_set("exit") {
sources = [ "_Exit.cc" ]
deps = [ "$zx/third_party/ulib/musl:musl_internal" ]
}
if (zx != "/" && zircon_toolchain == false) {
# Don't build the C runtime startup object in the Fuchsia user
# toolchain, because this adds many unwanted dependencies to fdio,
# trace-engine and whatnot that are completely un-needed and also
# interfere with sysroot generation. Use the C library toolchain instead.
group("crt1") {
public_deps = [ ":crt1($_libc_toolchain)" ]
}
} else {
source_set("crt1") {
sources = [ "Scrt1.cc" ]
# This runs before all runtime setup.
configs += [ "$zx_build_config:no_sanitizers" ]
# Minimize the code. Even if there were lazy PLT resolution, it's never
# worthwhile to have PLT entries for main or __libc_start_main, since
# they are always used eagerly anyway.
cflags = [ "-fno-plt" ]
}
}
group("tests") {
testonly = true
deps = [
":libc-unittests-pkg",
"test",
]
}
test("libc-unittests") {
deps = [ ":unittests" ]
}
fuchsia_unittest_package("libc-unittests-pkg") {
deps = [ ":libc-unittests" ]
}