[llvm] Do not use R12 for indirect tail calls with PACBTI (PR #82661)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 01:47:29 PDT 2024
ostannard wrote:
It looks like clang emits a module flag instead of a function attribute, so it applies to all functions in the module:
```
!4 = !{i32 8, !"sign-return-address", i32 1}
```
The attribute and flag are read by the `GetSignReturnAddress` function in `ARMMachineFunctionInfo.cpp`, with the function attribute taking priority over the module flag if both are present. This seems to work correctly for normal code-generation, so I'd expect it to work for these new instruction selection patterns too. Are you saying that this does not work if you test it end-to-end with clang, or when generating IR with clang?
For #81020, do you have a reproducer showing it not working correctly? I've tried a few simple examples and it seems to be working correctly, despite clang using module flags instead of function attributes:
```c
typedef void(func)(void);
void foo(func *fptr_arg) {
register func *fptr_x16 asm("x16") = fptr_arg;
asm("" : "+r" (fptr_x16) : : "lr");
fptr_x16();
}
```
```
$ /work/llvm/build/bin/clang --target=aarch64-none-elf -march=armv8.3-a -c indirect-tail.c -o - -S -O1 -mbranch-protection=pac-ret+pc | sed -n '/foo:/,/func_end/p'
foo: // @foo
// %bb.0: // %entry
hint #39
.Ltmp0:
paciasp
str x30, [sp, #-16]! // 8-byte Folded Spill
mov x16, x0
//APP
//NO_APP
mov x0, x16
ldr x30, [sp], #16 // 8-byte Folded Reload
adr x16, .Ltmp0
hint #39
autiasp
br x0
.Lfunc_end0:
```
https://github.com/llvm/llvm-project/pull/82661
More information about the llvm-commits
mailing list