diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn --- a/llvm/utils/gn/build/toolchain/BUILD.gn +++ b/llvm/utils/gn/build/toolchain/BUILD.gn @@ -244,6 +244,13 @@ } } +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 --- a/llvm/utils/gn/build/toolchain/target_flags.gni +++ b/llvm/utils/gn/build/toolchain/target_flags.gni @@ -42,6 +42,8 @@ "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 --- a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn @@ -12,6 +12,9 @@ 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 --- a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn @@ -2,7 +2,6 @@ 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 @@ 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 --- 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 @@ 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 @@ ] 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 @@ ] } - 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 --- a/llvm/utils/gn/secondary/compiler-rt/target.gni +++ b/llvm/utils/gn/secondary/compiler-rt/target.gni @@ -28,6 +28,9 @@ } } 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 --- a/llvm/utils/gn/secondary/llvm/triples.gni +++ b/llvm/utils/gn/secondary/llvm/triples.gni @@ -23,6 +23,8 @@ 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" }