Cranelift AArch64: Fix the get_return_address lowering (#4851)

The previous implementation assumed that nothing had clobbered the
LR register since the current function had started executing, so
it would be incorrect for a non-leaf function, for example, that
contains the `get_return_address` operation right after a call.
The operation is valid only if the `preserve_frame_pointers` flag
is enabled, which implies that the presence of a frame record on
the stack is guaranteed.

Copyright (c) 2022, Arm Limited.
This commit is contained in:
Anton Kirilov
2022-09-07 19:09:22 +01:00
committed by GitHub
parent e977f6a79d
commit dd07e354b4
7 changed files with 97 additions and 11 deletions

View File

@@ -0,0 +1,47 @@
test compile precise-output
set preserve_frame_pointers=true
target aarch64 sign_return_address
function %fp() -> i64 {
block0:
v0 = get_frame_pointer.i64
return v0
}
; paciasp
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; block0:
; mov x0, fp
; ldp fp, lr, [sp], #16
; autiasp ; ret
function %sp() -> i64 {
block0:
v0 = get_stack_pointer.i64
return v0
}
; paciasp
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; block0:
; mov x0, sp
; ldp fp, lr, [sp], #16
; autiasp ; ret
function %return_address() -> i64 {
block0:
v0 = get_return_address.i64
return v0
}
; paciasp
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; block0:
; ldr lr, [fp, #8]
; xpaclri
; mov x0, lr
; ldp fp, lr, [sp], #16
; autiasp ; ret

View File

@@ -37,7 +37,6 @@ block0:
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; block0:
; mov x0, lr
; ldr x0, [fp, #8]
; ldp fp, lr, [sp], #16
; ret