From 71aebd8c16dedd0f656c1e7a0b880fe0a2434852 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 31 Oct 2019 15:15:54 -0700 Subject: [PATCH] gn build: Add support for cross-compiling the builtins and profile runtimes for Android aarch64 and arm. Differential Revision: https://reviews.llvm.org/D69681 --- utils/gn/build/toolchain/BUILD.gn | 9 ++ utils/gn/build/toolchain/target_flags.gni | 3 + utils/gn/secondary/compiler-rt/BUILD.gn | 23 ++- .../compiler-rt/lib/builtins/BUILD.gn | 132 +++++++++--------- utils/gn/secondary/compiler-rt/target.gni | 2 + utils/gn/secondary/llvm/triples.gni | 4 + 6 files changed, 99 insertions(+), 74 deletions(-) diff --git a/utils/gn/build/toolchain/BUILD.gn b/utils/gn/build/toolchain/BUILD.gn index c36579f28e4..b8e46034cca 100644 --- a/utils/gn/build/toolchain/BUILD.gn +++ b/utils/gn/build/toolchain/BUILD.gn @@ -207,6 +207,15 @@ if (android_ndk_path != "") { use_lld = true } } + + stage2_unix_toolchain("stage2_android_arm") { + toolchain_args = { + current_os = "android" + current_cpu = "arm" + is_clang = true + use_lld = true + } + } } toolchain("win") { diff --git a/utils/gn/build/toolchain/target_flags.gni b/utils/gn/build/toolchain/target_flags.gni index e1c045f625c..02dfeda9d62 100644 --- a/utils/gn/build/toolchain/target_flags.gni +++ b/utils/gn/build/toolchain/target_flags.gni @@ -11,6 +11,9 @@ if (current_os == "android") { "-B$android_ndk_path/toolchains/llvm/prebuilt/linux-x86_64", ] target_ldflags += [ "-static-libstdc++" ] + if (current_cpu == "arm") { + target_flags += [ "-march=armv7-a" ] + } } if (current_cpu == "x86") { diff --git a/utils/gn/secondary/compiler-rt/BUILD.gn b/utils/gn/secondary/compiler-rt/BUILD.gn index 1da710d5ac9..7a1961678b0 100644 --- a/utils/gn/secondary/compiler-rt/BUILD.gn +++ b/utils/gn/secondary/compiler-rt/BUILD.gn @@ -1,8 +1,19 @@ -group("compiler-rt") { - # In the GN build, compiler-rt is always built by just-built clang and lld. - # FIXME: For macOS and iOS builds, depend on lib in all needed target arch - # toolchains and then lipo them together for the final output. - deps = [ - "//compiler-rt/lib(//llvm/utils/gn/build/toolchain:stage2_unix)", +import("//llvm/utils/gn/build/toolchain/compiler.gni") + +# In the GN build, compiler-rt is always built by just-built clang and lld. +# FIXME: For macOS and iOS builds, depend on lib in all needed target arch +# toolchains and then lipo them together for the final output. +supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_unix" ] +if (android_ndk_path != "") { + supported_toolchains += [ + "//llvm/utils/gn/build/toolchain:stage2_android_aarch64", + "//llvm/utils/gn/build/toolchain:stage2_android_arm", ] } + +group("compiler-rt") { + deps = [] + foreach(toolchain, supported_toolchains) { + deps += [ "//compiler-rt/lib($toolchain)" ] + } +} diff --git a/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn b/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn index c052603dab9..1614f07facf 100644 --- a/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn +++ b/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn @@ -306,12 +306,30 @@ static_library("builtins") { "comparesf2.c", "divmodsi4.c", "divsi3.c", + "fp_mode.c", "modsi3.c", "udivmodsi4.c", "udivsi3.c", "umodsi3.c", ] sources += [ + "arm/aeabi_cdcmp.S", + "arm/aeabi_cdcmpeq_check_nan.c", + "arm/aeabi_cfcmp.S", + "arm/aeabi_cfcmpeq_check_nan.c", + "arm/aeabi_dcmp.S", + "arm/aeabi_div0.c", + "arm/aeabi_drsub.c", + "arm/aeabi_fcmp.S", + "arm/aeabi_frsub.c", + "arm/aeabi_idivmod.S", + "arm/aeabi_ldivmod.S", + "arm/aeabi_memcmp.S", + "arm/aeabi_memcpy.S", + "arm/aeabi_memmove.S", + "arm/aeabi_memset.S", + "arm/aeabi_uidivmod.S", + "arm/aeabi_uldivmod.S", "arm/bswapdi2.S", "arm/bswapsi2.S", "arm/clzdi2.S", @@ -321,6 +339,10 @@ static_library("builtins") { "arm/divsi3.S", "arm/fp_mode.c", "arm/modsi3.S", + "arm/switch16.S", + "arm/switch32.S", + "arm/switch8.S", + "arm/switchu8.S", "arm/sync_fetch_and_add_4.S", "arm/sync_fetch_and_add_8.S", "arm/sync_fetch_and_and_4.S", @@ -341,10 +363,52 @@ static_library("builtins") { "arm/sync_fetch_and_umin_8.S", "arm/sync_fetch_and_xor_4.S", "arm/sync_fetch_and_xor_8.S", + "arm/sync_synchronize.S", "arm/udivmodsi4.S", "arm/udivsi3.S", "arm/umodsi3.S", ] + + if (current_os == "android") { + sources += [ + "arm/adddf3vfp.S", + "arm/addsf3vfp.S", + "arm/divdf3vfp.S", + "arm/divsf3vfp.S", + "arm/eqdf2vfp.S", + "arm/eqsf2vfp.S", + "arm/extendsfdf2vfp.S", + "arm/fixdfsivfp.S", + "arm/fixsfsivfp.S", + "arm/fixunsdfsivfp.S", + "arm/fixunssfsivfp.S", + "arm/floatsidfvfp.S", + "arm/floatsisfvfp.S", + "arm/floatunssidfvfp.S", + "arm/floatunssisfvfp.S", + "arm/gedf2vfp.S", + "arm/gesf2vfp.S", + "arm/gtdf2vfp.S", + "arm/gtsf2vfp.S", + "arm/ledf2vfp.S", + "arm/lesf2vfp.S", + "arm/ltdf2vfp.S", + "arm/ltsf2vfp.S", + "arm/muldf3vfp.S", + "arm/mulsf3vfp.S", + "arm/nedf2vfp.S", + "arm/negdf2vfp.S", + "arm/negsf2vfp.S", + "arm/nesf2vfp.S", + "arm/restore_vfp_d8_d15_regs.S", + "arm/save_vfp_d8_d15_regs.S", + "arm/subdf3vfp.S", + "arm/subsf3vfp.S", + "arm/truncdfsf2vfp.S", + "arm/unorddf2vfp.S", + "arm/unordsf2vfp.S", + ] + } } else { sources += [ "arm/aeabi_idivmod.S", @@ -450,73 +514,5 @@ source_set("_unused") { "arm/comparesf2.S", "arm/divsi3.S", "arm/udivsi3.S", - - # EABI - "arm/aeabi_cdcmp.S", - "arm/aeabi_cdcmpeq_check_nan.c", - "arm/aeabi_cfcmp.S", - "arm/aeabi_cfcmpeq_check_nan.c", - "arm/aeabi_dcmp.S", - "arm/aeabi_div0.c", - "arm/aeabi_drsub.c", - "arm/aeabi_fcmp.S", - "arm/aeabi_frsub.c", - "arm/aeabi_idivmod.S", - "arm/aeabi_ldivmod.S", - "arm/aeabi_memcmp.S", - "arm/aeabi_memcpy.S", - "arm/aeabi_memmove.S", - "arm/aeabi_memset.S", - "arm/aeabi_uidivmod.S", - "arm/aeabi_uldivmod.S", - - # Thumb1 JT - "arm/switch16.S", - "arm/switch32.S", - "arm/switch8.S", - "arm/switchu8.S", - - # Thumb1 SjLj - "arm/restore_vfp_d8_d15_regs.S", - "arm/save_vfp_d8_d15_regs.S", - - # Thumb1 VFPv2 - "arm/adddf3vfp.S", - "arm/addsf3vfp.S", - "arm/divdf3vfp.S", - "arm/divsf3vfp.S", - "arm/eqdf2vfp.S", - "arm/eqsf2vfp.S", - "arm/extendsfdf2vfp.S", - "arm/fixdfsivfp.S", - "arm/fixsfsivfp.S", - "arm/fixunsdfsivfp.S", - "arm/fixunssfsivfp.S", - "arm/floatsidfvfp.S", - "arm/floatsisfvfp.S", - "arm/floatunssidfvfp.S", - "arm/floatunssisfvfp.S", - "arm/gedf2vfp.S", - "arm/gesf2vfp.S", - "arm/gtdf2vfp.S", - "arm/gtsf2vfp.S", - "arm/ledf2vfp.S", - "arm/lesf2vfp.S", - "arm/ltdf2vfp.S", - "arm/ltsf2vfp.S", - "arm/muldf3vfp.S", - "arm/mulsf3vfp.S", - "arm/nedf2vfp.S", - "arm/negdf2vfp.S", - "arm/negsf2vfp.S", - "arm/nesf2vfp.S", - "arm/subdf3vfp.S", - "arm/subsf3vfp.S", - "arm/truncdfsf2vfp.S", - "arm/unorddf2vfp.S", - "arm/unordsf2vfp.S", - - # Thumb1 icache - "arm/sync_synchronize.S", ] } diff --git a/utils/gn/secondary/compiler-rt/target.gni b/utils/gn/secondary/compiler-rt/target.gni index c739acc656f..1f2372e8f1d 100644 --- a/utils/gn/secondary/compiler-rt/target.gni +++ b/utils/gn/secondary/compiler-rt/target.gni @@ -5,6 +5,8 @@ if (current_cpu == "x86") { crt_current_target_arch = "i386" } else if (current_cpu == "x64") { crt_current_target_arch = "x86_64" +} else if (current_cpu == "arm") { + crt_current_target_arch = "arm" } else if (current_cpu == "arm64") { crt_current_target_arch = "aarch64" } else if (current_cpu == "ppc64") { diff --git a/utils/gn/secondary/llvm/triples.gni b/utils/gn/secondary/llvm/triples.gni index 558731295ce..9c9ba132639 100644 --- a/utils/gn/secondary/llvm/triples.gni +++ b/utils/gn/secondary/llvm/triples.gni @@ -12,6 +12,10 @@ if (current_cpu == "x86") { } else if (current_os == "win") { llvm_current_triple = "x86_64-pc-windows-msvc" } +} else if (current_cpu == "arm") { + if (current_os == "android") { + llvm_current_triple = "arm-linux-androideabi" + } } else if (current_cpu == "arm64") { if (current_os == "android") { llvm_current_triple = "aarch64-linux-android21"