aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2020-04-17 16:54:12 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-04-23 16:14:28 +0100
commitf7e4641afba7c348a7e7c8655e537a953c416bb3 (patch)
tree09c18d44d073ab39f6ad54c1cf417bd525aaf1fb /gcc
parent857d1fa3f0a04569382bab12829e5bfd3725ecbf (diff)
downloadgcc-f7e4641afba7c348a7e7c8655e537a953c416bb3.zip
gcc-f7e4641afba7c348a7e7c8655e537a953c416bb3.tar.gz
gcc-f7e4641afba7c348a7e7c8655e537a953c416bb3.tar.bz2
aarch64: ensure bti c is emitted at function start [PR94697]
The bti pass currently first emits bti c at function start if there is no paciasp (which also acts as indirect call landing pad), then bti j is emitted at jump labels, however if there is a label right before paciasp then the function start can end up like foo: label: bti j paciasp ... This patch is a minimal fix that just moves the bti c handling after the bti j handling so we end up with foo: bti c label: bti j paciasp ... This could be improved by emitting bti jc in this case, or by detecting that the label is not in fact an indirect jump target and then this situation would be much less common. Needs to be backported to gcc-9 branch. gcc/ChangeLog: PR target/94697 * config/aarch64/aarch64-bti-insert.c (rest_of_insert_bti): Swap bti c and bti j handling. gcc/testsuite/ChangeLog: PR target/94697 * gcc.target/aarch64/pr94697.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/config/aarch64/aarch64-bti-insert.c32
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.target/aarch64/pr94697.c19
4 files changed, 46 insertions, 16 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4e427c0..c806e5e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-23 Szabolcs Nagy <szabolcs.nagy@arm.com>
+
+ PR target/94697
+ * config/aarch64/aarch64-bti-insert.c (rest_of_insert_bti): Swap
+ bti c and bti j handling.
+
2020-04-23 Andrew Stubbs <ams@codesourcery.com>
Thomas Schwinge <thomas@codesourcery.com>
diff --git a/gcc/config/aarch64/aarch64-bti-insert.c b/gcc/config/aarch64/aarch64-bti-insert.c
index 295d18a..aa091c3 100644
--- a/gcc/config/aarch64/aarch64-bti-insert.c
+++ b/gcc/config/aarch64/aarch64-bti-insert.c
@@ -132,22 +132,6 @@ rest_of_insert_bti (void)
rtx_insn *insn;
basic_block bb;
- /* Since a Branch Target Exception can only be triggered by an indirect call,
- we exempt function that are only called directly. We also exempt
- functions that are already protected by Return Address Signing (PACIASP/
- PACIBSP). For all other cases insert a BTI C at the beginning of the
- function. */
- if (!cgraph_node::get (cfun->decl)->only_called_directly_p ())
- {
- bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
- insn = BB_HEAD (bb);
- if (!aarch64_pac_insn_p (get_first_nonnote_insn ()))
- {
- bti_insn = gen_bti_c ();
- emit_insn_before (bti_insn, insn);
- }
- }
-
bb = 0;
FOR_EACH_BB_FN (bb, cfun)
{
@@ -203,6 +187,22 @@ rest_of_insert_bti (void)
}
}
+ /* Since a Branch Target Exception can only be triggered by an indirect call,
+ we exempt function that are only called directly. We also exempt
+ functions that are already protected by Return Address Signing (PACIASP/
+ PACIBSP). For all other cases insert a BTI C at the beginning of the
+ function. */
+ if (!cgraph_node::get (cfun->decl)->only_called_directly_p ())
+ {
+ bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
+ insn = BB_HEAD (bb);
+ if (!aarch64_pac_insn_p (get_first_nonnote_insn ()))
+ {
+ bti_insn = gen_bti_c ();
+ emit_insn_before (bti_insn, insn);
+ }
+ }
+
timevar_pop (TV_MACH_DEP);
return 0;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4f5f020..15e7d9e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-23 Szabolcs Nagy <szabolcs.nagy@arm.com>
+
+ PR target/94697
+ * gcc.target/aarch64/pr94697.c: New test.
+
2020-04-23 Felix Yang <felix.yang@huawei.com>
PR target/94678
diff --git a/gcc/testsuite/gcc.target/aarch64/pr94697.c b/gcc/testsuite/gcc.target/aarch64/pr94697.c
new file mode 100644
index 0000000..e6069d2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr94697.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mbranch-protection=standard" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+void bar (int *);
+void *addr;
+
+/*
+** foo:
+** hint (25|34|38) // (paciasp|bti c|bti jc)
+** ...
+*/
+int foo (int x)
+{
+label:
+ addr = &&label;
+ bar (&x);
+ return x;
+}