lkml.org 
[lkml]   [2023]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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

\
 
 \ /
  Last update: 2023-08-26 17:56    [W:0.055 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site