From 4e82d4787a775438ce10fc7e3ccefe9fcd23ccd0 Mon Sep 17 00:00:00 2001 From: Jeremy Huntwork Date: Fri, 5 Dec 2008 20:46:02 +0000 Subject: Bring in DIY's next generation build method. Move GRUB to chapter 8. git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@8755 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689 --- chapter05/adjusting.xml | 77 ++++++---------------- chapter05/binutils-pass1.xml | 59 ++++------------- chapter05/binutils-pass2.xml | 51 +++++++++++--- chapter05/chapter05.xml | 6 +- chapter05/gcc-pass1.xml | 75 +++++++-------------- chapter05/gcc-pass2.xml | 139 +++++++++++++++++++++++---------------- chapter05/glibc.xml | 62 +++++++---------- chapter05/toolchaintechnotes.xml | 16 +++-- 8 files changed, 214 insertions(+), 271 deletions(-) (limited to 'chapter05') diff --git a/chapter05/adjusting.xml b/chapter05/adjusting.xml index a916e3621..dc02f05e5 100644 --- a/chapter05/adjusting.xml +++ b/chapter05/adjusting.xml @@ -12,26 +12,13 @@ Now that the temporary C libraries have been installed, all tools compiled in the rest of this chapter should be linked against - these libraries. In order to accomplish this, the linker and the - compiler's specs file need to be adjusted. - - The linker, adjusted at the end of the first pass of Binutils, needs - to be renamed so that it can be properly found and used. First, backup the - original linker, then replace it with the adjusted linker. We'll also - create a link to its counterpart in - /tools/$(gcc -dumpmachine)/bin: - -mv -v /tools/bin/{ld,ld-old} -mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old} -mv -v /tools/bin/{ld-new,ld} -ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld - - From this point onwards, everything will link only against the - libraries in /tools/lib. - - The next task is to point GCC to the new dynamic linker. This is done by - dumping GCC's specs file to a location where GCC will look for it - by default. A simple sed substitution then alters the + these libraries. In order to accomplish this, the cross-compiler's + specs file needs to be adjusted to point to the new dynamic linker + in /tools. + + This is done by dumping the compiler's specs file to a + location where it will look for it by default. + A simple sed substitution then alters the dynamic linker that GCC will use. The principle here is to find all references to the dynamic linker file in /lib or possibly /lib64 if the host system @@ -46,28 +33,12 @@ ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld of the dynamic linker, if necessary. -gcc -dumpspecs | sed 's@/lib\(64\)\?/ld@/tools&@g' > \ - `dirname $(gcc -print-libgcc-file-name)`/specs - - During the build process, GCC runs a script - (fixincludes) that scans the system for header files - that may need to be fixed (they might contain syntax errors, for example), - and installs the fixed versions in a private include directory. There is a - possibility that, as a result of this process, some header files from the - host system have found their way into GCC's private include directory. As - the rest of this chapter only requires the headers from GCC and Glibc, - which have both been installed at this point, any fixed - headers can safely be removed. This helps to avoid any host headers - polluting the build environment. Run the following commands to remove the - header files in GCC's private include directory (you may find it easier to - copy and paste these commands, rather than typing them by hand, due to - their length): - - -GCC_FIXED=`dirname $(gcc -print-libgcc-file-name)`/include-fixed && -find ${GCC_FIXED}/* -maxdepth 0 -xtype d -exec rm -rvf '{}' \; && -rm -vf `grep -l "DO NOT EDIT THIS FILE" ${GCC_FIXED}/*` && -unset GCC_FIXED +SPECS=`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/specs +$LFS_TGT-gcc -dumpspecs | sed \ + -e 's@/lib\(64\)\?/ld@/tools&@g' \ + -e "/^\*cpp:$/{n;s,$, -isystem /tools/include,}" > $SPECS +echo "New specs file is: $SPECS" +unset SPECS At this point, it is imperative to stop and ensure that the basic @@ -75,7 +46,7 @@ unset GCC_FIXED expected. To perform a sanity check, run the following commands: echo 'main(){}' > dummy.c -cc dummy.c +$LFS_TGT-gcc -B/tools/lib dummy.c readelf -l a.out | grep ': /tools' If everything is working correctly, there should be no errors, @@ -91,17 +62,7 @@ readelf -l a.out | grep ': /tools' If the output is not shown as above or there was no output at all, then something is wrong. Investigate and retrace the steps to find out where the problem is and correct it. This issue must be resolved before - continuing on. First, perform the sanity check again, using - gcc instead of cc. If this works, - then the /tools/bin/cc symlink is - missing. Revisit and install - the symlink. Next, ensure that the PATH is correct. This - can be checked by running echo $PATH and verifying that - /tools/bin is at the head of the - list. If the PATH is wrong it could mean that you are not - logged in as user lfs or that - something went wrong back in Another option is that something may have gone wrong with the + continuing on. Something may have gone wrong with the specs file amendment above. In this case, redo the specs file amendment, being careful to copy-and-paste the commands. @@ -111,9 +72,9 @@ readelf -l a.out | grep ': /tools' - Building Tcl in the next section will serve as an additional check that - the toolchain has been built properly. If Tcl fails to build, it is an - indication that something has gone wrong with the Binutils, GCC, or Glibc - installation, but not with Tcl itself. + Building Binutils in the next section will serve as an additional check that + the toolchain has been built properly. If Binutils fails to build, it is an + indication that something has gone wrong with the previous Binutils, GCC, or Glibc + installations. diff --git a/chapter05/binutils-pass1.xml b/chapter05/binutils-pass1.xml index 6644c2250..2c8a5ab73 100644 --- a/chapter05/binutils-pass1.xml +++ b/chapter05/binutils-pass1.xml @@ -41,7 +41,7 @@ - Installation of Binutils + Installation of Cross Binutils It is important that Binutils be the first package compiled because both Glibc and GCC perform various tests on the available @@ -70,19 +70,20 @@ cd ../binutils-build Now prepare Binutils for compilation: -CC="gcc -B/usr/bin/" ../binutils-&binutils-version;/configure \ - --prefix=/tools --disable-nls --disable-werror +../binutils-&binutils-version;/configure \ + --target=$LFS_TGT --prefix=/tools \ + --disable-nls --disable-werror The meaning of the configure options: - CC="gcc -B/usr/bin/" + --target=$LFS_TGT - This forces gcc to prefer the linker from - the host in /usr/bin. This - is necessary on some hosts where the new ld - built here is not compatible with the host's gcc. + Because the machine description in the LFS_TGT + variable is slightly different than the value returned by the + config.guess script, this switch will tell the configure script to + adjust Binutil's build system for building a cross linker. @@ -124,49 +125,17 @@ cd ../binutils-build tests at this point are minimal since the programs from this first pass will soon be replaced by those from the second. - Create a symlink to ensure the sanity of our toolchain: + If building on x86_64, create a symlink to ensure the sanity of + the toolchain: -mkdir -v /tools/lib -ln -sv lib /tools/lib64 +case $(uname -m) in + x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;; +esac Install the package: make install - Finally, prepare the linker for the Adjusting phase - later on: - -make -C ld clean -make -C ld LIB_PATH=/tools/lib -cp -v ld/ld-new /tools/bin - - - The meaning of the make parameters: - - - -C ld clean - - This tells the make program to remove all compiled - files in the ld - subdirectory. - - - - - -C ld LIB_PATH=/tools/lib - - This option rebuilds everything in the ld subdirectory. Specifying the - LIB_PATH Makefile variable on the command line - allows us to override the default value and point it to the - temporary tools location. The value of this variable specifies - the linker's default library search path. This preparation is - used later in the chapter. - - - - - diff --git a/chapter05/binutils-pass2.xml b/chapter05/binutils-pass2.xml index 7cfcb6421..dd7e7d912 100644 --- a/chapter05/binutils-pass2.xml +++ b/chapter05/binutils-pass2.xml @@ -41,7 +41,7 @@ - Re-installation of Binutils + Installation of Binutils Binutils does not recognize versions of Texinfo newer than 4.9. Fix this issue by applying the following patch: @@ -55,12 +55,23 @@ cd ../binutils-build Prepare Binutils for compilation: -../binutils-&binutils-version;/configure --prefix=/tools \ - --disable-nls --with-lib-path=/tools/lib +CC="$LFS_TGT-gcc -B/tools/lib/" \ + AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \ + ../binutils-&binutils-version;/configure --prefix=/tools \ + --disable-nls --with-lib-path=/tools/lib The meaning of the new configure options: + + CC="$LFS_TGT-gcc -B/tools/lib/" AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib + + Because this is really a native build of Binutils, setting these + variables ensures that the build system uses the cross-compiler and + associated tools instead of the ones on the host system. + + + --with-lib-path=/tools/lib @@ -78,13 +89,6 @@ cd ../binutils-build make - Compilation is now complete. As discussed earlier, running the - test suite is not mandatory for the temporary tools here in this - chapter. To run the Binutils test suite anyway, issue the following - command: - -make check - Install the package: make install @@ -96,6 +100,33 @@ cd ../binutils-build make -C ld LIB_PATH=/usr/lib:/lib cp -v ld/ld-new /tools/bin + + The meaning of the make parameters: + + + -C ld clean + + This tells the make program to remove all compiled + files in the ld + subdirectory. + + + + + -C ld LIB_PATH=/usr/lib:/lib + + This option rebuilds everything in the ld subdirectory. Specifying the + LIB_PATH Makefile variable on the command line + allows us to override the default value of the temporary tools + and point it to the proper final path. The value of this variable + specifies the linker's default library search path. This + preparation is used in the next chapter. + + + + + diff --git a/chapter05/chapter05.xml b/chapter05/chapter05.xml index 5d776d032..096717c36 100644 --- a/chapter05/chapter05.xml +++ b/chapter05/chapter05.xml @@ -19,13 +19,11 @@ + + - - - diff --git a/chapter05/gcc-pass1.xml b/chapter05/gcc-pass1.xml index d9c6175ff..02854618d 100644 --- a/chapter05/gcc-pass1.xml +++ b/chapter05/gcc-pass1.xml @@ -41,7 +41,7 @@ - Installation of GCC + Installation of Cross GCC GCC now requires the GMP and MPFR packages. As these packages may not be included in your host distribution, they will be built with @@ -60,35 +60,16 @@ cd ../gcc-build Prepare GCC for compilation: -CC="gcc -B/usr/bin/" ../gcc-&gcc-version;/configure --prefix=/tools \ - --with-local-prefix=/tools --disable-nls --disable-shared --disable-libssp \ - --disable-multilib --enable-languages=c +../gcc-&gcc-version;/configure \ + --target=$LFS_TGT --prefix=/tools \ + --disable-nls --disable-shared --disable-multilib \ + --disable-decimal-float --disable-threads \ + --disable-libmudflap --disable-libssp \ + --disable-libgomp --enable-languages=c The meaning of the configure options: - - CC="gcc -B/usr/bin/" - - This forces gcc to prefer the linker from - the host in /usr/bin. This - is necessary on some hosts where the new ld - built in the previous section is not compatible with the host's - gcc. - - - - - --with-local-prefix=/tools - - The purpose of this switch is to remove /usr/local/include from - gcc's include search path. This is not - absolutely essential, however, it helps to minimize the - influence of the host system. - - - --disable-shared @@ -99,37 +80,34 @@ cd ../gcc-build - --disable-libssp + --disable-decimal-float, --disable-threads, --disable-libmudflap, --disable-libssp, --disable-libgomp - This switch prevents a conflict with older versions of - glibc which can cause the build to fail. + These switches disable support for the decimal floating point extension, + threading, libmudflap, libssp and libgomp respectively. These features will fail + to compile when building a cross-compiler and are not necessary for the task of + cross-compiling the temporary libc. - --enable-languages=c + --disable-multilib - This option ensures that only the C compiler is built. - This is the only language needed now. + On x86_64, LFS does not yet support a multilib configuration. + This switch is harmless for x86. - --disable-multilib + --enable-languages=c - We currently only want to build support for 64-bit libraries. + This option ensures that only the C compiler is built. + This is the only language needed now. - The following command will compile GCC not once, but several times. It - uses the programs compiled in a first round to compile itself a second time, - and then again a third time. It then compares these second and third compiles - to make sure it can reproduce itself flawlessly. This is called - bootstrapping. Building GCC in this way ensures that it was - compiled correctly and is now the default configuration for the released - package. Continue with compiling by running: + Compile GCC by running: make @@ -146,23 +124,14 @@ cd ../gcc-build Using --disable-shared means that the libgcc_eh.a file isn't created and installed. The Glibc package depends on this library as it uses - -lgcc_eh within its build system. We can satisfy - that dependency by creating a symlink to libgcc.a, + -lgcc_eh within its build system. This dependency + can be satisfied by creating a symlink to libgcc.a, since that file will end up containing the objects normally contained in libgcc_eh.a. -ln -vs libgcc.a `gcc -print-libgcc-file-name | \ +ln -vs libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | \ sed 's/libgcc/&_eh/'` - As a finishing touch, create a symlink. Many programs and scripts - run cc instead of gcc, which is - used to keep programs generic and therefore usable on all kinds of UNIX - systems where the GNU C compiler is not always installed. Running - cc leaves the system administrator free to decide - which C compiler to install: - -ln -vs gcc /tools/bin/cc - diff --git a/chapter05/gcc-pass2.xml b/chapter05/gcc-pass2.xml index bbdda355f..75bca7092 100644 --- a/chapter05/gcc-pass2.xml +++ b/chapter05/gcc-pass2.xml @@ -41,33 +41,19 @@ - Re-installation of GCC + Installation of GCC - The tools required to test GCC and Binutils—Tcl, Expect - and DejaGNU—are installed now. GCC and Binutils can now be - rebuilt, linking them against the new Glibc and testing them properly - (if running the test suites in this chapter). Please note that these - test suites are highly dependent on properly functioning PTYs which - are provided by the host. PTYs are most commonly implemented via the - devpts file system. Check - to see if the host system is set up correctly in this regard by - performing a quick test: + Versions of GCC later than 4.3 will treat this build as if + it were a relocated compiler and disallow searching for startfiles in + the location specified by --prefix. Since this + will not be a relocated compiler, and the startfiles in + /tools are crucial to building + a working compiler linked to the libs in /tools, + apply the following patch which partially reverts GCC to its old behavior: -expect -c "spawn ls" +patch -Np1 -i ../&gcc-startfiles-patch; - The response might be: - -The system has no more ptys. -Ask your system administrator to create more. - - If the above message is received, the host does not have its PTYs - set up properly. In this case, there is no point in running the test - suites for GCC and Binutils until this issue is resolved. Please consult - the LFS FAQ at for more - information on how to get PTYs working. - - As previously explained in , - under normal circumstances the GCC fixincludes script + Under normal circumstances the GCC fixincludes script is run in order to fix potentially broken header files. As GCC-&gcc-version; and Glibc-&glibc-version; have already been installed at this point, and their respective header files are known to not require fixing, the @@ -80,18 +66,17 @@ Ask your system administrator to create more. cp -v gcc/Makefile.in{,.orig} sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in - The bootstrap build performed in - built GCC with the compiler flag. - Non-bootstrap builds omit this flag by default, so apply the following - sed to use it in order to ensure consistent compiler - builds: + Non-bootstrap builds omit the + build flag by default, and the goal should be to produce a compiler that is + exactly the same as if it were bootstrapped. Apply the following + sed command to force the build to use the flag: cp -v gcc/Makefile.in{,.tmp} sed 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \ > gcc/Makefile.in The following command will change the location of GCC's default - dynamic linker to use the one we installed in + dynamic linker to use the one installed in /tools. It also removes /usr/include from GCC's include search path. Doing this now rather than adjusting the specs file after installation @@ -105,9 +90,11 @@ do cp -uv $file{,.orig} sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \ -e 's@/usr@/tools@g' $file.orig > $file - echo " + echo ' #undef STANDARD_INCLUDE_DIR -#define STANDARD_INCLUDE_DIR 0" >> $file +#define STANDARD_INCLUDE_DIR 0 +#define STANDARD_STARTFILE_PREFIX_1 "" +#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file touch $file.orig done @@ -120,19 +107,24 @@ done /tools to every instance of /lib/ld, /lib64/ld or /lib32/ld, while the second one replaces hard-coded instances of /usr. Then we add our define - statements which alter the include search path to the end of the file. Finally, - we use touch to update the timestamp on the copied files. + statements which alter the include search path and the default startfile prefix + to the end of the file. + Finally, we use touch to update the timestamp on the copied files. When used in conjunction with cp -u, this prevents unexpected changes to the original files in case the command is inadvertently run twice. - Unsetting the multlib spec for GCC ensures that it + On x86_64, unsetting the multlib spec for GCC ensures that it won't attempt to link against libraries on the host: -for file in $(find gcc/config -name t-linux64) ; do \ - cp -v $file{,.orig} - sed '/MULTILIB_OSDIRNAMES/d' $file.orig > $file -done +case $(uname -m) in + x86_64) + for file in $(find gcc/config -name t-linux64) ; do \ + cp -v $file{,.orig} + sed '/MULTILIB_OSDIRNAMES/d' $file.orig > $file + done + ;; +esac As in the first build of GCC it requires the GMP and MPFR packages. Unpack the tarballs and move them into the required directory names: @@ -152,7 +144,9 @@ cd ../gcc-build Now prepare GCC for compilation: -../gcc-&gcc-version;/configure --prefix=/tools \ +CC="$LFS_TGT-gcc -B/tools/lib/" \ + AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \ + ../gcc-&gcc-version;/configure --prefix=/tools \ --with-local-prefix=/tools --enable-clocale=gnu \ --enable-shared --enable-threads=posix \ --enable-__cxa_atexit --enable-languages=c,c++ \ @@ -227,27 +221,58 @@ cd ../gcc-build make - Compilation is now complete. As previously mentioned, running the test - suites for the temporary tools compiled in this chapter is not mandatory. - To run the GCC test suite anyway, use the following command: - -make -k check - - The -k flag is used to make the test suite run - through to completion and not stop at the first failure. The GCC test - suite is very comprehensive and is almost guaranteed to generate a few - failures. - - For a discussion of test failures that are of particular - importance, please see - Install the package: make install - + As a finishing touch, create a symlink. Many programs and scripts + run cc instead of gcc, which is + used to keep programs generic and therefore usable on all kinds of UNIX + systems where the GNU C compiler is not always installed. Running + cc leaves the system administrator free to decide + which C compiler to install: + +ln -vs gcc /tools/bin/cc + + + At this point, it is imperative to stop and ensure that the basic + functions (compiling and linking) of the new toolchain are working as + expected. To perform a sanity check, run the following commands: + +echo 'main(){}' > dummy.c +cc dummy.c +readelf -l a.out | grep ': /tools' + + If everything is working correctly, there should be no errors, + and the output of the last command will be of the form: + +[Requesting program interpreter: + /tools/lib/ld-linux.so.2] + + Note that /tools/lib, or + /tools/lib64 for 64-bit machines + appears as the prefix of the dynamic linker. + + If the output is not shown as above or there was no output at all, + then something is wrong. Investigate and retrace the steps to find out + where the problem is and correct it. This issue must be resolved before + continuing on. First, perform the sanity check again, using + gcc instead of cc. If this works, + then the /tools/bin/cc symlink is + missing. Install the symlink as per above. + Next, ensure that the PATH is correct. This + can be checked by running echo $PATH and verifying that + /tools/bin is at the head of the + list. If the PATH is wrong it could mean that you are not + logged in as user lfs or that + something went wrong back in + + Once all is well, clean up the test files: + +rm -v dummy.c a.out + + diff --git a/chapter05/glibc.xml b/chapter05/glibc.xml index 3252c5a10..f8063f204 100644 --- a/chapter05/glibc.xml +++ b/chapter05/glibc.xml @@ -43,11 +43,6 @@ Installation of Glibc - Fix a potential issue if /etc/ld.so.preload is - used on the host system. - -sed -i 's@/etc/ld.so.preload@/tools/etc/ld.so.preload@' elf/rtld.c - The Glibc documentation recommends building Glibc outside of the source directory in a dedicated build directory: @@ -71,14 +66,23 @@ esac Next, prepare Glibc for compilation: ../glibc-&glibc-version;/configure --prefix=/tools \ + --host=$LFS_TGT --build=$(../glibc-&glibc-version;/scripts/config.guess) \ --disable-profile --enable-add-ons \ - --enable-kernel=2.6.0 --with-binutils=/tools/bin \ - --without-gd --with-headers=/tools/include \ - --without-selinux + --enable-kernel=2.6.0 --with-headers=/tools/include \ + libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes The meaning of the configure options: + + --host=$LFS_TGT, --build=$(../glibc-&glibc-version;/scripts/config.guess) + + The combined effect of these switches is that Glibc's build system + configures itself to cross-compile, using the cross-linker and + cross-compiler in /tools. + + + --disable-profile @@ -103,24 +107,6 @@ esac - - --with-binutils=/tools/bin - - While not required, this switch ensures that there are - no errors pertaining to which Binutils programs get used during the - Glibc build. - - - - - --without-gd - - This prevents the build of the memusagestat - program, which insists on linking against the host's libraries - (libgd, libpng, libz, etc.). - - - --with-headers=/tools/include @@ -131,12 +117,19 @@ esac - --without-selinux + libc_cv_forced_unwind=yes - When building from hosts that include SELinux functionality - (e.g., Fedora Core 3), Glibc will build with support for SELinux. - As the LFS tools environment does not contain support for SELinux, a - Glibc compiled with such support will fail to operate correctly. + The build requires support for forced unwind, but because it is + being cross compiled, it cannot auto detect it. Setting this variable + on the command line explicitly tells the configure script that support + is available. + + + + libc_cv_c_cleanup=yes + + The build also requires support for C cleanup handling, which it + cannot auto detect when being cross compiled. Enable it explicitly. @@ -167,13 +160,6 @@ esac This package does come with a test suite, however, it cannot be run at this time because we do not have a C++ compiler yet. - The install stage of Glibc will issue a harmless warning at the - end about the absence of /tools/etc/ld.so.conf. - Prevent this warning with: - -mkdir -v /tools/etc -touch /tools/etc/ld.so.conf - Install the package: make install diff --git a/chapter05/toolchaintechnotes.xml b/chapter05/toolchaintechnotes.xml index f6adefb61..60e1f10ff 100644 --- a/chapter05/toolchaintechnotes.xml +++ b/chapter05/toolchaintechnotes.xml @@ -14,7 +14,7 @@ behind the overall build method. It is not essential to immediately understand everything in this section. Most of this information will be clearer after performing an actual build. This section can be referred - back to at any time during the process. + to at any time during the process. The overall goal of is to provide a temporary environment that can be chrooted into and from which can be @@ -54,13 +54,17 @@ - The process is similar in principle to cross-compiling, whereby - tools installed in the same prefix work in cooperation, and thus utilize - a little GNU magic + Slightly adjusting the name of the working platform ensures that + the first build of Binutils and GCC produces a compatible cross-linker + and cross-compiler. Instead of producing binaries for another architecture, + the cross-linker and cross-compiler will produce binaries compatible with + the current hardware. - Careful manipulation of the standard linker's library search path - ensures programs are linked only against chosen libraries + The temporary libraries are cross-compiled. This removes all + dependency on the host system, lessens the chance of headers or libraries + from the host corrupting the new tools and allows for the possibility of + building both 32-bit and 64-bit libraries on 64-bit capable hardware. Careful manipulation of gcc's -- cgit v1.2.3-54-g00ecf