Closed nmeum closed 1 month ago
Likely it is the code which aligns the stack pointer in makecontext.c which needs to be fixed here.
Most definitely so, the initial SP value set in makecontext.c is not 16-byte aligned. However, one also needs to adjust the setcontext.S, swapcontext.S and FETCH_LINKPTR implementations to operate on the new SP value and my x86 assembly skills are a bit too rusty for that.
Are we positive that the alignment issue has been fixed? gcc-go binaries still crash on x86. And the gdb instructions provided above still print an $esp
value which is not 16-byte aligned.
The x86 calling convention requires the stack pointer to be aligned on a 16-byte boundary. Otherwise, code using SSE instructions on x86 in conjunction with libucontext will just crash. This currently causes the gccgo runtime to crash on x86 Alpine Linux, see https://github.com/golang/go/issues/63935.
Independent of gccgo, we can reproduce this issue by inspecting SP values in the libucontext test suite:
From this debugging session, we can deduce that the stack pointer (
$esp
) is not aligned before the first call to theputs(3)
function in f2 (0xffffdbac % 16 == 12
). I believe this to be non-conformant with the x86 calling convention which requires it to be 16-byte aligned when calling a function.