[PATCH 12/15] arm: implement bti injection
authorAndrea Corallo <andrea.corallo@arm.com>
Thu, 7 Apr 2022 09:51:56 +0000 (11:51 +0200)
committerAndrea Corallo <andrea.corallo@arm.com>
Mon, 23 Jan 2023 10:45:28 +0000 (11:45 +0100)
commitdb6b9a9ddb7855f348ea978c392d8ebc258199af
treec3e3b4f52eda158fc050d729506387af17f06c3d
parentf7ad35a3ff369e10a6db6098439ca346b9e668de
[PATCH 12/15] arm: implement bti injection

Hi all,

this patch enables Branch Target Identification Armv8.1-M Mechanism
[1].

This is achieved by using the bti pass made common with Aarch64.

The pass iterates through the instructions and adds the necessary BTI
instructions at the beginning of every function and at every landing
pads targeted by indirect jumps.

Best Regards

  Andrea

[1]
<https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension>

gcc/ChangeLog

2022-04-07  Andrea Corallo  <andrea.corallo@arm.com>

* config.gcc (arm*-*-*): Add 'aarch-bti-insert.o' object.
* config/arm/arm-protos.h: Update.
* config/arm/aarch-common-protos.h: Declare
'aarch_bti_arch_check'.
* config/arm/arm.cc (aarch_bti_enabled) Update.
(aarch_bti_j_insn_p, aarch_pac_insn_p, aarch_gen_bti_c)
(aarch_gen_bti_j, aarch_bti_arch_check): New functions.
* config/arm/arm.md (bti_nop): New insn.
* config/arm/t-arm (PASSES_EXTRA): Add 'arm-passes.def'.
(aarch-bti-insert.o): New target.
* config/arm/unspecs.md (VUNSPEC_BTI_NOP): New unspec.
* config/arm/aarch-bti-insert.cc (rest_of_insert_bti): Verify arch
compatibility.
(gate): Make use of 'aarch_bti_arch_check'.
* config/arm/arm-passes.def: New file.
* config/aarch64/aarch64.cc (aarch_bti_arch_check): New function.

gcc/testsuite/ChangeLog

2022-04-07  Andrea Corallo  <andrea.corallo@arm.com>

* gcc.target/arm/bti-1.c: New testcase.
* gcc.target/arm/bti-2.c: Likewise.
12 files changed:
gcc/config.gcc
gcc/config/aarch64/aarch64.cc
gcc/config/arm/aarch-bti-insert.cc
gcc/config/arm/aarch-common-protos.h
gcc/config/arm/arm-passes.def [new file with mode: 0644]
gcc/config/arm/arm-protos.h
gcc/config/arm/arm.cc
gcc/config/arm/arm.md
gcc/config/arm/t-arm
gcc/config/arm/unspecs.md
gcc/testsuite/gcc.target/arm/bti-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/bti-2.c [new file with mode: 0644]