@@ -33147,6 +33147,22 @@ arm_valid_target_attribute_rec (tree args, struct gcc_options *opts)
opts->x_arm_arch_string = xstrndup (arch, strlen (arch));
}
+ else if (startswith (q, "branch-protection="))
+ {
+ char *bp_str = q + strlen ("branch-protection=");
+
+ opts->x_arm_branch_protection_string
+ = xstrndup (bp_str, strlen (bp_str));
+
+ /* Capture values from target attribute. */
+ aarch_validate_mbranch_protection
+ (opts->x_arm_branch_protection_string);
+
+ /* Init function target attr values. */
+ opts->x_aarch_ra_sign_scope = aarch_ra_sign_scope;
+ opts->x_aarch_enable_bti = aarch_enable_bti;
+
+ }
else if (q[0] == '+')
{
opts->x_arm_arch_string
@@ -4767,6 +4767,12 @@ In this example @code{target("+crc+nocrypto")} enables the @code{crc}
extension and disables the @code{crypto} extension for the function @code{foo}
without modifying an existing @option{-march=} or @option{-mcpu} option.
+@item branch-protection=
+@cindex @code{branch-protection=} function attribute, arm
+Select the function scope on which branch protection will be applied. The
+behavior and permissible arguments are the same as for the command-line option
+@option{-mbranch-protection=}. The default value is @code{none}.
+
@end table
@end table
new file mode 100644
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=pac-ret+leaf --save-temps" } */
+
+/* { dg-final { scan-assembler "\.eabi_attribute 50, 2" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 52, 2" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 74, 0" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */
+
+#if defined (__ARM_FEATURE_BTI_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_BTI_DEFAULT should be undefined."
+#endif
+
+#if !defined (__ARM_FEATURE_PAC_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_PAC_DEFAULT should be defined."
+#endif
+
+__attribute__((target("branch-protection=pac-ret+bti"), noinline))
+void foo ()
+{
+ if (__ARM_FEATURE_PAC_DEFAULT != 5)
+ __builtin_abort ();
+}
+
+int
+main()
+{
+ foo ();
+ return 0;
+}