Skip to content

Commit

Permalink
Reland "gn build: Fix support for building the builtins for baremetal."
Browse files Browse the repository at this point in the history
Our support for building for baremetal was conditional on a default
off arg and would have failed to build if you had somehow arranged
to pass the correct --target flag; presumably nobody noticed because
nobody was turning it on. A better approach is to model baremetal
as a separate "OS" called "baremetal" and build it in the same way
as we cross-compile for other targets. That's what this patch does.
I only hooked up the arm64 target but others can be added.

Relanding after fixing Mac build breakage in D123244.

Differential Revision: https://reviews.llvm.org/D122862
  • Loading branch information
pcc committed Apr 6, 2022
1 parent 096477e commit 02a7b17
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
7 changes: 7 additions & 0 deletions llvm/utils/gn/build/toolchain/BUILD.gn
Expand Up @@ -245,6 +245,13 @@ if (host_os == "mac") {
}
}

stage2_unix_toolchain("stage2_baremetal_aarch64") {
toolchain_args = {
current_os = "baremetal"
current_cpu = "arm64"
}
}

template("win_toolchain") {
toolchain(target_name) {
# https://groups.google.com/a/chromium.org/d/msg/gn-dev/F_lv5T-tNDM
Expand Down
2 changes: 2 additions & 0 deletions llvm/utils/gn/build/toolchain/target_flags.gni
Expand Up @@ -42,6 +42,8 @@ if (current_os == "android") {
"x86_64",
]
}
} else if (current_os == "baremetal") {
target_flags += [ "--target=$llvm_current_triple" ]
}

if (current_cpu == "x86") {
Expand Down
3 changes: 3 additions & 0 deletions llvm/utils/gn/secondary/compiler-rt/BUILD.gn
Expand Up @@ -12,6 +12,9 @@ if (current_os == "win") {
supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
}
supported_toolchains += supported_android_toolchains
if (llvm_build_AArch64) {
supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_baremetal_aarch64" ]
}
group("compiler-rt") {
deps = [ "//compiler-rt/include($host_toolchain)" ]
foreach(toolchain, supported_toolchains) {
Expand Down
14 changes: 8 additions & 6 deletions llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
Expand Up @@ -2,21 +2,23 @@ group("lib") {
deps = [
"//compiler-rt/lib/asan:ignorelist($host_toolchain)",
"//compiler-rt/lib/cfi:ignorelist($host_toolchain)",
"//compiler-rt/lib/profile",
]
if (current_os == "linux") {
deps += [ "//compiler-rt/lib/msan" ]
}
if (current_os == "linux" || current_os == "android") {
deps += [ "//compiler-rt/lib/ubsan_minimal" ]
}
if (current_os != "win") {
deps += [
"//compiler-rt/lib/asan",
"//compiler-rt/lib/builtins",
]
if (current_os != "win" && current_os != "baremetal") {
deps += [ "//compiler-rt/lib/asan" ]
if (current_cpu == "x64" || current_cpu == "arm64") {
deps += [ "//compiler-rt/lib/tsan/rtl" ]
}
}
if (current_os != "win") {
deps += [ "//compiler-rt/lib/builtins" ]
}
if (current_os != "baremetal") {
deps += [ "//compiler-rt/lib/profile" ]
}
}
11 changes: 4 additions & 7 deletions llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn
Expand Up @@ -4,9 +4,6 @@ import("//llvm/utils/gn/build/buildflags.gni")
declare_args() {
# Skip the atomic builtin (should normally be provided by a shared library).
compiler_rt_exclude_atomic_builtin = true

# Compile builtins for baremetal.
compiler_rt_baremetal_build = false
}

static_library("builtins") {
Expand Down Expand Up @@ -170,17 +167,17 @@ static_library("builtins") {
]

if (current_os != "fuchsia") {
sources += [ "clear_cache.c" ]
}

if (current_os != "fuchsia" && current_os != "baremetal") {
sources += [
"emutls.c",
"enable_execute_stack.c",
"eprintf.c",
]
}

if (current_os != "fuchsia" && !compiler_rt_baremetal_build) {
sources += [ "clear_cache.c" ]
}

if (current_os == "mac" || current_os == "ios") {
sources += [
"atomic_flag_clear.c",
Expand Down
3 changes: 3 additions & 0 deletions llvm/utils/gn/secondary/compiler-rt/target.gni
Expand Up @@ -28,6 +28,9 @@ if (clang_enable_per_target_runtime_dir) {
}
} else if (current_os == "ios" || current_os == "mac") {
crt_current_out_dir = "$clang_resource_dir/lib/darwin"
} else if (current_os == "baremetal") {
crt_current_out_dir = "$clang_resource_dir/lib/baremetal"
crt_current_target_suffix = "-$crt_current_target_arch"
} else if (current_os == "win") {
crt_current_out_dir = "$clang_resource_dir/lib/windows"
crt_current_target_suffix = "-$crt_current_target_arch"
Expand Down
2 changes: 2 additions & 0 deletions llvm/utils/gn/secondary/llvm/triples.gni
Expand Up @@ -23,6 +23,8 @@ if (current_cpu == "x86") {
llvm_current_triple = "aarch64-linux-android29"
} else if (current_os == "ios" || current_os == "mac") {
llvm_current_triple = "arm64-apple-darwin"
} else if (current_os == "baremetal") {
llvm_current_triple = "aarch64-elf"
} else if (current_os == "linux") {
llvm_current_triple = "aarch64-unknown-linux-gnu"
}
Expand Down

0 comments on commit 02a7b17

Please sign in to comment.