I'm trying to build Linux From Scratch 12.3 systemd, but the last (third, in chapter 8) gcc compilation fails. Apparently, is a problem with the 'mulxc3' function. These are the last lines of the log file:
/sources/gcc-14.2.0/build/./gcc/xgcc -B/sources/gcc-14.2.0/build/./gcc/ -B/usr/x86_64-pc-linux-gnu/bin/ -B/usr/x86_64-pc-linux-gnu/lib/ -isystem /usr/x86_64-pc-linux-gnu/include -isystem /usr/x86_64-pc-linux-gnu/sys-include -g -O2 -O2 -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fpic -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -I. -I. -I../.././gcc -I../../../libgcc -I../../../libgcc/. -I../../../libgcc/../gcc -I../../../libgcc/../include -I../../../libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_TLS -o _mulxc3.o -MT _mulxc3.o -MD -MP -MF _mulxc3.dep -DL_mulxc3 -c ../../../libgcc/libgcc2.c -fvisibility=hidden -DHIDE_EXPORTS
during RTL pass: expand
In file included from ../../../libgcc/libgcc2.c:56:
../../../libgcc/libgcc2.c: In function '__mulxc3':
../../../libgcc/libgcc2.h:269:17: internal compiler error: Illegal instruction
269 | #define __N(a) __ ## a
| ^~
../../../libgcc/libgcc2.h:370:33: note: in expansion of macro '__N'
370 | #define __mulxc3 __N(mulxc3)
| ^~~
../../../libgcc/libgcc2.c:2667:25: note: in expansion of macro '__mulxc3'
2667 | #define _CONCAT3(A,B,C) A##B##C
| ^
../../../libgcc/libgcc2.c:2666:25: note: in expansion of macro '_CONCAT3'
2666 | #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
| ^~~~~~~~
../../../libgcc/libgcc2.c:2697:1: note: in expansion of macro 'CONCAT3'
2697 | CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
| ^~~~~~~
0x561776d6d973 crash_signal
../../gcc/toplev.cc:319
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
What I find strange is that the first two compilations of gcc (in chapters 5 and 6) run fine.
Below are the configurations for each gcc build:
Chapter 5
../configure \
--target=$LFS_TGT \
--prefix=$LFS/tools \
--with-glibc-version=2.41 \
--with-sysroot=$LFS \
--with-newlib \
--without-headers \
--enable-default-pie \
--enable-default-ssp \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-threads \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libssp \
--disable-libvtv \
--disable-libstdcxx \
--enable-languages=c,c++
Chapter 6
../configure \
--build=$(../config.guess) \
--host=$LFS_TGT \
--target=$LFS_TGT \
LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc \
--prefix=/usr \
--with-build-sysroot=$LFS \
--enable-default-pie \
--enable-default-ssp \
--disable-nls \
--disable-multilib \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--enable-languages=c,c++
Chapter 8
../configure --prefix=/usr \
LD=ld \
--enable-languages=c,c++ \
--enable-default-pie \
--enable-default-ssp \
--enable-host-pie \
--disable-multilib \
--disable-bootstrap \
--disable-fixincludes \
--with-system-zlib
For context, I'm using Linux Mint 21 as a base system in a VirtualBox (Windows 10 host). I'm cross-compiling everything with optimizations for the target system (with -march=slm), except gcc. I've also tried with other flag (-march=core2) and without optimization, and still get the same result.
If anyone has any clue, or idea that I can try to get gcc to compile, please let me know. Thank you.
I'm posting this in case someone else stumbles across the same issue.
I've tried forcing long double to be 64-bit with --with-long-double-64 as apparently it can trigger the error with __mulxc3, but didn't work.
Also tried building without optimization, and got the same error. After failing to build with the same options for configure and make as in chapters 5 and 6 (that worked fine before), I realized some other package was the problem.
It turns out I somehow overlooked a bit caution remark on the LFS book when building gmp, that clearly states:
"The code in gmp is highly optimized for the processor where it is built. Occasionally, the code that detects the processor misidentifies the system capabilities and there will be errors in the tests or other applications using the gmp libraries with the message Illegal instruction
. In this case, gmp should be reconfigured with the option --host=none-linux-gnu
and rebuilt."
I recompiled gmp with that option and everything worked fine when compiling gcc with optimizations.
In short: read the book thoroughly.