This is an archive of the discontinued LLVM Phabricator instance.

[llvm][AArch64] Insert "bti j" after call to setjmp
ClosedPublic

Authored by DavidSpickett on Mar 15 2022, 8:21 AM.

Details

Summary

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

Diff Detail

Event Timeline

DavidSpickett created this revision.Mar 15 2022, 8:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2022, 8:21 AM
DavidSpickett requested review of this revision.Mar 15 2022, 8:21 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 15 2022, 8:21 AM
danielkiss accepted this revision.Mar 21 2022, 2:14 AM
danielkiss added a subscriber: danielkiss.

Add to the commit message Fixes #48888 to make the connection on github.

LGTM

llvm/lib/Target/AArch64/AArch64InstrInfo.td
480–481
This revision is now accepted and ready to land.Mar 21 2022, 2:14 AM
DavidSpickett edited the summary of this revision. (Show Details)Mar 21 2022, 4:00 AM
DavidSpickett marked an inline comment as done.
This revision was landed with ongoing or failed builds.Mar 23 2022, 2:51 AM
This revision was automatically updated to reflect the committed changes.