Skip to content

Commit ebbe0d8

Browse files
wtarreaupaulmckrcu
authored andcommitted
tools/nolibc: i386: fix initial stack alignment
After re-checking in the spec and comparing stack offsets with glibc, The last pushed argument must be 16-byte aligned (i.e. aligned before the call) so that in the callee esp+4 is multiple of 16, so the principle is the 32-bit equivalent to what Ammar fixed for x86_64. It's possible that 32-bit code using SSE2 or MMX could have been affected. In addition the frame pointer ought to be zero at the deepest level. Link: https://gitlab.com/x86-psABIs/i386-ABI/-/wikis/Intel386-psABI Cc: Ammar Faizi <ammar.faizi@students.amikom.ac.id> Cc: stable@vger.kernel.org Signed-off-by: Willy Tarreau <w@1wt.eu> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 937ed91 commit ebbe0d8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tools/include/nolibc/nolibc.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,21 @@ struct sys_stat_struct {
583583
})
584584

585585
/* startup code */
586+
/*
587+
* i386 System V ABI mandates:
588+
* 1) last pushed argument must be 16-byte aligned.
589+
* 2) The deepest stack frame should be set to zero
590+
*
591+
*/
586592
asm(".section .text\n"
587593
".global _start\n"
588594
"_start:\n"
589595
"pop %eax\n" // argc (first arg, %eax)
590596
"mov %esp, %ebx\n" // argv[] (second arg, %ebx)
591597
"lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx)
592-
"and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned when
598+
"xor %ebp, %ebp\n" // zero the stack frame
599+
"and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned before
600+
"sub $4, %esp\n" // the call instruction (args are aligned)
593601
"push %ecx\n" // push all registers on the stack so that we
594602
"push %ebx\n" // support both regparm and plain stack modes
595603
"push %eax\n"

0 commit comments

Comments
 (0)