Skip to content

Commit b02b9b3

Browse files
committed
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. Differential Revision: https://reviews.llvm.org/D122862
1 parent bdb1ab9 commit b02b9b3

File tree

7 files changed

+29
-13
lines changed

7 files changed

+29
-13
lines changed

llvm/utils/gn/build/toolchain/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ if (host_os == "mac") {
244244
}
245245
}
246246

247+
stage2_unix_toolchain("stage2_baremetal_aarch64") {
248+
toolchain_args = {
249+
current_os = "baremetal"
250+
current_cpu = "arm64"
251+
}
252+
}
253+
247254
template("win_toolchain") {
248255
toolchain(target_name) {
249256
# https://groups.google.com/a/chromium.org/d/msg/gn-dev/F_lv5T-tNDM

llvm/utils/gn/build/toolchain/target_flags.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ if (current_os == "android") {
4242
"x86_64",
4343
]
4444
}
45+
} else if (current_os == "baremetal") {
46+
target_flags += [ "--target=$llvm_current_triple" ]
4547
}
4648

4749
if (current_cpu == "x86") {

llvm/utils/gn/secondary/compiler-rt/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if (current_os == "win") {
1212
supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
1313
}
1414
supported_toolchains += supported_android_toolchains
15+
if (llvm_build_AArch64) {
16+
supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_baremetal_aarch64" ]
17+
}
1518
group("compiler-rt") {
1619
deps = [ "//compiler-rt/include($host_toolchain)" ]
1720
foreach(toolchain, supported_toolchains) {

llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ group("lib") {
22
deps = [
33
"//compiler-rt/lib/asan:ignorelist($host_toolchain)",
44
"//compiler-rt/lib/cfi:ignorelist($host_toolchain)",
5-
"//compiler-rt/lib/profile",
65
]
76
if (current_os == "linux") {
87
deps += [ "//compiler-rt/lib/msan" ]
98
}
109
if (current_os == "linux" || current_os == "android") {
1110
deps += [ "//compiler-rt/lib/ubsan_minimal" ]
1211
}
13-
if (current_os != "win") {
14-
deps += [
15-
"//compiler-rt/lib/asan",
16-
"//compiler-rt/lib/builtins",
17-
]
12+
if (current_os != "win" && current_os != "baremetal") {
13+
deps += [ "//compiler-rt/lib/asan" ]
1814
if (current_cpu == "x64" || current_cpu == "arm64") {
1915
deps += [ "//compiler-rt/lib/tsan/rtl" ]
2016
}
2117
}
18+
if (current_os != "win") {
19+
deps += [ "//compiler-rt/lib/builtins" ]
20+
}
21+
if (current_os != "baremetal") {
22+
deps += [ "//compiler-rt/lib/profile" ]
23+
}
2224
}

llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import("//llvm/utils/gn/build/buildflags.gni")
44
declare_args() {
55
# Skip the atomic builtin (should normally be provided by a shared library).
66
compiler_rt_exclude_atomic_builtin = true
7-
8-
# Compile builtins for baremetal.
9-
compiler_rt_baremetal_build = false
107
}
118

129
static_library("builtins") {
@@ -170,17 +167,17 @@ static_library("builtins") {
170167
]
171168

172169
if (current_os != "fuchsia") {
170+
sources += [ "clear_cache.c" ]
171+
}
172+
173+
if (current_os != "fuchsia" && current_os != "baremetal") {
173174
sources += [
174175
"emutls.c",
175176
"enable_execute_stack.c",
176177
"eprintf.c",
177178
]
178179
}
179180

180-
if (current_os != "fuchsia" && !compiler_rt_baremetal_build) {
181-
sources += [ "clear_cache.c" ]
182-
}
183-
184181
if (current_os == "mac" || current_os == "ios") {
185182
sources += [
186183
"atomic_flag_clear.c",

llvm/utils/gn/secondary/compiler-rt/target.gni

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ if (clang_enable_per_target_runtime_dir) {
2828
}
2929
} else if (current_os == "ios" || current_os == "mac") {
3030
crt_current_out_dir = "$clang_resource_dir/lib/darwin"
31+
} else if (current_os == "baremetal") {
32+
crt_current_out_dir = "$clang_resource_dir/lib/baremetal"
33+
crt_current_target_suffix = "-$crt_current_target_arch"
3134
} else if (current_os == "win") {
3235
crt_current_out_dir = "$clang_resource_dir/lib/windows"
3336
crt_current_target_suffix = "-$crt_current_target_arch"

llvm/utils/gn/secondary/llvm/triples.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ if (current_cpu == "x86") {
2323
llvm_current_triple = "aarch64-linux-android29"
2424
} else if (current_os == "ios" || current_os == "mac") {
2525
llvm_current_triple = "arm64-apple-darwin"
26+
} else if (current_os == "baremetal") {
27+
llvm_current_triple = "aarch64-elf"
2628
} else if (current_os == "linux") {
2729
llvm_current_triple = "aarch64-unknown-linux-gnu"
2830
}

0 commit comments

Comments
 (0)