<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58072>58072</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Miscompilation with ShadowCallStack + PAC-RET + -march=armv8.3a
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pcc
</td>
</tr>
</table>
<pre>
```
> echo 'void g(void); int f(void) { g(); return 0; }' | ra/bin/clang -fsanitize=shadow-call-stack -ffixed-x18 -march=armv8.3a -mbranch-protection=pac-ret -target aarch64-linux -S -o - -x c -
.text
.section .note.gnu.property,"a",@note
.p2align 3, 0x0
.word 4
.word 16
.word 5
.asciz "GNU"
.word 3221225472
.word 4
.word 2
.word 0
.Lsec_end0:
.text
.file "-"
.globl f // -- Begin function f
.p2align 2
.type f,@function
f: // @f
.cfi_startproc
// %bb.0: // %entry
str x30, [x18], #8
.cfi_escape 0x16, 0x12, 0x02, 0x82, 0x78 //
pacia x30, sp
.cfi_negate_ra_state
stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
.cfi_def_cfa_offset 16
mov x29, sp
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
bl g
mov w0, wzr
.cfi_def_cfa wsp, 16
ldp x29, x30, [sp], #16 // 16-byte Folded Reload
.cfi_def_cfa_offset 0
ldr x30, [x18, #-8]!
.cfi_restore w18
.cfi_restore w30
.cfi_restore w29
retaa
.Lfunc_end0:
.size f, .Lfunc_end0-f
.cfi_endproc
// -- End function
.ident "clang version 16.0.0"
.section ".note.GNU-stack","",@progbits
.addrsig
.addrsig_sym g
```
On return an unsigned pointer is being loaded from the shadow call stack and authenticated, which will fail because it is unsigned. The compiler should at least be using AUTIASP before the SCS load instead of RETAA, but given that the signing operation here is almost completely useless since we're using a return address loaded from the SCS instead of the one loaded from the stack it would probably be better to arrange for the pointer on the SCS to be signed instead.
</pre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