https://bugs.winehq.org/show_bug.cgi?id=55470
Bug ID: 55470 Summary: i686-w64-mingw32-gcc assumes wrong stack alignment Product: Wine Version: unspecified Hardware: x86 OS: Linux Status: NEW Severity: normal Priority: P2 Component: build-env Assignee: wine-bugs@winehq.org Reporter: stefan@codeweavers.com Distribution: ---
Created attachment 75028 --> https://bugs.winehq.org/attachment.cgi?id=75028 Example C code to show the issue
This is probably not a Wine bug, but something we may want to document and take care of one way or another:
i686-w64-mingw32-gcc quietly assumes 16 byte stack alignment, which is wrong for Win32. To see the effect compile and disassemble the attached test.c with
i686-w64-mingw32-gcc test.c -c -O2 i686-w64-mingw32-objdump -d test.o
The outcome: 0: 81 ec ac 01 00 00 sub $0x1ac,%esp 6: 8d 44 24 10 lea 0x10(%esp),%eax a: 89 04 24 mov %eax,(%esp) d: e8 00 00 00 00 call 12 <_func+0x12> 12: 81 c4 ac 01 00 00 add $0x1ac,%esp 18: c3 ret
However, x86_64-w64-mingw32-gcc -m32 properly aligns the stack before placing the aligned structure:
x86_64-w64-mingw32-gcc test.c -c -O2 -m32 i686-w64-mingw32-objdump -d test.o 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 e4 f0 and $0xfffffff0,%esp 6: 81 ec a0 01 00 00 sub $0x1a0,%esp c: 8d 44 24 10 lea 0x10(%esp),%eax 10: 89 04 24 mov %eax,(%esp) 13: e8 00 00 00 00 call 18 <_func+0x18> 18: c9 leave 19: c3 ret
To my knowledge Wine does not use SSE instructions on purpose, so we should be mostly fine. msvcrt, wined3d or dsound (especially when compiled to use SSE to make Rosetta 2 happy) may be affected.
The test.c file is attached.
What can we do about it?
1) Ignore it 2) pass -mincoming-stack-boundary=2 to mingw for 32 bit targets 3) Use 64 bit target mingw with -m32
I'll file a bug for mingw too, linking this bug as reference.