[9/9,Arm] Implement arm Function target attribute 'branch-protection'.
Commit Message
Hi,
This patch is part of the series of PACBTI-M patches posted earlier https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582773.html
This change adds the target function attribute 'branch-protection'. The
options that it can take are the same the command-line option
'mbranch-protection'. The function attribute options override the command-
line options for the function scope.
Regression tested for arm-none-eabi. OK for trunk?
2021-11-11 Tejas Belagod <tbelagod@arm.com>
gcc/ChangeLog:
* config/arm/arm.c (arm_valid_target_attribute_rec): Add ARM function
attribute 'branch-protection' and parse its options.
* doc/extend.texi: Document ARM Function attribute 'branch-protection'.
gcc/testsuite/
* gcc.target/arm/acle/pacbti-m-predef-7.c: New test.
Thanks,
Tejas.
Comments
Tejas Belagod via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> Hi,
>
> This patch is part of the series of PACBTI-M patches posted earlier https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582773.html
>
> This change adds the target function attribute 'branch-protection'. The
> options that it can take are the same the command-line option
> 'mbranch-protection'. The function attribute options override the command-
> line options for the function scope.
>
> Regression tested for arm-none-eabi. OK for trunk?
>
> 2021-11-11 Tejas Belagod <tbelagod@arm.com>
>
> gcc/ChangeLog:
> * config/arm/arm.c (arm_valid_target_attribute_rec): Add ARM function
> attribute 'branch-protection' and parse its options.
> * doc/extend.texi: Document ARM Function attribute 'branch-protection'.
>
> gcc/testsuite/
> * gcc.target/arm/acle/pacbti-m-predef-7.c: New test.
>
> Thanks,
> Tejas.
[...]
Ping
Andrea
@@ -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;
+}