]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
arm: Fix missing bti instruction for virtual thunks
authorRichard Ball <richard.ball@arm.com>
Mon, 5 Feb 2024 14:03:05 +0000 (14:03 +0000)
committerRichard Ball <richard.ball@arm.com>
Mon, 5 Feb 2024 14:04:12 +0000 (14:04 +0000)
Adds missing bti instruction at the beginning of a virtual
thunk, when bti is enabled.

gcc/ChangeLog:

* config/arm/arm.cc (arm_output_mi_thunk): Emit
insn for bti_c when bti is enabled.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp: Add v8_1_m_main_pacbti.
* g++.target/arm/bti_thunk.C: New test.

gcc/config/arm/arm.cc
gcc/testsuite/g++.target/arm/bti_thunk.C [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp

index e5a944486d7bd583627b0e22dfe8f95862e975bb..c44047c377a802d0c1dc1406df1b88a6b079607b 100644 (file)
@@ -29257,6 +29257,8 @@ arm_output_mi_thunk (FILE *file, tree thunk, HOST_WIDE_INT delta,
   const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk));
 
   assemble_start_function (thunk, fnname);
+  if (aarch_bti_enabled ())
+    emit_insn (aarch_gen_bti_c ());
   if (TARGET_32BIT)
     arm32_output_mi_thunk (file, thunk, delta, vcall_offset, function);
   else
diff --git a/gcc/testsuite/g++.target/arm/bti_thunk.C b/gcc/testsuite/g++.target/arm/bti_thunk.C
new file mode 100644 (file)
index 0000000..23c1acc
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_arch_v8_1m_main_pacbti_ok } */
+/* { dg-add-options arm_arch_v8_1m_main_pacbti } */
+/* { dg-additional-options "-mbranch-protection=bti" }*/
+
+#include <stdio.h>
+
+struct C18 {
+  virtual void f7();
+};
+
+struct C19 : virtual C18 {
+  virtual void f7();
+};
+
+void C19::f7() {
+  printf("foo\n");
+}
+
+/* { dg-final { scan-assembler-times "\tbti" 2 } } */
index f66dcaac7b84087d039011c9366dff32b1a40dda..b1faaf4aa955efdb78cdc13a139a0a11b24012a7 100644 (file)
@@ -5533,6 +5533,8 @@ foreach { armfunc armflag armdefs } {
                __ARM_ARCH_8M_BASE__
        v8m_main "-march=armv8-m.main+fp -mthumb" __ARM_ARCH_8M_MAIN__
        v8_1m_main "-march=armv8.1-m.main+fp -mthumb" __ARM_ARCH_8M_MAIN__
+       v8_1m_main_pacbti "-march=armv8.1-m.main+pacbti+fp -mthumb"
+               "__ARM_ARCH_8M_MAIN__ && __ARM_FEATURE_BTI"
        v9a "-march=armv9-a+simd" __ARM_ARCH_9A__ } {
     eval [string map [list FUNC $armfunc FLAG $armflag DEFS $armdefs ] {
        proc check_effective_target_arm_arch_FUNC_ok { } {