RE: [PATCH v2] ARM: unwind: improve unwinders for noreturn case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Russell King
> Sent: 21 March 2024 13:08
> 
> On Thu, Mar 21, 2024 at 12:57:07PM +0000, David Laight wrote:
> > From: Russell King
> > > Sent: 21 March 2024 12:23
> > ...
> > > > That might mean you can get the BL in the middle of a function
> > > > but where the following instruction is for the 'no stack frame'
> > > > side of the branch.
> > > > That is very likely to break any stack offset calculations.
> > >
> > > No it can't. At any one point in the function, the stack has to be in
> > > a well defined state, so that access to local variables can work, and
> > > also the stack can be correctly unwound. If there exists a point in
> > > the function body which can be reached where the stack could be in two
> > > different states, then the stack can't be restored to the parent
> > > context.
> >
> > Actually you can get there with a function that has a lot of args.
> > So you can have:
> > 	if (...) {
> > 		push x
> > 		bl func
> > 		add %sp, #8
> > 	}
> > 	code;
> > which is fine.
> 
> No you can't.... and that isn't even Arm code. Arm doesn't use %sp.
> Moreover, that "bl" will stomp over the link register, meaning this
> function can not return.

With 9+ arguments they spill to see https://godbolt.org/z/Yj3ovd8bY

Where the compiler generates:
f9:
        cmp     w0, 0
        ble     .L2
        sub     sp, sp, #32
        mov     w7, w0
        mov     w6, w0
        mov     w5, w0
        mov     w4, w0
        mov     w3, w0
        stp     x29, x30, [sp, 16]
        add     x29, sp, 16
        mov     w2, w0
        mov     w1, w0
        str     w0, [sp]
        bl      f
.L2:
        ret


A traceback from inside f() definitely needs to use LR-4
for the stack offset.

(arm64 doesn't seem to support -mno-sched-prolog).

I've failed to get different sized stack frames for the true/false
sides of the branch.
The compiler seems to pre-allocate the space for extra args rather
than using 'push' type instructions.
This was certainly better for some x86 cpu (p-pro?) but has now
gone out of fashion.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)






[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux