blob: 1270620e3d794e5954f8f300a8c87453b226f139 [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("$zx/vdso/vdso.gni")
import("$zx_build/public/gn/migrated_targets.gni")
import("$zx_build_config/standard.gni")
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"
toolchain_variant_args = {
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 == "/") {
import("sysroot_entries.gni")
}
if (zx != "/" && zircon_toolchain == false) {
group("c") {
public_deps = [ ":c(//zircon/system/ulib/c:user.libc_$target_cpu)" ]
}
} else {
zx_library("c") {
shared = true
static = false
sdk = "shared"
sdk_headers = []
sdk_migrated = true
if (zx == "/") {
# 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_path = "lib/${toolchain.libprefix}ld.so.1"
} else {
# TODO(60613): Enable this once the sysroot moves entirely to the Fuchsia build.
# 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 = [
":exit",
"$zx/system/ulib/zx-panic-libc:as_source",
"$zx/third_party/scudo",
"$zx/third_party/ulib/musl",
"sanitizers",
"setjmp",
"stubs",
"zircon",
]
if (zx == "/") {
# Suppress the ${toolchain.implicit_deps} that points back to here.
no_implicit_deps = true
}
# Don't link against the shared libc++.
configs += [ "$zx_build_config:static-libc++" ]
if (zx == "/") {
libc_stripped = "$target_out_dir/libc.so"
} else {
libc_stripped = "$root_build_dir/libc.so"
}
libc_unstripped = libc_stripped + ".debug"
rebased_libc_stripped = rebase_path(libc_stripped, root_build_dir)
rebased_libc_unstripped = rebase_path(libc_unstripped, root_build_dir)
not_needed([
"rebased_libc_stripped",
"rebased_libc_unstripped",
])
if (zx == "/") {
metadata = {
# TODO(BLD-353): temporary kludges; see //zircon/public/sysroot
legacy_sysroot = sysroot_instrumented_libc_entries
if (toolchain.tags + [ "instrumented" ] - [ "instrumented" ] ==
toolchain.tags) {
legacy_sysroot += sysroot_uninstrumented_libc_entries
}
}
}
}
}
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.
group("crt1") {
public_deps = [ ":crt1(//zircon/system/ulib/c:user.libc_$current_cpu)" ]
}
} 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" ]
if (zx == "/") {
metadata = {
# TODO(fxbug.dev/3156): temporary kludges
if (toolchain.tags + [ "instrumented" ] - [ "instrumented" ] ==
toolchain.tags) {
legacy_sysroot = sysroot_crt1_entries
}
}
}
}
}
group("tests") {
testonly = true
deps = [ "test" ]
}