From bca786d742a4317e09b7bc7eb161b9797fc5476f Mon Sep 17 00:00:00 2001 From: Tamas Petz Date: Wed, 20 Jan 2021 18:56:33 +0100 Subject: [PATCH] [arm64] Build NDK with PAuth and BTI This change adds a new arch named "armv8-a-branchprot". The new target is no different from the usual "armv8-a" variant except it has the compiler flag "-mbranch-protection=standard" set. With this flag compiler emits Armv8.3-A Pointer Authentication and Armv8.5-A Branch Target Identification instructions. All of these instructions are in the hint space; therefore devices which do not support any of these extensions would execute them as NOPs. In terms of directory structure there is no change in the output of build/soong/scripts/build-ndk-prebuilts.sh script. Test: build NDK prebuilts Change-Id: Ie52ccba5653fbf567f0b7ca312d8a8e71602ad06 --- android/arch.go | 2 +- android/arch_list.go | 1 + cc/config/arm64_device.go | 7 +++++++ rust/config/arm64_device.go | 7 ++++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/android/arch.go b/android/arch.go index baee9be26..a8239a03f 100644 --- a/android/arch.go +++ b/android/arch.go @@ -1434,7 +1434,7 @@ type archConfig struct { func getNdkAbisConfig() []archConfig { return []archConfig{ {"arm", "armv7-a", "", []string{"armeabi-v7a"}}, - {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, + {"arm64", "armv8-a-branchprot", "", []string{"arm64-v8a"}}, {"x86", "", "", []string{"x86"}}, {"x86_64", "", "", []string{"x86_64"}}, } diff --git a/android/arch_list.go b/android/arch_list.go index 0c33b9d34..d68a0d1d1 100644 --- a/android/arch_list.go +++ b/android/arch_list.go @@ -41,6 +41,7 @@ var archVariants = map[ArchType][]string{ }, Arm64: { "armv8_a", + "armv8_a_branchprot", "armv8_2a", "armv8-2a-dotprod", "cortex-a53", diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index e6024aa45..d083d2a0b 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -31,6 +31,10 @@ var ( "armv8-a": []string{ "-march=armv8-a", }, + "armv8-a-branchprot": []string{ + "-march=armv8-a", + "-mbranch-protection=standard", + }, "armv8-2a": []string{ "-march=armv8.2-a", }, @@ -102,6 +106,7 @@ func init() { pctx.StaticVariable("Arm64ClangCppflags", strings.Join(ClangFilterUnknownCflags(arm64Cppflags), " ")) pctx.StaticVariable("Arm64ClangArmv8ACflags", strings.Join(arm64ArchVariantCflags["armv8-a"], " ")) + pctx.StaticVariable("Arm64ClangArmv8ABranchProtCflags", strings.Join(arm64ArchVariantCflags["armv8-a-branchprot"], " ")) pctx.StaticVariable("Arm64ClangArmv82ACflags", strings.Join(arm64ArchVariantCflags["armv8-2a"], " ")) pctx.StaticVariable("Arm64ClangArmv82ADotprodCflags", strings.Join(arm64ArchVariantCflags["armv8-2a-dotprod"], " ")) @@ -124,6 +129,7 @@ func init() { var ( arm64ClangArchVariantCflagsVar = map[string]string{ "armv8-a": "${config.Arm64ClangArmv8ACflags}", + "armv8-a-branchprot": "${config.Arm64ClangArmv8ABranchProtCflags}", "armv8-2a": "${config.Arm64ClangArmv82ACflags}", "armv8-2a-dotprod": "${config.Arm64ClangArmv82ADotprodCflags}", } @@ -202,6 +208,7 @@ func (toolchainArm64) LibclangRuntimeLibraryArch() string { func arm64ToolchainFactory(arch android.Arch) Toolchain { switch arch.ArchVariant { case "armv8-a": + case "armv8-a-branchprot": case "armv8-2a": case "armv8-2a-dotprod": // Nothing extra for armv8-a/armv8-2a diff --git a/rust/config/arm64_device.go b/rust/config/arm64_device.go index 506642861..186e571dd 100644 --- a/rust/config/arm64_device.go +++ b/rust/config/arm64_device.go @@ -26,9 +26,10 @@ var ( Arm64LinkFlags = []string{} Arm64ArchVariantRustFlags = map[string][]string{ - "armv8-a": []string{}, - "armv8-2a": []string{}, - "armv8-2a-dotprod": []string{}, + "armv8-a": []string{}, + "armv8-a-branchprot": []string{}, + "armv8-2a": []string{}, + "armv8-2a-dotprod": []string{}, } )