blob: a9b3a7e8072b1f00d6c1d5c37cd06a4a2cb489c3 [file] [log] [blame]
# Copyright 2019 The Fuchsia Authors
#
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT
import("//build/config/zircon/standard.gni")
import("//build/testing/zbi_test_success.gni")
import("//build/toolchain/toolchain_environment.gni")
import("//build/toolchain/zircon/zircon_toolchain_suite.gni")
import("//build/zircon/c_utils.gni")
# userboot gets its own toolchain for its special build requirements.
if (current_toolchain == default_toolchain) {
# Define the special toolchain itself only in the default toolchain.
foreach(cpu, standard_fuchsia_cpus) {
zircon_toolchain_suite("userboot_$cpu") {
cpu = cpu
os = "fuchsia"
environment = "userboot"
configs = [
"//zircon/kernel/lib/userabi/userboot:userboot_config",
# TODO(fxbug.dev/48501): This is needed pervasively and not just
# in the linking target so its compile-time flags can
# work around fxbug.dev/48501. It's separate from
# userboot_config so it can be removed by other links
# reusing this environment, e.g. hermetic_module().
"//build/config/zircon:rodso",
]
# This doesn't get a separate shlib sub-toolchain, but the main one
# can do loadable_module().
with_shared = false
is_pic_default = true
toolchain_args = {
if (optimize == "none" || optimize == "debug") {
# userboot doesn't stay sufficiently pure without optimization.
optimize = "default"
}
# No runtime to print asserts, so can't compile them in.
zx_assert_level = 0
}
# userboot can't use any instrumentation runtimes.
exclude_variant_tags = [ "instrumented" ]
}
}
}
if (toolchain_environment == "userboot") {
# Everything in userboot gets compiled this way.
config("userboot_config") {
configs = [
"//build/config/zircon:user",
"//build/config/zircon:static-libc++",
"//build/config/sanitizers:no_sanitizers",
"//build/config:symbol_no_undefined",
]
cflags = [
# -fPIE is the default in Clang, but not in GCC.
"-fpie",
# Everything is statically linked together with no PLT or GOT.
# No $inputs needed here since the depfile will list it.
"-include",
rebase_path("//zircon/kernel/include/hidden.h", root_build_dir),
]
defines = [ "HIDDEN" ]
}
group("userboot_config_deps") {
}
# This is the output of target ":gen-vdso-syms-ld", below.
vdso_syms_ld = "$target_gen_dir/vdso-syms.ld"
# userboot is a reentrant DSO (no writable segment) with an entry point.
loadable_module("userboot") {
sources = [
"bootfs.cc",
"loader-service.cc",
"option.cc",
"start.cc",
"userboot-elf.cc",
"util.cc",
"zbi.cc",
"zx_panic.cc",
]
defines = [ "ZBI_TEST_SUCCESS_STRING=\"$zbi_test_success_string\"" ]
ldflags = [ "-Wl,-e,_start" ]
libs = [ vdso_syms_ld ]
deps = [
":gen-vdso-syms-ld",
"//src/zircon/lib/zircon",
"//zircon/kernel/lib/boot-options",
"//zircon/kernel/lib/userabi:headers",
"//zircon/system/ulib/elf-psabi",
"//zircon/system/ulib/elfload",
"//zircon/system/ulib/fbl",
"//zircon/system/ulib/fidl",
"//zircon/system/ulib/ldmsg",
"//zircon/system/ulib/processargs",
"//zircon/system/ulib/zbitl",
"//zircon/system/ulib/zircon-internal",
"//zircon/system/ulib/zx",
"//zircon/third_party/ulib/musl/src/exit:abort",
"//zircon/third_party/ulib/musl/src/string:minimal_str",
"//zircon/third_party/ulib/musl/src/string:stdmem",
]
}
# This generated header lists all the ABI symbols in the vDSO with their
# addresses. It's used to generate vdso-syms.ld, below.
toolchain_utils_action("gen-vdso-syms-header") {
visibility = [ ":gen-vdso-syms-ld" ]
# Use the same link_output_rspfile() that lib/userabi uses to embed it,
# so we're sure to be getting the exact same binary.
deps = [ "//zircon/kernel/lib/userabi:vdso.rsp" ]
vdso_gen_dir = get_label_info(deps[0], "target_gen_dir")
sources = [ "$vdso_gen_dir/vdso.rsp" ]
outputs = [ "$target_gen_dir/vdso-syms.h" ]
depfile = "${outputs[0]}.d"
utils = [ "nm" ]
script = "//zircon/scripts/shlib-symbols"
args = [
"-a",
"@" + rebase_path(sources[0], root_build_dir),
rebase_path(outputs[0], root_build_dir),
rebase_path(depfile, root_build_dir),
]
metadata = {
generated_sources = rebase_path(outputs, root_build_dir)
}
}
# This generated linker script defines symbols for each vDSO entry point
# giving the relative address where it will be found at runtime. With
# this hack, the userboot code doesn't need to do any special work to
# find the vDSO and its entry points, keeping the code far simpler.
toolchain_utils_action("gen-vdso-syms-ld") {
visibility = [ ":*" ]
outputs = [ vdso_syms_ld ]
deps = [ ":gen-vdso-syms-header" ]
sources = get_target_outputs(deps[0])
inputs = [ "vdso-syms.ld.h" ]
utils = [ "cc" ]
args = [
"-o",
rebase_path(outputs[0], root_build_dir),
"-E",
"-P",
"-include",
rebase_path(inputs[0], root_build_dir),
rebase_path(sources[0], root_build_dir),
]
}
} else {
group("userboot") {
public_deps = [
":userboot(//zircon/kernel/lib/userabi/userboot:userboot_${target_cpu})",
]
}
}