From 459d4936aec6671d94a0a4be918d8efbbc130215 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Sun, 27 Feb 2022 01:09:05 +0800 Subject: fix GCC PR100017 and enable libstdc++ for pass 2 This is the issue preventing us from cross-compiling libstdc++ in Chapter 6. By fixing this issue we can remove a seperate pass 2 for libstdc++ and simplify the instruction. The upstream fix will be released in 11.3 and 12.0, so we can remove the first sed upgrading gcc next time. --- chapter06/gcc-pass2.xml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'chapter06') diff --git a/chapter06/gcc-pass2.xml b/chapter06/gcc-pass2.xml index bf3007848..6dd6f90a5 100644 --- a/chapter06/gcc-pass2.xml +++ b/chapter06/gcc-pass2.xml @@ -62,23 +62,24 @@ mv -v mpc-&mpc-version; mpc sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac - + + Fix an issue causing failure cross-compiling libstdc++: + +sed 's/gnu++17/& -nostdinc++/' \ + -i libstdc++-v3/src/c++17/Makefile.in + + Override the building rule of libgcc and libstdc++ headers, to + allow building these libraries with POSIX threads support: + +sed '/thread_header =/s/@.*@/gthr-posix.h/' \ + -i libgcc/Makefile.in libstdc++-v3/include/Makefile.in + Create a separate build directory again: mkdir -v build cd build - Create a symlink that allows libgcc to be built with posix threads - support: - -mkdir -pv $LFS_TGT/libgcc -ln -s ../../../libgcc/gthr-posix.h $LFS_TGT/libgcc/gthr-default.h - Before starting to build GCC, remember to unset any environment variables that override the default optimization flags. @@ -89,6 +90,8 @@ ln -s ../../../libgcc/gthr-posix.h $LFS_TGT/libgcc/gthr-default.h -- cgit v1.2.3-54-g00ecf From 8e0f8a9a521080c2f5fc460319e6d87b12d6039a Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Wed, 2 Mar 2022 17:50:41 +0800 Subject: gcc pass2: use --target=$LFS_TGT instead of many {C,CXX}_FOR_TARGET There is also a "GCC_FOR_TARGET" which was not set correctly. The --target=$LFS_TGT parameter can set up all of these variables as we expected. --- chapter06/gcc-pass2.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'chapter06') diff --git a/chapter06/gcc-pass2.xml b/chapter06/gcc-pass2.xml index 6dd6f90a5..d10b403e9 100644 --- a/chapter06/gcc-pass2.xml +++ b/chapter06/gcc-pass2.xml @@ -88,10 +88,9 @@ cd build ../configure \ --build=$(../config.guess) \ --host=$LFS_TGT \ - --prefix=/usr \ - CC_FOR_TARGET=$LFS_TGT-gcc \ - CXX_FOR_TARGET=$LFS_TGT-g++ \ + --target=$LFS_TGT \ LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc \ + --prefix=/usr \ --with-build-sysroot=$LFS \ --enable-initfini-array \ --disable-nls \ -- cgit v1.2.3-54-g00ecf From 3bb463d33d713d262b4864d8d3c6af08e25c77aa Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Tue, 1 Mar 2022 18:09:30 +0800 Subject: gcc-pass2: document *_FOR_TARGET parameters --- chapter06/gcc-pass2.xml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'chapter06') diff --git a/chapter06/gcc-pass2.xml b/chapter06/gcc-pass2.xml index d10b403e9..d76b9d9af 100644 --- a/chapter06/gcc-pass2.xml +++ b/chapter06/gcc-pass2.xml @@ -107,7 +107,7 @@ cd build The meaning of the new configure options: - -with-build-sysroot=$LFS + --with-build-sysroot=$LFS Normally, using --host ensures that a cross-compiler is used for building GCC, and that compiler knows @@ -119,6 +119,33 @@ cd build + + --target=$LFS_TGT + + As we are cross-compiling GCC, it's impossible to build + target libraries (libgcc + and libstdc++) with the + compiled GCC binaries because these binaries won't run on the + host distro. GCC building system will attempt to use the + C and C++ compilers on the host distro as a workaround by default. + It's not supported to build GCC target libraries with a different + version of GCC, so using host compilers may cause building + failure. This parameter ensures to build the libraries with GCC + pass 1 and prevent the issue. + + + + + LDFLAGS_FOR_TARGET=... + + Allow libstdc++ to + use shared libgcc being + built in this pass, instead of the static version built in GCC + pass 1. This is needed for supporting C++ exception + handling. + + + --enable-initfini-array -- cgit v1.2.3-54-g00ecf