aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/arm/arm.cc
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2023-06-19 12:56:41 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2024-03-11 12:43:03 +0000
commit1bf70e68e4910fe0904466d06cae7f747c02ab72 (patch)
treefd9f3f391ad8a04debbb8e7993df11bd4f41e54d /gcc/config/arm/arm.cc
parent119f5ae0455f02568159eafa9008a555605e7d71 (diff)
downloadgcc-1bf70e68e4910fe0904466d06cae7f747c02ab72.zip
gcc-1bf70e68e4910fe0904466d06cae7f747c02ab72.tar.gz
gcc-1bf70e68e4910fe0904466d06cae7f747c02ab72.tar.bz2
aarch64,arm: Move branch-protection data to targets
The branch-protection types are target specific, not the same on arm and aarch64. This currently affects pac-ret+b-key, but there will be a new type on aarch64 that is not relevant for arm. After the move, change aarch_ identifiers to aarch64_ or arm_ as appropriate. Refactor aarch_validate_mbranch_protection to take the target specific branch-protection types as an argument. In case of invalid input currently no hints are provided: the way branch-protection types and subtypes can be mixed makes it difficult without causing confusion. gcc/ChangeLog: * config/aarch64/aarch64.md: Rename aarch_ to aarch64_. * config/aarch64/aarch64.opt: Likewise. * config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Likewise. * config/aarch64/aarch64.cc (aarch64_expand_prologue): Likewise. (aarch64_expand_epilogue): Likewise. (aarch64_post_cfi_startproc): Likewise. (aarch64_handle_no_branch_protection): Copy and rename. (aarch64_handle_standard_branch_protection): Likewise. (aarch64_handle_pac_ret_protection): Likewise. (aarch64_handle_pac_ret_leaf): Likewise. (aarch64_handle_pac_ret_b_key): Likewise. (aarch64_handle_bti_protection): Likewise. (aarch64_override_options): Update branch protection validation. (aarch64_handle_attr_branch_protection): Likewise. * config/arm/aarch-common-protos.h (aarch_validate_mbranch_protection): Pass branch protection type description as argument. (struct aarch_branch_protect_type): Move from aarch-common.h. * config/arm/aarch-common.cc (aarch_handle_no_branch_protection): Remove. (aarch_handle_standard_branch_protection): Remove. (aarch_handle_pac_ret_protection): Remove. (aarch_handle_pac_ret_leaf): Remove. (aarch_handle_pac_ret_b_key): Remove. (aarch_handle_bti_protection): Remove. (aarch_validate_mbranch_protection): Pass branch protection type description as argument. * config/arm/aarch-common.h (enum aarch_key_type): Remove. (struct aarch_branch_protect_type): Remove. * config/arm/arm-c.cc (arm_cpu_builtins): Remove aarch_ra_sign_key. * config/arm/arm.cc (arm_handle_no_branch_protection): Copy and rename. (arm_handle_standard_branch_protection): Likewise. (arm_handle_pac_ret_protection): Likewise. (arm_handle_pac_ret_leaf): Likewise. (arm_handle_bti_protection): Likewise. (arm_configure_build_target): Update branch protection validation. * config/arm/arm.opt: Remove aarch_ra_sign_key.
Diffstat (limited to 'gcc/config/arm/arm.cc')
-rw-r--r--gcc/config/arm/arm.cc55
1 files changed, 48 insertions, 7 deletions
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 6a35fe4..0217abc 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -3259,6 +3259,52 @@ static sbitmap isa_all_fpubits_internal;
static sbitmap isa_all_fpbits;
static sbitmap isa_quirkbits;
+static void
+arm_handle_no_branch_protection (void)
+{
+ aarch_ra_sign_scope = AARCH_FUNCTION_NONE;
+ aarch_enable_bti = 0;
+}
+
+static void
+arm_handle_standard_branch_protection (void)
+{
+ aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF;
+ aarch_enable_bti = 1;
+}
+
+static void
+arm_handle_pac_ret_protection (void)
+{
+ aarch_ra_sign_scope = AARCH_FUNCTION_NON_LEAF;
+}
+
+static void
+arm_handle_pac_ret_leaf (void)
+{
+ aarch_ra_sign_scope = AARCH_FUNCTION_ALL;
+}
+
+static void
+arm_handle_bti_protection (void)
+{
+ aarch_enable_bti = 1;
+}
+
+static const struct aarch_branch_protect_type arm_pac_ret_subtypes[] = {
+ { "leaf", false, arm_handle_pac_ret_leaf, NULL, 0 },
+ { NULL, false, NULL, NULL, 0 }
+};
+
+static const struct aarch_branch_protect_type arm_branch_protect_types[] = {
+ { "none", true, arm_handle_no_branch_protection, NULL, 0 },
+ { "standard", true, arm_handle_standard_branch_protection, NULL, 0 },
+ { "pac-ret", false, arm_handle_pac_ret_protection, arm_pac_ret_subtypes,
+ ARRAY_SIZE (arm_pac_ret_subtypes) },
+ { "bti", false, arm_handle_bti_protection, NULL, 0 },
+ { NULL, false, NULL, NULL, 0 }
+};
+
/* Configure a build target TARGET from the user-specified options OPTS and
OPTS_SET. If WARN_COMPATIBLE, emit a diagnostic if both the CPU and
architecture have been specified, but the two are not identical. */
@@ -3306,14 +3352,9 @@ arm_configure_build_target (struct arm_build_target *target,
if (opts->x_arm_branch_protection_string)
{
- aarch_validate_mbranch_protection (opts->x_arm_branch_protection_string,
+ aarch_validate_mbranch_protection (arm_branch_protect_types,
+ opts->x_arm_branch_protection_string,
"-mbranch-protection=");
-
- if (aarch_ra_sign_key != AARCH_KEY_A)
- {
- warning (0, "invalid key type for %<-mbranch-protection=%>");
- aarch_ra_sign_key = AARCH_KEY_A;
- }
}
if (arm_selected_arch)