blob: a83d23465faf8b142cfaf2fa41d3ad3fbd7a04b9 [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/config/build_id.gni")
import("//build/config/clang/clang.gni")
import("//build/config/clang/crash_diagnostics.gni")
import("//build/config/compiler.gni")
import("//build/config/linker.gni")
import("//build/config/zircon/levels.gni")
import("//build/toolchain/variant.gni")
# NOTE: This file provides the GN configs used by Zircon toolchains
# exclusively. See //build/toolchain/zircon/zircon_toolchain.gni.
#
# They come from a rewrite of the configs from the old Zircon build.
# Major differences in the rewrite:
#
# - Uses |zircon_toolchain| global variable, instead of |toolchain|.
#
# - All code paths related to |is_host| has been removed (the Zircon toolchain
# are never used to build host binaries).
#
# - There are many configs here that redirect to an equivalent config
# defined in //build/config/BUILD.gn. These are necessary to ensure
# that build commands between the Zircon and Fuchsia builds are equivalent,
# as verified by //zircon/public/canaries/compare_toolchains.py, because
# the order of entries in `configs` list must be the same, even after
# a `gn format` pass.
#
# I.e. compare:
#
# configs = [
# "//build/config/zircon:default_include_dirs",
# "//build/config/zircon:relative_paths",
# ]
#
# Which corresponds to the original configs list as it appeared in the
# Zircon build, with:
#
# configs = [
# "//build/config:relative_paths",
# "//build/config/zircon:default_include_dirs",
# ]
#
# Which is the properly formatted equivalent, when not using intermediate
# configs here. Because the entries appear in different order, the build
# commands will place tool flags in different position, making comparison
# much more difficult.
#
# Once the build is unified, these intermediate configs will be removed
# since the order of build tool parameters is only important to minimize
# surprises during unification.
#
# These flags are enabled by default in Fuchsia's Clang toolchain, but we set
# them explicitly to support other Clang toolchains and Clang-based tools.
config("clang_defaults") {
cflags = [ "-fexperimental-new-pass-manager" ]
asmflags = cflags
ldflags = cflags
if (clang_embed_bitcode) {
cflags += [
"-Xclang",
"-fembed-bitcode=all",
]
}
if (current_cpu == "x64") {
asmflags += [ "-Wa,--mrelax-relocations=yes" ]
}
if (current_os == "linux") {
cflags_cc = [ "-stdlib=libc++" ]
ldflags += [
"-stdlib=libc++",
"-unwindlib=",
"-rtlib=compiler-rt",
]
}
}
config("compiler") {
compiler_flags = []
defines = []
ldflags = []
# NOTE: This config should only be used with Zircon-specific toolchains
# but this BUILD.gn file is also included from non-Zircon ones. To
# avoid un-necessary GN errors, define a fake local zircon_toolchain
# scope to ensure this config() definitions executes properly even if
# it is never used.
if (zircon_toolchain == false) {
zircon_toolchain = {
target_tuple = ""
version_string = ""
include_dirs = []
lib_dirs = []
}
}
# For GCC, the compiler command implies the target.
# For Clang, there's a single compiler command that takes `--target`.
if (!is_gcc) {
compiler_flags += [ "--target=${zircon_toolchain.target_tuple}" ]
}
if (linker != "") {
ldflags += [ "-fuse-ld=$linker" ]
}
if (defined(zircon_toolchain.version_string) &&
zircon_toolchain.version_string != "") {
# Nothing uses this define, but its presence on compilation command
# lines ensures that Ninja will rebuild things when a new compiler
# version arrives.
defines += [ "TOOLCHAIN_VERSION=${zircon_toolchain.version_string}" ]
}
# This is the default already on Fuchsia and maybe others, but never hurts.
cflags = [ "-fno-common" ]
configs = [
"//build/config:color_diagnostics",
# TODO: "$current_os:compiler",
]
if (!is_gcc) {
configs += [ ":clang_defaults" ]
}
if (is_fuchsia) {
# TODO(mcgrathr): These should all be default in the compiler driver.
ldflags += [
"-Wl,-z,combreloc",
"-Wl,-z,relro",
"-Wl,-z,now",
"-Wl,-z,text",
]
if (is_gcc) {
# This is predefined by Clang --target=*-fuchsia.
# But the GCC toolchain is the generic --target=*-elf one.
defines += [ "__Fuchsia__" ]
# These are done by default in the Clang toolchain.
cflags += [ "-fasynchronous-unwind-tables" ]
ldflags += [
"-Wl,--build-id",
"-Wl,--eh-frame-hdr",
"-Wl,--hash-style=gnu",
]
# In the Clang toolchain assembly files with no explicit marker don't
# cause the presumption of executable stack as they do in GCC.
ldflags += [ "-Wl,-z,noexecstack" ]
} else {
# gcc defaults to enabling sized deallocation >= c++14; clang does not.
# Enable sized-deallocation for the kernel, so the heap implementation can
# optimize for or check generated sizes.
cflags += [ "-fsized-deallocation" ]
# TODO(mcgrathr): This should be default in the compiler driver.
ldflags += [ "-Wl,--pack-dyn-relocs=relr" ]
configs += [ "//build/config/fuchsia:compiler_relative_vtables" ]
}
if (current_cpu == "arm64") {
# Generate code for the fairly generic cortex-a53.
compiler_flags += [ "-mcpu=cortex-a53" ]
# x18 is reserved in the Fuchsia ABI so it can be used
# for things like -fsanitize=shadow-call-stack.
compiler_flags += [ "-ffixed-x18" ]
if (is_gcc) {
# By default GCC 10 will generate outcalls to libgcc functions that can
# do runtime switching between old and new atomic insns. We want just
# old atomic insns inline instead. Eventually we'll have builds using
# -march=armv8.1-a or better, which should get new atomic insns inline
# regardless of this switch.
cflags += [ "-mno-outline-atomics" ]
}
} else if (current_cpu == "x64") {
# Let the compiler generate the cmpxchg16b instruction.
compiler_flags += [ "-mcx16" ]
if (!is_gcc) {
# TODO(fxrev.dev/485257): Enable for GCC when it supports march=x86-64-v2
compiler_flags += [ "-march=x86-64-v2" ]
} else {
compiler_flags += [ "-march=x86-64" ]
}
}
} else if (current_os == "win") {
# This enables build ID-like PDB UUIDs without timestamp.
ldflags += [ "-Wl,/Brepro" ]
}
if (!is_gcc && crash_diagnostics_dir != "") {
compiler_flags += [ "-fcrash-diagnostics-dir=" +
rebase_path(crash_diagnostics_dir, root_build_dir) ]
}
# The toolchain-supplied headers come after include_dirs from targets and
# configs but before libc.
foreach(dir, zircon_toolchain.include_dirs) {
compiler_flags += [
"-isystem",
rebase_path(dir, root_build_dir),
]
}
lib_dirs = zircon_toolchain.lib_dirs
asmflags = compiler_flags
cflags += compiler_flags
ldflags += compiler_flags
if (is_fuchsia && build_id_format != "") {
ldflags += [ "-Wl,--build-id=$build_id_format" ]
}
}
# NOTE: Do not remove this until unification completes (see explanation above).
config("language") {
configs = [ "//build/config:language" ]
}
# NOTE: Do not remove this until unification completes (see explanation above).
config("relative_paths") {
configs = [ "//build/config:relative_paths" ]
}
config("nolibc") {
ldflags = [ "-nostartfiles" ]
# Don't use -nostdlib, because the builtins (or libgcc) are what we want
# and are otherwise annoying to find and specify. It's just the -lc that
# we really want to defeat, and that's handled by giving a -L that will
# find exactly nothing but a dummy libc.so. Clang has -nolibc to kill
# the -lc, but for C++ it still uses -lm under -nolibc. So this is still
# needed to make -lm into a dummy, though for -lc only GCC needs it.
lib_dirs = [ "libc-dummy" ]
if (is_gcc) {
# Include this in every link.
# Note GN requires "./" so it doesn't think this should mean a -l switch.
libs = [ "./dso_handle.ld" ]
} else {
# TODO(mcgrathr): GCC 9 has -nolibc, so use it when we get that toolchain.
ldflags += [ "-nolibc" ]
}
}
config("freestanding") {
cflags = [ "-ffreestanding" ]
# In Clang -fasynchronous-unwind-tables is the default for *-fuchsia
# targets. But -ffreestanding defeats that (in target-independent logic
# in the Clang driver). So add it back explicitly. For GCC, it's
# already added explicitly in :compiler regardless so don't double it.
if (!is_gcc) {
cflags += [ "-fasynchronous-unwind-tables" ]
}
ldflags = cflags
}
config("data_sections") {
cflags = [ "-fdata-sections" ]
ldflags = cflags
}
config("linker_gc") {
configs = [ ":data_sections" ]
cflags = [ "-ffunction-sections" ]
ldflags = cflags
if (current_os == "mac") {
ldflags += [ "-Wl,-dead_strip" ]
} else if (current_os == "win") {
ldflags += [ "-Wl,/opt:ref" ]
} else {
ldflags += [ "-Wl,--gc-sections" ]
}
}
group("linker_gc_deps") {
}
# The 'default_assert_level' will point to one of the assert_level_XXX values
# below. This allows targets or toolchains to opt out from the default and
# select a specific value.
config("assert_level_0") {
defines = [
"ZX_ASSERT_LEVEL=0",
"NDEBUG",
]
}
group("assert_level_0_deps") {
}
config("assert_level_1") {
defines = [ "ZX_ASSERT_LEVEL=1" ]
}
group("assert_level_1_deps") {
}
config("assert_level_2") {
defines = [ "ZX_ASSERT_LEVEL=2" ]
}
group("assert_level_2_deps") {
}
config("default_assert_level") {
assert(
zx_assert_level >= 0 && zx_assert_level <= 2,
"Invalid zx_assert_level value '$zx_assert_level', valid values are 0, 1 or 2")
configs = [ ":assert_level_$zx_assert_level" ]
}
group("default_assert_level_deps") {
# Implicit dependencies for 'default_assert_level' config.
}
config("linker_string_merging") {
if (current_os == "win") {
ldflags = [ "-Wl,/opt:lldtailmerge" ]
} else if (current_os != "mac") {
ldflags = [ "-Wl,-O2" ]
}
}
# IMPORTANT: //build/config/BUILD.gn also defines a list of optimize_${level}
# configs, but some of them have slightly different values. Until build
# unification completes, the configs below should match the Zircon build
# values instead.
config("optimize_none") {
configs = [ "//build/config:optimize_none" ]
}
# NOTE: //build/config:optimize_debug is slightly different.
config("optimize_debug") {
cflags = [ "-Og" ]
ldflags = cflags
rustflags = [ "-Copt-level=1" ]
}
config("optimize_default") {
configs = [ "//build/config:optimize_default" ]
}
config("optimize_size") {
configs = [ "//build/config:optimized_size" ]
}
# NOTE: //build/config:optimize_speed is slightly different.
config("optimize_speed") {
cflags = [ "-O3" ]
ldflags = cflags
rustflags = [ "-Copt-level=3" ]
configs = [ ":linker_string_merging" ]
}
config("optimize_sanitizer") {
configs = [ "//build/config:optimize_sanitizer" ]
}
config("optimize_profile") {
# NOTE: Unlike //build/config:optimize_profile", this must always enable
# optimizations to ensure userboot.so is compiled with -O2
# See https://fxbug.dev/67467 for more context.
configs = [ "//build/config:optimize_default" ]
}
config("optimize_coverage") {
# NOTE: Unlike //build/config:optimize_coverage", this must always enable
# optimizations to ensure userboot.so is compiled with -O2
# See https://fxbug.dev/67467 for more context.
configs = [ "//build/config:optimize_default" ]
}
config("default_optimize") {
configs = [ ":optimize_${optimize}" ]
}
config("linker_gc_none") {
# No linker GC when wholly unoptimized.
}
# Linker GC is a good default for most cases.
config("linker_gc_debug") {
configs = [ ":linker_gc" ]
}
config("linker_gc_default") {
configs = [ ":linker_gc" ]
}
config("linker_gc_size") {
configs = [ ":linker_gc" ]
}
config("linker_gc_speed") {
configs = [ ":linker_gc" ]
}
config("linker_gc_sanitizer") {
configs = [ ":linker_gc" ]
}
config("linker_gc_profile") {
# TODO(fxbug.dev/51509): See if we can enable linker GC for profile.
}
config("default_linker_gc") {
configs = [ ":linker_gc_${optimize}" ]
}
# This is separate from default_optimize so it can be removed.
config("default_icf") {
if (optimize != "none" && optimize != "debug") {
# Our code should never rely on C's unique function pointer semantics,
# which is broken by --icf=all for sometimes substantial space savings.
configs = [ ":icf" ]
}
}
# Each of the debuginfo_$debuginfo configs below corresponds to a single setting
# that controls the amount of debugging information used and is controlled by
# the debuginfo argument. The default_debuginfo level is set to
# debuginfo_$debuginfo for convenience, but individual targets can override
# their debuginfo level by manually applying one of the configs below.
# Keep in sync with //build/config/BUILD.gn
config("debuginfo_none") {
configs = [ "//build/config:debuginfo_none" ]
}
config("debuginfo_backtrace") {
configs = [ "//build/config:debuginfo_backtrace" ]
}
config("debuginfo_debug") {
configs = [ "//build/config:debuginfo_debug" ]
}
config("default_debuginfo") {
configs = [ "//build/config:default_debuginfo" ]
}
config("werror") {
cflags = [
"-Werror",
# Declarations marked as deprecated should not cause build failures.
# Rather they should emit warnings to notify developers about the use
# of deprecated interfaces.
"-Wno-error=deprecated-declarations",
# Do not add additional `-Wno-error=...` switches to this config!
]
asmflags = [ "-Wa,--fatal-warnings" ]
cflags += asmflags
if (current_os == "win") {
ldflags = [ "-Wl,/WX" ]
}
}
config("default_warnings") {
cflags = [
"-Wall",
"-Wextra",
"-Wno-unused-parameter",
# TODO(fxbug.dev/37765): Temporarily disable this warning to unblock the GCC roll.
"-Wno-address-of-packed-member",
]
cflags_c = [
"-Wstrict-prototypes",
"-Wwrite-strings",
]
cflags_cc = [
"-Wconversion",
"-Wno-sign-conversion",
"-Wextra-semi",
# TODO(fxbug.dev/38640): Temporarily disable this warning to unblock the GCC roll.
"-Wno-deprecated-copy",
]
if (is_gcc) {
cflags += [
"-Wno-nonnull-compare",
"-Wno-format-truncation",
]
cflags_cc += [
# TODO(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036): Re-enable
# once the bug is fixed.
"-Wno-format-overflow",
# TODO(fxbug.dev/64272): Disable "-Wmissing-field-initializers" which
# warns when designated initializers are used on some (but not all)
# fields in C++, contrary to its documentation (and Clang).
"-Wno-missing-field-initializers",
]
} else {
cflags += [
"-Wnewline-eof",
# TODO(fxbug.dev/35965): Temporarily disable C99 designator warnings introduced in
# https://reviews.llvm.org/D59754. After the new Clang toolchain lands
# and we do some cleanup, this will be re-enabled.
"-Wno-unknown-warning-option",
"-Wno-c99-designator",
# TODO(fxbug.dev/37215): Temporarily disable this warning until we roll toolchain.
# Then we can re-enable it and cleanup instances it appears.
"-Wno-int-in-bool-context",
# TODO(fxbug.dev/43681): Temporarily disable this warning until we roll toolchain,
# then come back and fix the instances this appears after rolling.
"-Wno-range-loop-analysis",
]
cflags_cc += [
# TODO(fxbug.dev/45689): Temporarily disable this warning until we roll toolchain,
# then come back and fix the instances this appears after rolling.
"-Wno-non-c-typedef-for-linkage",
]
}
}
config("Wno-unused-function") {
cflags = [ "-Wno-unused-function" ]
visibility = [
"//zircon/third_party/ulib/musl/ldso",
"//zircon/third_party/ulib/musl/src/network",
"//zircon/third_party/ulib/musl/src/time",
]
}
# TODO(fxbug.dev/58162): clean up usages of this config
config("Wno-conversion") {
# NOTE: Use individual cflags_cc and cflags_c here because these
# need to appear _after_ the -Wconversion in default_warnings above.
cflags_cc = [ "-Wno-conversion" ]
cflags_c = cflags_cc
visibility = [
"//sdk/lib/fit/*",
"//third_party/lz4/*",
"//tools/fidl/fidlc/*",
"//zircon/kernel/arch/x86/*",
"//zircon/kernel/arch/x86/cpuid/*",
"//zircon/kernel/debugcommands/*",
"//zircon/kernel/dev/iommu/dummy/*",
"//zircon/kernel/dev/pcie/*",
"//zircon/kernel/lib/cmdline/*",
"//zircon/kernel/lib/console",
"//zircon/kernel/lib/heap/cmpctmalloc/*",
"//zircon/kernel/object/*",
"//zircon/kernel/phys/*",
"//zircon/kernel/platform/*",
"//zircon/kernel/tests/*",
"//zircon/kernel/vm/*",
"//zircon/system/ulib/cmdline/*",
"//zircon/system/ulib/elf-psabi/*",
"//zircon/system/ulib/elfload/*",
"//zircon/system/ulib/fidl/*",
"//zircon/system/ulib/gfx/*",
"//zircon/system/ulib/hwreg/*",
"//zircon/system/ulib/ldmsg/*",
"//zircon/system/ulib/pretty/*",
"//zircon/system/ulib/tftp/*",
"//zircon/system/ulib/zbi/*",
"//zircon/system/ulib/zxc/*",
"//zircon/system/ulib/zxtest/*",
"//zircon/third_party/*",
"//zircon/third_party/ulib/cksum/*",
"//zircon/third_party/ulib/usbhost/*",
"//zircon/tools/kazoo/*",
"//zircon/tools/zbi/*",
]
}
config("warn-implicit-fallthrough") {
cflags = [ "-Wimplicit-fallthrough" ]
}
config("default_template_backtrace_limit") {
cflags_cc = [ "-ftemplate-backtrace-limit=0" ]
}
config("icf") {
# This changes C/C++ semantics and might be incompatible with third-party
# code that relies on function pointers comparison.
if (current_os == "win" && (linker == "lld" || !is_gcc)) {
ldflags = [ "-Wl,/opt:icf=all" ]
} else if (linker == "gold" || linker == "lld") {
ldflags = [ "-Wl,--icf=all" ]
}
}
config("exceptions") {
configs = [ "//build/config:exceptions" ]
}
config("no_exceptions") {
configs = [ "//build/config:no_exceptions" ]
}
config("rtti") {
configs = [ "//build/config:rtti" ]
}
config("no_rtti") {
configs = [ "//build/config:no_rtti" ]
}
config("no_threadsafe_statics") {
cflags_cc = [ "-fno-threadsafe-statics" ]
cflags_objcc = cflags_cc
}
config("default_include_dirs") {
include_dirs = [ "//zircon/system/public" ]
}
config("default_frame_pointers") {
if (zx_assert_level > 0) {
configs = [ ":frame_pointers" ]
} else {
configs = [ ":no_frame_pointers" ]
}
}
# NOTE: //build/config:frame_pointers exists but is different!
config("frame_pointers") {
defines = [ "WITH_FRAME_POINTERS=1" ]
cflags = [ "-fno-omit-frame-pointer" ]
}
group("frame_pointers_deps") {
}
# NOTE: //build/config:no_frame_pointers exists but is different!
config("no_frame_pointers") {
defines = [ "WITH_FRAME_POINTERS=0" ]
cflags = [ "-fomit-frame-pointer" ]
}
# NOTE: //build/config:thread_safety_annotations is slightly different
config("thread_safety_annotations") {
if (!is_gcc) {
cflags = [ "-Wthread-safety" ]
defines = [ "_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS=1" ]
}
}
config("no_stack_protector") {
cflags = [ "-fno-stack-protector" ]
}
config("no_safestack") {
if (!is_gcc) {
cflags = [ "-fno-sanitize=safe-stack" ]
}
configs = [ ":no_stack_protector" ]
}
group("no_safestack_deps") {
# Each config added to a zircon_toolchain_suite() must have a corresponding
# _deps group listing implicit dependencies if needed.
}
config("no-shadow-call-stack") {
if (current_cpu == "arm64" && !is_gcc) {
cflags = [ "-fno-sanitize=shadow-call-stack" ]
}
}
config("no_sanitizers") {
cflags = [ "-fno-sanitize=all" ]
if (!is_gcc) {
cflags += [ "-fsanitize-coverage=0" ]
}
configs = [ ":no_stack_protector" ]
}
config("no_fuzzer") {
if (!is_gcc) {
cflags = [ "-fno-sanitize=fuzzer" ]
}
}
# TODO(fxbug.dev/27266) Remove this once the warning with fit::variant is addressed.
config("no_maybe_uninitialized") {
if (is_gcc) {
cflags = [ "-Wno-maybe-uninitialized" ]
}
}
# Compile code appropriately to be linked into a shared library.
config("shared_library_config") {
if (current_os != "mac") {
# Assembly code can use `#ifdef __PIC__`.
compiler_flags = [ "-fPIC" ]
asmflags = compiler_flags
cflags = compiler_flags
ldflags = compiler_flags
}
}
# Don't allow dangling undefined references in shared libraries.
# All references should be satisfied by link-time library dependencies.
config("no_undefined_symbols") {
if (current_os == "mac") {
ldflags = [ "-Wl,-undefined,error" ]
} else {
ldflags = [ "-Wl,-z,defs" ]
}
}
config("visibility_hidden") {
cflags = [ "-fvisibility=hidden" ]
cflags_cc = [ "-fvisibility-inlines-hidden" ]
# Disable libc++ visibility annotations to make sure that the compiler option
# has effect on symbols defined in libc++ headers. Note that we don't want to
# disable these annotations altogether to ensure that our toolchain is usable
# outside of our build since not every user uses hidden visibility by default.
defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ]
}
config("machine") {
ldflags = []
if (current_cpu == "arm64" && current_os != "win") {
# The linker rewrites instructions to work around a CPU bug.
ldflags += [ "-Wl,--fix-cortex-a53-843419" ]
}
if (is_fuchsia) {
# TODO(fxbug.dev/32157): Really need to get this nailed down once and for all
# and set by default in the compiler driver (Clang at least).
ldflags += [ "-Wl,-z,max-page-size=4096" ]
}
}
# TODO(fxbug.dev/54322): Use the config under //third_party/ulib/musl once the C
# library has been migrated to the GN build.
config("musl_headers") {
_musl_dir = "//zircon/third_party/ulib/musl"
visibility = [
"${_musl_dir}/*",
"//zircon/system/ulib/c:*",
]
cflags = [
"-idirafter",
rebase_path("${_musl_dir}/include", root_build_dir),
]
asmflags = cflags
}
config("user") {
defines = [ "_ALL_SOURCE" ]
configs = [
":nolibc",
":musl_headers",
]
}
config("user_executable") {
# NOTE: Was only used in the 'user' Zircon build environment, which is
# implemented by the Fuchsia build using the 'target' toolchain instead,
# so this is not needed here.
}
config("integer-paranoia") {
cflags = [
"-fsanitize=integer-divide-by-zero,signed-integer-overflow",
"-fsanitize-undefined-trap-on-error",
]
}
config("static-libc++") {
if (current_os == "mac") {
# The macOS driver doesn't support -static-libstdc++ properly, so pass
# the libraries directly. This has to locate the files explicitly in
# the toolchain, because -lc++ would look for the shared library.
ldflags = [
"-nostdlib++",
# NOTE: the path below was relative to toolchain.tool_dir in the Zircon build
# but the Fuchsia one doesn't support GCC-based host builds at all, so this
# is assuming Clang is always used instead.
rebase_path("${clang_prefix}/../lib/libc++.a", root_build_dir),
]
} else {
ldflags = [ "-static-libstdc++" ]
# TODO(fxbug.dev/26846): The implicitly linked static libc++.a depends on these.
if (current_os == "linux") {
libs = [
"dl",
"pthread",
]
}
}
}
config("pure") {
if (!is_gcc) {
# TODO(fxbug.dev/48501): This disables the SwitchToLookupTable optimization,
# which is not PIC-friendly.
cflags = [ "-fno-jump-tables" ]
}
}
config("rodso") {
configs = [ ":pure" ]
if (is_gcc) {
inputs = [ "rodso.ld" ]
ldflags = [ "-Wl,-T," + rebase_path(inputs[0], root_build_dir) ]
}
}
group("rodso_deps") {
}
config("auto_var_init") {
if (!is_gcc) {
# Automatically initialize variables with a pattern.
cflags = [ "-ftrivial-auto-var-init=pattern" ]
}
}
# This has to be variant() rather than config() to be used in the toolchain
# configs list.
variant("tiny") {
cflags = [ "-mcmodel=tiny" ]
asmflags = cflags
ldflags = cflags
}
# TODO(fxbug.dev/42305): We will temporarily disable UBSan for a specified number of
# instances where UBSan triggers runtime errors. This config will go away once
# the asan-ubsan variant is in CI/CQ and we remove all instances of caught
# undefined behavior in fuchsia. THIS CONFIG SHOULD NOT BE USED.
config("temporarily_disable_ubsan_do_not_use") {
visibility = [
# TODO(fxbug.dev/41888): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/ulib/affine:*",
"//zircon/system/ulib/affine/test:*",
# TODO(fxbug.dev/41892): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/ulib/trace-reader:*",
# TODO(fxbug.dev/42488): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/dev/display/display:*",
# TODO(fxbug.dev/41887): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/uapp/nand-util:*",
# TODO(fxbug.dev/42493): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/ulib/cobalt-client/test:*",
# TODO(fxbug.dev/41890): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//src/storage/gpt:*",
# TODO(fxbug.dev/41893): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/ulib/zxio/test:*",
# TODO(fxbug.dev/41894): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/ulib/zxtest:*",
# TODO(fxbug.dev/41900): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/system/utest/trace:*",
# TODO(fxbug.dev/41901): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/third_party/uapp/dash:*",
# TODO(fxbug.dev/41766): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/third_party/ulib/lz4:*",
# TODO(fxbug.dev/41901): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/third_party/ulib/musl/ldso:*",
# TODO(fxbug.dev/42500): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/third_party/ulib/musl/src/stdio:*",
# TODO(fxbug.dev/41904): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
"//zircon/third_party/ulib/boringssl:*",
]
if (!is_gcc) {
cflags = [ "-fno-sanitize=undefined" ]
}
}
# TODO(fxbug.dev/54322): Move this to //zircon/kernel/BUILD.gn once the kernel has been
# migrated to the Fuchsia build.
# For any standalone static binary.
config("standalone") {
ldflags = [
"-nostdlib",
"-static",
]
cflags = [
"-ffreestanding",
"-include",
rebase_path("//zircon/kernel/include/hidden.h", root_build_dir),
# We want `.debug_frame` for the kernel (fxbug.dev/30023). And we still want
# asynchronous unwind tables. Alas there's (currently) no way to
# achieve this with our GCC. At the moment we compile with
# `-fno-omit-frame-pointer`, which is good because we link with
# `--gc-sections`, which means `.eh_frame` gets discarded so GCC-built
# kernels don't have any unwind info (except for assembly)! Assembler
# code has its own way of requesting `.debug_frame` vs `.eh_frame` with
# the `.cfi_sections` directive.
"-fno-unwind-tables",
]
cflags_cc = [
# Underlying kernel heap only has default alignment of 8 bytes, so pass
# this to the compiler as the default new alignment.
"-faligned-new=8",
]
if (current_cpu == "x64") {
# This only matters in an environment where interrupt handlers might
# push trap frames in the same privilege level, like the kernel.
# e.g. Multiboot probably doesn't actually need it, but it doesn't hurt.
cflags += [ "-mno-red-zone" ]
} else if (current_cpu == "arm64") {
# This matters if vector registers are not available, e.g. in the kernel
# since the they hold unsaved user state, or in the physmem environment
# because they might not be enabled in hardware yet.
cflags += [ "-mgeneral-regs-only" ]
}
if (is_gcc && current_os == "fuchsia") {
cflags += [ "-fpie" ]
}
if (!is_gcc && current_os == "fuchsia") {
# In the Fuchsia-target toolchains there's no way to prevent the
# compiler driver from passing -pie, so negate it. BFD ld doesn't
# have --no-pie, but arm64-elf-gcc doesn't pass -pie either.
ldflags += [ "-Wl,--no-pie" ]
}
if (!is_gcc) {
# Disable the implicit addition of toolchain-provided libraries to
# the link by the compiler driver. No toolchain-provided library is
# compatible with the kernel's internal ABI.
#
# TODO(fxbug.dev/27356): Clang doesn't have a single straightforward switch to
# disable all such libraries, though it certainly should. It
# provides separate switches to disable the profiling/coverage
# runtime and to disable all the flavors of runtime implied by
# -fsanitize=... switches (including any such defaults). It will
# still provide other incompatible libraries to the link, but they
# won't have any effect since they don't define any symbols the link
# needs. However, this is a fragile situation that could easily
# break.
ldflags += [
"-noprofilelib",
"-fno-sanitize-link-runtime",
]
}
configs = [ "//build/config/zircon:no_exceptions" ]
}
# Statically linked posititon independent executable.
#
# These have to be variant() rather than config() to be used in the toolchain
# configs list.
variant("static-pie-compile") {
cflags = [ "-fPIE" ]
defines = [ "ZX_STATIC_PIE=1" ]
}
variant("static-pie-link") {
ldflags = [
"-Wl,-pie",
"-Wl,--no-dynamic-linker",
]
}