diff options
author | Andrea Corallo <andrea.corallo@arm.com> | 2022-04-07 11:51:56 +0200 |
---|---|---|
committer | Andrea Corallo <andrea.corallo@arm.com> | 2023-01-23 11:45:28 +0100 |
commit | db6b9a9ddb7855f348ea978c392d8ebc258199af (patch) | |
tree | c3e3b4f52eda158fc050d729506387af17f06c3d /gcc/config/arm/arm.cc | |
parent | f7ad35a3ff369e10a6db6098439ca346b9e668de (diff) | |
download | gcc-db6b9a9ddb7855f348ea978c392d8ebc258199af.zip gcc-db6b9a9ddb7855f348ea978c392d8ebc258199af.tar.gz gcc-db6b9a9ddb7855f348ea978c392d8ebc258199af.tar.bz2 |
[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.
Diffstat (limited to 'gcc/config/arm/arm.cc')
-rw-r--r-- | gcc/config/arm/arm.cc | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 33ec15c..fb52048 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -33122,13 +33122,69 @@ arm_current_function_pac_enabled_p (void) && !crtl->is_leaf)); } +/* Raise an error if the current target arch is not bti compatible. */ +void aarch_bti_arch_check (void) +{ + if (!arm_arch8m_main) + error ("This architecture does not support branch protection instructions"); +} + /* Return TRUE if Branch Target Identification Mechanism is enabled. */ -static bool -aarch_bti_enabled () +bool +aarch_bti_enabled (void) +{ + return aarch_enable_bti != 0; +} + +/* Check if INSN is a BTI J insn. */ +bool +aarch_bti_j_insn_p (rtx_insn *insn) +{ + if (!insn || !INSN_P (insn)) + return false; + + rtx pat = PATTERN (insn); + return GET_CODE (pat) == UNSPEC_VOLATILE && XINT (pat, 1) == VUNSPEC_BTI_NOP; +} + +/* Check if X (or any sub-rtx of X) is a PACIASP/PACIBSP instruction. */ +bool +aarch_pac_insn_p (rtx x) { + if (!x || !INSN_P (x)) + return false; + + rtx pat = PATTERN (x); + + if (GET_CODE (pat) == SET) + { + rtx tmp = XEXP (pat, 1); + if (tmp + && ((GET_CODE (tmp) == UNSPEC + && XINT (tmp, 1) == UNSPEC_PAC_NOP) + || (GET_CODE (tmp) == UNSPEC_VOLATILE + && XINT (tmp, 1) == VUNSPEC_PACBTI_NOP))) + return true; + } + return false; } + /* Target specific mapping for aarch_gen_bti_c and aarch_gen_bti_j. + For Arm, both of these map to a simple BTI instruction. */ + +rtx +aarch_gen_bti_c (void) +{ + return gen_bti_nop (); +} + +rtx +aarch_gen_bti_j (void) +{ + return gen_bti_nop (); +} + /* Implement TARGET_SCHED_CAN_SPECULATE_INSN. Return true if INSN can be scheduled for speculative execution. Reject the long-running division and square-root instructions. */ |