From 148511312891f05034be13900cae434e0414457f Mon Sep 17 00:00:00 2001 From: Thomas Trepl Date: Fri, 8 Nov 2024 13:18:30 +0100 Subject: [PATCH] Add explanation --- chapter08/glibc.xml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/chapter08/glibc.xml b/chapter08/glibc.xml index efc9318c1..03d427031 100644 --- a/chapter08/glibc.xml +++ b/chapter08/glibc.xml @@ -638,7 +638,37 @@ CXX="g++ -m32 -mstackrealign" \ Adding the -mstackrealign flag helps to overcome issues with old binaries which cannot be recompiled - on the actual OS. + on the actual OS. Those issues were reported for + Steam. + + + Today the x86-32 SysV psABI (used by all Linux programs) + mandates a 16-byte alignment of the stack frame, so the routines + using SSE will save/load SSE vectors onto/from the stack using a + movaps instruction (which only works with + aligned addresses, but faster than its counterpart allowing + unaligned addresses, movups). + But some really old x86-32 Linux binaries (compiled about + 15 years ago), and all Windows x86-32 binaries only aligns the + stack frame to 4-byte. Thus, when it calls a SSE routine in LFS + built without -mstackrealign, the + movdqa instruction fails with a General + Protection Error and the Linux kernel terminates the process + with a SIGSEGV. + It is not clear why this seems to be an issue with Glibc only. + gcc -m32 does not turn off SSE (because + it means "building a 32-bit program for x86_64" instead of + "building a program for i686," and all x86_64 CPU have SSE), so + every library can use SSE. Steam has + an issue here, but Wine has not. + Maybe Wine evades the issue by building + most libraries as Windows DLLs using mingw-gcc (which enables + -mstackrealign by default) instead of relying + on the system library, but it still uses the system libc. + In theory, the -mstackrealign should be + applied for all m32 libraries but actually, the only issue + reported so far can be fixed by adding it to glibc in the above + command only. Compile the package: