aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ball <richard.ball@arm.com>2024-02-05 14:03:05 +0000
committerRichard Ball <richard.ball@arm.com>2024-02-05 14:04:12 +0000
commit23f1b496aa6c7015a2b986aa183041c722104779 (patch)
tree32de2d80bbdcdfed7b7972b61fdb45ef6b1cc742
parente5f50e63a83d03d1db6be1578070041ac7f31c37 (diff)
downloadgcc-23f1b496aa6c7015a2b986aa183041c722104779.zip
gcc-23f1b496aa6c7015a2b986aa183041c722104779.tar.gz
gcc-23f1b496aa6c7015a2b986aa183041c722104779.tar.bz2
arm: Fix missing bti instruction for virtual thunks
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.
-rw-r--r--gcc/config/arm/arm.cc2
-rw-r--r--gcc/testsuite/g++.target/arm/bti_thunk.C20
-rw-r--r--gcc/testsuite/lib/target-supports.exp2
3 files changed, 24 insertions, 0 deletions
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index e5a9444..c44047c 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -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
index 0000000..23c1acc
--- /dev/null
+++ b/gcc/testsuite/g++.target/arm/bti_thunk.C
@@ -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 } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index f66dcaa..b1faaf4 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -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 { } {