[AArch64, 5/6] Enable BTI : Add new pass for BTI.
authorSudakshina Das <sudi.das@arm.com>
Wed, 9 Jan 2019 14:21:22 +0000 (14:21 +0000)
committerSudakshina Das <sudi@gcc.gnu.org>
Wed, 9 Jan 2019 14:21:22 +0000 (14:21 +0000)
commitb5f794b47bc09930e3a05b64de0890d315631436
tree42d0229f90e50a750e4e74a9c304b1bfb86af2c3
parent30afdf34a6d6a3d8d31fdd590ba60044cf0e004c
[AArch64, 5/6] Enable BTI : Add new pass for BTI.

This patch is part of a series that enables ARMv8.5-A in GCC and
adds Branch Target Identification Mechanism.

This patch adds a new pass called "bti" which is triggered by the command
line argument -mbranch-protection whenever "bti" is turned on.

The pass iterates through the instructions and adds appropriated BTI
instructions based on the following:
  * Add a new "BTI C" at the beginning of a function, unless its already
    protected by a "PACIASP". We exempt the functions that are only called
    directly.
  * Add a new "BTI J" for every target of an indirect jump, jump table
    targets, non-local goto targets or labels that might be referenced by
    variables, constant pools, etc (NOTE_INSN_DELETED_LABEL).

Since we have already changed the use of indirect tail calls to only x16 and
x17, we do not have to use "BTI JC".
(check patch 3/6).

*** gcc/ChangeLog ***

2018-01-09  Sudakshina Das  <sudi.das@arm.com>
    Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>

* config.gcc (aarch64*-*-*): Add aarch64-bti-insert.o.
* gcc/config/aarch64/aarch64.h: Update comment for TRAMPOLINE_SIZE.
* config/aarch64/aarch64.c (aarch64_asm_trampoline_template): Update
if bti is enabled.
* config/aarch64/aarch64-bti-insert.c: New file.
* config/aarch64/aarch64-passes.def (INSERT_PASS_BEFORE): Insert bti
pass.
* config/aarch64/aarch64-protos.h (make_pass_insert_bti): Declare the
new bti pass.
* config/aarch64/aarch64.md (unspecv): Add UNSPECV_BTI_NOARG,
UNSPECV_BTI_C, UNSPECV_BTI_J and UNSPECV_BTI_JC.
(bti_noarg, bti_j, bti_c, bti_jc): New define_insns.
* config/aarch64/t-aarch64: Add rule for aarch64-bti-insert.o.

*** gcc/testsuite/ChangeLog ***

2018-01-09  Sudakshina Das  <sudi.das@arm.com>

* gcc.target/aarch64/bti-1.c: New test.
* gcc.target/aarch64/bti-2.c: New test.
* gcc.target/aarch64/bti-3.c: New test.
* lib/target-supports.exp
(check_effective_target_aarch64_bti_hw): Add new check for BTI hw.

Co-Authored-By: Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
From-SVN: r267769
14 files changed:
gcc/ChangeLog
gcc/config.gcc
gcc/config/aarch64/aarch64-bti-insert.c [new file with mode: 0644]
gcc/config/aarch64/aarch64-passes.def
gcc/config/aarch64/aarch64-protos.h
gcc/config/aarch64/aarch64.c
gcc/config/aarch64/aarch64.h
gcc/config/aarch64/aarch64.md
gcc/config/aarch64/t-aarch64
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/bti-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/bti-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/bti-3.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp