From 9d595b99fb7dc3bd306ffd7abc85509f14201a7a Mon Sep 17 00:00:00 2001 From: klzgrad Date: Tue, 19 May 2020 23:42:14 +0800 Subject: [PATCH] arm: build: Support -mcpu= on ARM and ARM64 --- src/build/config/arm.gni | 5 +++++ src/build/config/compiler/BUILD.gn | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/build/config/arm.gni b/src/build/config/arm.gni index cf21113480..fe0acb9338 100644 --- a/src/build/config/arm.gni +++ b/src/build/config/arm.gni @@ -27,6 +27,8 @@ if (current_cpu == "arm" || v8_current_cpu == "arm") { # Thumb is a reduced instruction set available on some ARM processors that # has increased code density. arm_use_thumb = true + + arm_cpu = "" } if (current_os == "android" || target_os == "android") { @@ -69,6 +71,9 @@ if (current_cpu == "arm" || v8_current_cpu == "arm") { current_cpu == "arm64e" || v8_current_cpu == "arm64e") { # arm64 supports only "hard". arm_float_abi = "hard" + declare_args() { + arm_cpu = "" + } declare_args() { # Enables the new Armv8 branch protection features. Valid strings are: # - "pac": Enables Pointer Authentication Code (PAC, featured in Armv8.3) diff --git a/src/build/config/compiler/BUILD.gn b/src/build/config/compiler/BUILD.gn index 2ae8eb717f..211d672339 100644 --- a/src/build/config/compiler/BUILD.gn +++ b/src/build/config/compiler/BUILD.gn @@ -902,7 +902,11 @@ config("compiler") { # TODO(pcc): The contents of .ARM.attributes should be based on the # -march flag passed at compile time (see llvm.org/pr36291). if (current_cpu == "arm") { - ldflags += [ "-march=$arm_arch" ] + if (arm_cpu != "") { + ldflags += [ "-mcpu=$arm_cpu" ] + } else { + ldflags += [ "-march=$arm_arch" ] + } } } @@ -1372,11 +1376,19 @@ config("compiler_cpu_abi") { "-march=$arm_arch", "-mfloat-abi=$arm_float_abi", ] + if (arm_cpu != "") { + cflags -= [ "-march=$arm_arch" ] + cflags += [ "-mcpu=$arm_cpu" ] + } + ldflags += [ "-mfloat-abi=$arm_float_abi" ] } else if (current_cpu == "arm64") { if (is_clang && !is_android && !is_fuchsia && !is_chromeos_device) { cflags += [ "--target=aarch64-linux-gnu" ] ldflags += [ "--target=aarch64-linux-gnu" ] } + if (arm_cpu != "") { + cflags += [ "-mcpu=$arm_cpu" ] + } if (target_os == "chromeos" && cros_target_cpu_arch != "" && is_a_target_toolchain) { cflags += [ "-march=$cros_target_cpu_arch" ]