]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: don't emit bti j after NOTE_INSN_DELETED_LABEL [PR94748]
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 24 Apr 2020 16:36:02 +0000 (17:36 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 14 May 2020 12:16:29 +0000 (13:16 +0100)
It was previously discussed that indirect branches cannot go to
NOTE_INSN_DELETED_LABEL so inserting a landing pad is unnecessary.
See https://gcc.gnu.org/pipermail/gcc-patches/2019-May/522625.html

Before the patch a bti j was inserted after the label in

  __attribute__((target("branch-protection=bti")))
  int foo (void)
  {
  label:
    return 0;
  }

This is not necessary and weakens the security protection.

gcc/ChangeLog:

Backport from mainline.
2020-04-30  Szabolcs Nagy  <szabolcs.nagy@arm.com>

PR target/94748
* config/aarch64/aarch64-bti-insert.c (rest_of_insert_bti): Remove
the check for NOTE_INSN_DELETED_LABEL.

gcc/testsuite/ChangeLog:

Backport from mainline.
2020-04-30  Szabolcs Nagy  <szabolcs.nagy@arm.com>

PR target/94748
* gcc.target/aarch64/pr94748.c: New test.

gcc/ChangeLog
gcc/config/aarch64/aarch64-bti-insert.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/pr94748.c [new file with mode: 0644]

index 1b814c7308bdf93e5455c2b88f613eb3505403b6..80a48f8341cac4f98cce0a52d7ec71ff898971cc 100644 (file)
@@ -1,3 +1,12 @@
+2020-05-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>
+
+       Backport from mainline.
+       2020-04-30  Szabolcs Nagy  <szabolcs.nagy@arm.com>
+
+       PR target/94748
+       * config/aarch64/aarch64-bti-insert.c (rest_of_insert_bti): Remove
+       the check for NOTE_INSN_DELETED_LABEL.
+
 2020-05-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
        Backport from mainline.
index 9e0fc168435db4ed77f0954ddc40f0df2d2b6251..7da89074ce0226e5584d136ad4a2fef446b31def 100644 (file)
@@ -137,14 +137,10 @@ rest_of_insert_bti (void)
           insn = NEXT_INSN (insn))
        {
          /* If a label is marked to be preserved or can be a non-local goto
-            target, it must be protected with a BTI J.  The same applies to
-            NOTE_INSN_DELETED_LABEL since they are basically labels that might
-            be referenced via variables or constant pool.  */
-         if ((LABEL_P (insn)
+            target, it must be protected with a BTI J.  */
+         if (LABEL_P (insn)
               && (LABEL_PRESERVE_P (insn)
                   || bb->flags & BB_NON_LOCAL_GOTO_TARGET))
-             || (NOTE_P (insn)
-                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
            {
              bti_insn = gen_bti_j ();
              emit_insn_after (bti_insn, insn);
index a642d0f9a19ca0a2c7e642ac3fe8015238ada1b8..b69958e23d09375fa8110e20f4e4cb5257d2c6da 100644 (file)
@@ -1,3 +1,11 @@
+2020-05-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>
+
+       Backport from mainline.
+       2020-04-30  Szabolcs Nagy  <szabolcs.nagy@arm.com>
+
+       PR target/94748
+       * gcc.target/aarch64/pr94748.c: New test.
+
 2020-05-14  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
        Backport from mainline.
diff --git a/gcc/testsuite/gcc.target/aarch64/pr94748.c b/gcc/testsuite/gcc.target/aarch64/pr94748.c
new file mode 100644 (file)
index 0000000..2a2850d
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+__attribute__ ((target("branch-protection=bti")))
+int foo ()
+{
+label:
+  return 0;
+}
+
+/* { dg-final { scan-assembler-not {hint (36|38) // bti (j|jc)} } } */