If I may ask a follow up question. I am having a similar issue with llc (or is it better to create a separate question thread for it?)
Is there a way to instruct llc to “support” the @llvm.ptrauth.resign.load.relative intrinsic?
Consider the following test.ll IR:
; Declare the intrinsic
declare i64 @llvm.ptrauth.resign.load.relative(i64, i32 immarg, i64, i32 immarg, i64, i64 immarg)
define i64 @test_resign(i64 %ptr) {
entry:
; Just call the intrinsic with some dummy arguments
%res = call i64 @llvm.ptrauth.resign.load.relative(
i64 %ptr,
i32 0,
i64 42,
i32 0,
i64 42,
i64 0
)
ret i64 %res
}
When llc is used to compile it into a binary,
llc -mtriple=arm64e-apple-macosx26.0 test.ll -o -
I am getting the following incorrect assembly, where the intrinsic is treated as a function call:
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 26, 0
.globl _test_resign ; -- Begin function test_resign
.p2align 2
_test_resign: ; @test_resign
.cfi_startproc
; %bb.0: ; %entry
stp x29, x30, [sp, #-16]! ; 16-byte Folded Spill
.cfi_def_cfa_offset 16
.cfi_offset w30, -8
.cfi_offset w29, -16
mov w1, #0 ; =0x0
mov w2, #42 ; =0x2a
mov w3, #0 ; =0x0
mov w4, #42 ; =0x2a
mov x5, #0 ; =0x0
bl _llvm.ptrauth.resign.load.relative
ldp x29, x30, [sp], #16 ; 16-byte Folded Reload
ret
.cfi_endproc
; -- End function
.subsections_via_symbols
however when I use clang driver, like this clang -S -target arm64e-apple-macosx26.0 test.ll -o test.s I am getting correct assembly with signing instructions:
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 11, 0
.globl _test_resign ; -- Begin function test_resign
.p2align 2
_test_resign: ; @test_resign
.cfi_startproc
; %bb.0: ; %entry
mov x16, x0
mov x17, #42 ; =0x2a
autia x16, x17
mov x17, x16
xpaci x17
cmp x16, x17
b.eq Lauth_success_0
mov x16, x17
b Lresign_end_0
Lauth_success_0:
ldrsw x17, [x16, #0]!
add x16, x16, x17
mov x17, #42 ; =0x2a
pacia x16, x17
Lresign_end_0:
mov x0, x16
ret
.cfi_endproc
; -- End function
.subsections_via_symbols
Interestingly, other more common ptrauth intrinsics, like @llvm.ptrauth.sign, are treated correctly by both llc and clang.
I tried several llvm branches, including one that comes with Apple Swift 6.2 repo, and none of them have llc support this intrinsic “by default”.
I am wondering if llc binary may have some hidden arguments that would enable such intrinsics?