diff --git a/chapter05/gcc-pass1.xml b/chapter05/gcc-pass1.xml index cbd3456b4..1ac142dde 100644 --- a/chapter05/gcc-pass1.xml +++ b/chapter05/gcc-pass1.xml @@ -80,6 +80,12 @@ esac -i.orig gcc/config/i386/t-linux64 + Make -mstackrealign a default for 32bit + objects: + +sed '/STACK_REALIGN_DEFAULT/s/0/(!TARGET_64BIT \&\& TARGET_SSE)/' \ + -i gcc/config/i386/i386.h + The GCC documentation recommends building GCC in a dedicated build directory: diff --git a/chapter06/gcc-pass2.xml b/chapter06/gcc-pass2.xml index db4e73605..4d4b27ca9 100644 --- a/chapter06/gcc-pass2.xml +++ b/chapter06/gcc-pass2.xml @@ -75,6 +75,12 @@ esac -e '/m32=/s/m32=.*/m32=..\/lib32$(call if_multiarch,:i386-linux-gnu)/' \ -i.orig gcc/config/i386/t-linux64 + Make -mstackrealign a default for 32bit + objects: + +sed '/STACK_REALIGN_DEFAULT/s/0/(!TARGET_64BIT \&\& TARGET_SSE)/' \ + -i gcc/config/i386/i386.h + Override the building rule of libgcc and libstdc++ headers, to allow building these libraries with POSIX threads support: diff --git a/chapter08/gcc.xml b/chapter08/gcc.xml index 641cf890c..4624443c6 100644 --- a/chapter08/gcc.xml +++ b/chapter08/gcc.xml @@ -58,6 +58,12 @@ esac -e '/m32=/s/m32=.*/m32=..\/lib32$(call if_multiarch,:i386-linux-gnu)/' \ -i.orig gcc/config/i386/t-linux64 + Make -mstackrealign a default for 32bit + objects: + +sed '/STACK_REALIGN_DEFAULT/s/0/(!TARGET_64BIT \&\& TARGET_SSE)/' \ + -i gcc/config/i386/i386.h + The GCC documentation recommends building GCC in a dedicated build directory: mkdir -v build diff --git a/chapter08/glibc.xml b/chapter08/glibc.xml index 03d427031..ed79fc887 100644 --- a/chapter08/glibc.xml +++ b/chapter08/glibc.xml @@ -624,8 +624,7 @@ find .. -name "*.a" -delete Configure Glibc for m32 with the following commands: -CC="gcc -m32 -mstackrealign" \ -CXX="g++ -m32 -mstackrealign" \ +CC="gcc -m32" CXX="g++ -m32" \ ../configure \ --prefix=/usr \ --host=i686-pc-linux-gnu \ @@ -636,40 +635,6 @@ CXX="g++ -m32 -mstackrealign" \ --libexecdir=/usr/lib32 \ libc_cv_slibdir=/usr/lib32 - Adding the -mstackrealign flag helps to - overcome issues with old binaries which cannot be recompiled - 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: make