This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Remove redundant BTI instructions for table jumps
ClosedPublic

Authored by JiruiWu on Feb 21 2023, 3:52 AM.

Details

Summary

A BTI instruction was previously inserted at the beginning of each block
that has its address stored in a jump table. Jump tables only emit
indirect jumps in ARM or Thumb1 modes. However, PACBTI is not supported
in these modes. As a result, BTI instructions emitted by jump tables are
redundant. Removing redundant BTI instructions improves the code size
and prevents potential gadgets.

Diff Detail

Event Timeline

JiruiWu created this revision.Feb 21 2023, 3:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 3:52 AM
JiruiWu requested review of this revision.Feb 21 2023, 3:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 3:52 AM
olista01 added inline comments.Feb 21 2023, 9:00 AM
llvm/lib/Target/ARM/ARMBranchTargets.cpp
67–68

This comment can be removed too.

llvm/test/MC/AArch64/remove-redundant-bti.s
1 ↗(On Diff #499105)

The filename for this should end in .ll, because it contains IR, not assembly.

30 ↗(On Diff #499105)

These tests should also check the tbb/tbh/mov instructions which branch to these labels, to make sure that the two test cases are testing different was of implementing jump tables.

JiruiWu updated this revision to Diff 499219.Feb 21 2023, 10:00 AM

Addressed review comments.

JiruiWu marked an inline comment as done.Feb 21 2023, 10:02 AM
This revision is now accepted and ready to land.Feb 24 2023, 12:55 AM
This revision was landed with ongoing or failed builds.Feb 24 2023, 2:33 AM
This revision was automatically updated to reflect the committed changes.