[llvm][AArch64] Insert "bti j" after call to setjmp
authorDavid Spickett <david.spickett@linaro.org>
Mon, 14 Mar 2022 10:24:45 +0000 (10:24 +0000)
committerDavid Spickett <david.spickett@linaro.org>
Wed, 23 Mar 2022 09:51:02 +0000 (09:51 +0000)
commiteb5ecbbcbb6ce38e29237ab5d17156fcb2e96e74
treec71db334a50e5a96a4a663828762dc13114422d4
parenta451a291278b22b031b2b6d8ca4a3b2517a491f6
[llvm][AArch64] Insert "bti j" after call to setjmp

Some implementations of setjmp will end with a br instead of a ret.
This means that the next instruction after a call to setjmp must be
a "bti j" (j for jump) to make this work when branch target identification
is enabled.

The BTI extension was added in armv8.5-a but the bti instruction is in the
hint space. This means we can emit it for any architecture version as long
as branch target enforcement flags are passed.

The starting point for the hint number is 32 then call adds 2, jump adds 4.
Hence "hint #36" for a "bti j" (and "hint #34" for the "bti c" you see
at the start of functions).

The existing Arm command line option -mno-bti-at-return-twice has been
applied to AArch64 as well.

Support is added to SelectionDAG Isel and GlobalIsel. FastIsel will
defer to SelectionDAG.

Based on the change done for M profile Arm in https://reviews.llvm.org/D112427

Fixes #48888

Reviewed By: danielkiss

Differential Revision: https://reviews.llvm.org/D121707
14 files changed:
clang/docs/ClangCommandLineReference.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
llvm/lib/Target/AArch64/AArch64FastISel.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp
llvm/test/CodeGen/AArch64/setjmp-bti-no-enforcement.ll [new file with mode: 0644]
llvm/test/CodeGen/AArch64/setjmp-bti-outliner.ll [new file with mode: 0644]
llvm/test/CodeGen/AArch64/setjmp-bti.ll [new file with mode: 0644]