Created attachment 50535 [details] minimal reproducer For the attached testcase (reduced from the linux kernel), GCC generates multiple redundant sequences of back-to-back bti j instructions, the longest of which is 262 instructions long. To reproduce: $ aarch64-linux-gnu-gcc -c test.c -S -o - -O2 -mbranch-protection=standard | uniq -c | grep "bti j" | sort -nr 262 hint 36 // bti j 7 hint 36 // bti j 6 hint 36 // bti j 4 hint 36 // bti j 4 hint 36 // bti j 3 hint 36 // bti j 2 hint 36 // bti j 2 hint 36 // bti j 2 hint 36 // bti j 2 hint 36 // bti j 2 hint 36 // bti j 2 hint 36 // bti j 2 hint 36 // bti j
GCC 10 and 9 are also affected.
Taking a look at this.
The master branch has been updated by Alex Coplan <acoplan@gcc.gnu.org>: https://gcc.gnu.org/g:fe11882ae34c49f6214f93867783ed1332f35f0f commit r12-34-gfe11882ae34c49f6214f93867783ed1332f35f0f Author: Alex Coplan <alex.coplan@arm.com> Date: Wed Apr 21 14:42:04 2021 +0100 aarch64: Avoid duplicating bti j insns for jump tables [PR99988] This patch fixes PR99988 which shows us generating large (> 250) sequences of back-to-back bti j instructions. The fix is simply to avoid inserting bti j instructions at the target of a jump table if we've already inserted one for a given label. gcc/ChangeLog: PR target/99988 * config/aarch64/aarch64-bti-insert.c (aarch64_bti_j_insn_p): New. (rest_of_insert_bti): Avoid inserting duplicate bti j insns for jump table targets. gcc/testsuite/ChangeLog: PR target/99988 * gcc.target/aarch64/pr99988.c: New test.
Fixed on trunk. Keeping open for backports (once it's had some decent baking time).
The master branch has been updated by Christophe Lyon <clyon@gcc.gnu.org>: https://gcc.gnu.org/g:d44d8ed6b4e6fb2d0cf7566214e2e8281dd44cf0 commit r12-58-gd44d8ed6b4e6fb2d0cf7566214e2e8281dd44cf0 Author: Christophe Lyon <christophe.lyon@linaro.org> Date: Thu Apr 22 12:43:25 2021 +0000 testsuite/aarch64: Run pr99988.c test under lp64 only The new test fails with -mabi=ilp32: sorry, unimplemented: return address signing is only supported for '-mabi=lp64' 2021-04-22 Christophe Lyon <christophe.lyon@linaro.org> gcc/testsuite/ PR target/99988 * gcc.target/aarch64/pr99988.c: Skip if not lp64 target.
The releases/gcc-11 branch has been updated by Alex Coplan <acoplan@gcc.gnu.org>: https://gcc.gnu.org/g:1011bb8bc67cf34c45a9237d72a801a14ad9ef0f commit r11-8379-g1011bb8bc67cf34c45a9237d72a801a14ad9ef0f Author: Alex Coplan <alex.coplan@arm.com> Date: Wed Apr 21 14:42:04 2021 +0100 aarch64: Avoid duplicating bti j insns for jump tables [PR99988] This patch fixes PR99988 which shows us generating large (> 250) sequences of back-to-back bti j instructions. The fix is simply to avoid inserting bti j instructions at the target of a jump table if we've already inserted one for a given label. Co-Authored-By: Christophe Lyon <clyon@gcc.gnu.org> gcc/ChangeLog: PR target/99988 * config/aarch64/aarch64-bti-insert.c (aarch64_bti_j_insn_p): New. (rest_of_insert_bti): Avoid inserting duplicate bti j insns for jump table targets. gcc/testsuite/ChangeLog: PR target/99988 * gcc.target/aarch64/pr99988.c: New test.
The releases/gcc-10 branch has been updated by Alex Coplan <acoplan@gcc.gnu.org>: https://gcc.gnu.org/g:419c243dfb9aba51aceb1370a241db082847eeb5 commit r10-9818-g419c243dfb9aba51aceb1370a241db082847eeb5 Author: Alex Coplan <alex.coplan@arm.com> Date: Wed Apr 21 14:42:04 2021 +0100 aarch64: Avoid duplicating bti j insns for jump tables [PR99988] This patch fixes PR99988 which shows us generating large (> 250) sequences of back-to-back bti j instructions. The fix is simply to avoid inserting bti j instructions at the target of a jump table if we've already inserted one for a given label. Co-Authored-By: Christophe Lyon <clyon@gcc.gnu.org> gcc/ChangeLog: PR target/99988 * config/aarch64/aarch64-bti-insert.c (aarch64_bti_j_insn_p): New. (rest_of_insert_bti): Avoid inserting duplicate bti j insns for jump table targets. gcc/testsuite/ChangeLog: PR target/99988 * gcc.target/aarch64/pr99988.c: New test. (cherry picked from commit 1011bb8bc67cf34c45a9237d72a801a14ad9ef0f)
The releases/gcc-9 branch has been updated by Alex Coplan <acoplan@gcc.gnu.org>: https://gcc.gnu.org/g:52a09050fdfafb0e41d56b6adf1625264f315b82 commit r9-9528-g52a09050fdfafb0e41d56b6adf1625264f315b82 Author: Alex Coplan <alex.coplan@arm.com> Date: Wed Apr 21 14:42:04 2021 +0100 aarch64: Avoid duplicating bti j insns for jump tables [PR99988] This patch fixes PR99988 which shows us generating large (> 250) sequences of back-to-back bti j instructions. The fix is simply to avoid inserting bti j instructions at the target of a jump table if we've already inserted one for a given label. Co-Authored-By: Christophe Lyon <clyon@gcc.gnu.org> gcc/ChangeLog: PR target/99988 * config/aarch64/aarch64-bti-insert.c (aarch64_bti_j_insn_p): New. (rest_of_insert_bti): Avoid inserting duplicate bti j insns for jump table targets. gcc/testsuite/ChangeLog: PR target/99988 * gcc.target/aarch64/pr99988.c: New test. (cherry picked from commit 1011bb8bc67cf34c45a9237d72a801a14ad9ef0f)
Fixed everywhere.