| # 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/components.gni") |
| import("//build/config/zircon/standard.gni") |
| import("//build/test.gni") |
| import("//build/zircon/migrated_targets.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 = [ |
| "ctype", |
| "scudo", |
| ] |
| |
| 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 = [ "//zircon/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\")]]", |
| ] |
| } |
| |
| 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 = [ |
| "//build/config/zircon:user", |
| "//build/config/zircon:shared_library_config", |
| "//build/config/zircon: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 (zircon_toolchain == false) { |
| group("headers") { |
| public_configs = [ |
| ":headers.config", |
| "//zircon/third_party/ulib/musl:headers", |
| ] |
| } |
| |
| config("headers.config") { |
| include_dirs = [ "include" ] |
| } |
| |
| 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 = [ "//zircon/third_party/ulib/musl:headers" ] |
| |
| # The code comes from musl, where a source_set is defined. |
| sources = [] |
| |
| deps = [ |
| ":components", |
| ":exit", |
| "sanitizers", |
| "setjmp", |
| "stubs", |
| "zircon", |
| "//zircon/system/ulib/zx-panic-libc:as_source", |
| "//zircon/third_party/ulib/musl", |
| ] |
| |
| # Don't link against the shared libc++. |
| configs += [ "//build/config/zircon:static-libc++" ] |
| } |
| } |
| |
| source_set("exit") { |
| sources = [ "_Exit.cc" ] |
| deps = [ "//zircon/third_party/ulib/musl:musl_internal" ] |
| } |
| |
| if (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 += [ "//build/config/zircon: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" ] |
| } |