> Split-stack prologue on function entry is as follow (this goes before the
> usual function prologue):
> mrs x9, tpidr_el0
> mov x10, -<required stack allocation>
As Jiong already remarked, the nop won't work. Do we know the maximum adjustment
that the linker is allowed to make? If so, and we can limit the adjustment to
most cases, emitting 2 subtracts is best. Larger offset need mov/movk/sub but
should be extremely rare.
> add x10, sp, x10
> ldr x9, [x9, 16]
Is there any need to detect underflow of x10 or is there a guarantee that
never allocated in the low 2GB (given the maximum adjustment is 2GB)? It's safe
to do a signed comparison.
> cmp x10, x9
> b.cs enough
Why save/restore x30 and the call x30+8 trick when we could pass the
continuation address and use a tailcall? That also avoids emitting extra unwind
> stp x30, [sp, -16]
> bl __morestack
> ldp x30, [sp], 16
This part doesn't make any sense - both x28 and carry flag as an input, and
across the prolog - why???
> mov x10, sp
> b.cs continue
> mov x10, x28
[rest of function]
Why not do this?
mrs x9, tpidr_el0
sub x10, sp, N & 0xfff000
sub x10, x10, N & 0xfff
ldr x9, [x9, 16]
adr x12, main_fn_entry
mov x11, sp [if function has stacked arguments]
cmp x10, x9
main_fn_entry: [x11 is argument pointer]
[rest of function]
In __morestack you need to save x8 as well (another argument register!) and x12
continuation address). After returning from the call x8 doesn't need to be
There are several issues with unwinding in __morestack. x28 is not described as
so will be corrupted if unwinding across a __morestack call. This won't unwind
the ldp as the unwinder will use the restored frame pointer to try to restore
+ ldp x29, x30, [x28, STACKFRAME_BASE]
+ ldr x28, [x28, STACKFRAME_BASE + 80]
+ .cfi_restore 30
+ .cfi_restore 29
+ .cfi_def_cfa 31, 0
This stores a random x30 value on the stack, what is the purpose of this?
Nothing can unwind
+ # Start using new stack
+ stp x29, x30, [x0, -16]!
+ mov sp, x0
Also we no longer need split_stack_arg_pointer_used_p () or any code that uses
that don't have any arguments passed on the stack could omit the mov x11, sp).