[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZOogWznEtMBZc5iE@biznet-home.integral.gnuweeb.org>
Date:   Sat, 26 Aug 2023 22:55:07 +0700
From:   Ammar Faizi <ammarfaizi2@...weeb.org>
To:     Zhangjin Wu <falcon@...ylab.org>
Cc:     Willy Tarreau <w@....eu>,
        Thomas Weißschuh <linux@...ssschuh.net>,
        Ammar Faizi <ammarfaizi2@...weeb.org>,
        Nicholas Rosenberg <inori@...x.org>,
        GNU/Weeb Mailing List <gwml@...r.gnuweeb.org>,
        Michael William Jonathan <moe@...weeb.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v1 1/1] tools/nolibc: i386: Fix a stack misalign bug on
 _start
On Sat, Aug 26, 2023 at 11:07:04PM +0800, Zhangjin Wu wrote:
> > @@ -167,7 +167,8 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
> >  	__asm__ volatile (
> >  		"xor  %ebp, %ebp\n"       /* zero the stack frame                                */
> >  		"mov  %esp, %eax\n"       /* save stack pointer to %eax, as arg1 of _start_c     */
> > -		"and  $-16, %esp\n"       /* last pushed argument must be 16-byte aligned        */
> > +		"and  $-16, %esp\n"       /* align stack to 16 bytes                             */
> > +		"sub  $12, %esp\n"        /* last pushed argument must be 16-byte aligned        */
> 
> Ammar, the new call of _start_c() only requires a single push, it pushes
> the argument and minus %esp by 4, so, the alignment of %esp requires to
> minus 12 to reserve 16-byte alignment, is this description right?
Yes, that's correct.
> If so, What about further?
> 
>     "and  $-16, %esp\n"       /* align stack to 16 bytes                             */
>     "sub ($16 - $4), %esp"    /* the 'push %eax' breaks stack alignment, fix up it   */
The sub part should have been:
    "sub  $(16 - 4), %esp\n"
It's fine to me writing it that way too.
-- 
Ammar Faizi
Powered by blists - more mailing lists
 
