Skip to content

Commit 56ea6bc

Browse files
committed
Fix the description, add a test case
1 parent 0398d2e commit 56ea6bc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,19 @@ class MCPlusBuilder {
640640
/// it may be important for the compiler to check the address explicitly not
641641
/// to introduce a signing or authentication oracle.
642642
///
643-
/// If this function returns a (Reg, Inst) pair and before execution of Inst
643+
/// This function is intended to detect a complex, multi-instruction pointer-
644+
/// checking sequence spanning a contiguous range of instructions at the end
645+
/// of the basic block (as these sequences are expected to end with a
646+
/// conditional branch - this is how they are implemented on AArch64 by LLVM).
647+
/// If a (Reg, FirstInst) pair is returned and before execution of FirstInst
644648
/// Reg was last written to by an authentication instruction, then it is known
645649
/// that in any successor of BB either
646650
/// * the authentication instruction that last wrote to Reg succeeded, or
647651
/// * the program is terminated abnormally without introducing any signing
648652
/// or authentication oracles
653+
///
654+
/// Note that this function is not expected to repeat the results returned
655+
/// by getAuthCheckedReg(Inst, MayOverwrite) function below.
649656
virtual std::optional<std::pair<MCPhysReg, MCInst *>>
650657
getAuthCheckedReg(BinaryBasicBlock &BB) const {
651658
llvm_unreachable("not implemented");
@@ -660,6 +667,9 @@ class MCPlusBuilder {
660667
///
661668
/// Additionally, if MayOverwrite is false, it is known that the authenticated
662669
/// pointer is not clobbered by Inst itself.
670+
///
671+
/// Use this function for simple, single-instruction patterns instead of
672+
/// its getAuthCheckedReg(BB) counterpart.
663673
virtual MCPhysReg getAuthCheckedReg(const MCInst &Inst,
664674
bool MayOverwrite) const {
665675
llvm_unreachable("not implemented");

bolt/test/binary-analysis/AArch64/gs-pauth-address-checks.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,33 @@ resign_load_unscaled_good:
629629
ret
630630
.size resign_load_unscaled_good, .-resign_load_unscaled_good
631631

632+
// Any basic block can check at most one register using a multi-instruction
633+
// pointer-checking sequence, but it can contain an arbitrary number of single-
634+
// instruction pointer checks.
635+
636+
.globl many_checked_regs
637+
.type many_checked_regs,@function
638+
many_checked_regs:
639+
// CHECK-NOT: many_checked_regs
640+
autdzb x0
641+
autdzb x1
642+
autdzb x2
643+
b 1f
644+
1:
645+
ldr w3, [x0] // single-instruction check
646+
ldr w3, [x1] // single-instruction check
647+
mov x16, x2 // start of multi-instruction checker sequence
648+
xpacd x16 // ...
649+
cmp x2, x16 // ...
650+
b.eq 2f // end of basic block
651+
brk 0x1234
652+
2:
653+
pacdza x0
654+
pacdza x1
655+
pacdza x2
656+
ret
657+
.size many_checked_regs, .-many_checked_regs
658+
632659
.globl main
633660
.type main,@function
634661
main:

0 commit comments

Comments
 (0)