[llvm] 02a7b17 - Reland "gn build: Fix support for building the builtins for baremetal."
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 6 13:49:39 PDT 2022
Author: Peter Collingbourne
Date: 2022-04-06T13:45:40-07:00
New Revision: 02a7b1754f76b6ecd3930aabc618f9209ac20dd0
URL: https://github.com/llvm/llvm-project/commit/02a7b1754f76b6ecd3930aabc618f9209ac20dd0
DIFF: https://github.com/llvm/llvm-project/commit/02a7b1754f76b6ecd3930aabc618f9209ac20dd0.diff
LOG: Reland "gn build: Fix support for building the builtins for baremetal."
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
Added:
Modified:
llvm/utils/gn/build/toolchain/BUILD.gn
llvm/utils/gn/build/toolchain/target_flags.gni
llvm/utils/gn/secondary/compiler-rt/BUILD.gn
llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn
llvm/utils/gn/secondary/compiler-rt/target.gni
llvm/utils/gn/secondary/llvm/triples.gni
Removed:
################################################################################
diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index 864ae45a88ca9..2099b784e34e3 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -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
diff --git a/llvm/utils/gn/build/toolchain/target_flags.gni b/llvm/utils/gn/build/toolchain/target_flags.gni
index 573e758a6d6f6..0e59aba6c2a44 100644
--- a/llvm/utils/gn/build/toolchain/target_flags.gni
+++ b/llvm/utils/gn/build/toolchain/target_flags.gni
@@ -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") {
diff --git a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
index b4933bd80d7b1..05053e770e0d5 100644
--- a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn
@@ -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) {
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
index 92930337518d8..52c6431f1f67b 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn
@@ -2,7 +2,6 @@ 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" ]
@@ -10,13 +9,16 @@ group("lib") {
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" ]
+ }
}
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn
index ba733ad90f64b..d595bef112164 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn
@@ -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") {
@@ -170,6 +167,10 @@ 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",
@@ -177,10 +178,6 @@ static_library("builtins") {
]
}
- if (current_os != "fuchsia" && !compiler_rt_baremetal_build) {
- sources += [ "clear_cache.c" ]
- }
-
if (current_os == "mac" || current_os == "ios") {
sources += [
"atomic_flag_clear.c",
diff --git a/llvm/utils/gn/secondary/compiler-rt/target.gni b/llvm/utils/gn/secondary/compiler-rt/target.gni
index ac273372cee60..44e8343170b0c 100644
--- a/llvm/utils/gn/secondary/compiler-rt/target.gni
+++ b/llvm/utils/gn/secondary/compiler-rt/target.gni
@@ -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"
diff --git a/llvm/utils/gn/secondary/llvm/triples.gni b/llvm/utils/gn/secondary/llvm/triples.gni
index fc061650e6350..e39e1dd8089e2 100644
--- a/llvm/utils/gn/secondary/llvm/triples.gni
+++ b/llvm/utils/gn/secondary/llvm/triples.gni
@@ -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"
}
More information about the llvm-commits
mailing list