diff --git a/chapter01/changelog.xml b/chapter01/changelog.xml
index c521419a5..e9f8d40aa 100644
--- a/chapter01/changelog.xml
+++ b/chapter01/changelog.xml
@@ -36,6 +36,38 @@
-->
+
+
+ 2012-04-25
+
+
+ [bdubbs] - Incorporate changes developed and tested in the jh branch.
+
+
+
+ [jhuntwork] - Update chapter 5 toolchain technical notes to match changes
+ in build method.
+
+
+ [jhuntwork] - Use --with-native-system-header-dir
+ switch in chapter 5 gcc. This replaces seds that were used previously
+ to alter the CROSS_SYSTEM_HEADER_DIR and NATIVE_SYSTEM_HEADER_DIR
+ values to keep the toolchain searching for headers only in
+ /tools/include and not /usr/include. Thanks to Pierre Labastie. Fixes
+ #3066.
+
+
+ [jhuntwork] - Remove --without-cloog and --without-ppl from chapter 5 gcc.
+ These are unnecessary since it doesn't matter if pass 1 gcc is linked against
+ host libs and it should be impossible for the build of pass 2 gcc to find host
+ headers or libs.
+
+
+ [jhuntwork] - Adjust build method to use sysroot.
+
+
+
+
2012-04-24
diff --git a/chapter01/whatsnew.xml b/chapter01/whatsnew.xml
index 41f46e94f..b02858588 100644
--- a/chapter01/whatsnew.xml
+++ b/chapter01/whatsnew.xml
@@ -231,10 +231,6 @@
&coreutils-i18n-patch;
-
- &gcc-startfiles-patch;
-
-
&glibc-gcc_fix-patch;
diff --git a/chapter03/patches.xml b/chapter03/patches.xml
index 21ec95b9a..fc11228a8 100644
--- a/chapter03/patches.xml
+++ b/chapter03/patches.xml
@@ -58,14 +58,6 @@
-
- GCC Startfiles Fix Patch - &gcc-startfiles-patch-size;:
-
- Download:
- MD5 sum: &gcc-startfiles-patch-md5;
-
-
-
Glibc GCC Fix Patch - &glibc-gcc_fix-patch-size;:
diff --git a/chapter05/binutils-pass1.xml b/chapter05/binutils-pass1.xml
index 610486fa5..b6de18b96 100644
--- a/chapter05/binutils-pass1.xml
+++ b/chapter05/binutils-pass1.xml
@@ -76,14 +76,43 @@ cd ../binutils-build
Now prepare Binutils for compilation:
-../binutils-&binutils-version;/configure --target=$LFS_TGT \
- --prefix=/tools \
- --disable-nls \
- --disable-werror
+
+../binutils-&binutils-version;/configure \
+ --prefix=/tools \
+ --with-sysroot=$LFS \
+ --with-lib-path=/tools/lib \
+ --target=$LFS_TGT \
+ --disable-nls \
+ --disable-werror
The meaning of the configure options:
+
+ --prefix=/tools
+
+ This tells the configure script to prepare to install the
+ Binutils programs in the /tools
+ directory.
+
+
+
+
+ --with-sysroot=$LFS
+
+ For cross compilation, this tells the build system to look in
+ $LFS for the target system libraries as needed.
+
+
+
+
+ --with-lib-path=/tools/lib
+
+ This specifies which library path the linker should be
+ configured to use.
+
+
+
--target=$LFS_TGT
@@ -95,15 +124,6 @@ cd ../binutils-build
-
- --prefix=/tools
-
- This tells the configure script to prepare to install the
- Binutils programs in the /tools
- directory.
-
-
-
--disable-nls
@@ -111,7 +131,7 @@ cd ../binutils-build
temporary tools.
-
+
--disable-werror
diff --git a/chapter05/binutils-pass2.xml b/chapter05/binutils-pass2.xml
index 0a3d2df52..cb96b62f0 100644
--- a/chapter05/binutils-pass2.xml
+++ b/chapter05/binutils-pass2.xml
@@ -54,19 +54,20 @@ cd ../binutils-build
Prepare Binutils for compilation:
-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
+
+CC=$LFS_TGT-gcc \
+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
+ CC="$LFS_TGT-gcc" 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
diff --git a/chapter05/chapter05.xml b/chapter05/chapter05.xml
index 2d957c81b..d6a977d48 100644
--- a/chapter05/chapter05.xml
+++ b/chapter05/chapter05.xml
@@ -18,7 +18,6 @@
-
diff --git a/chapter05/gcc-pass1.xml b/chapter05/gcc-pass1.xml
index 532bbae36..12d6d48b4 100644
--- a/chapter05/gcc-pass1.xml
+++ b/chapter05/gcc-pass1.xml
@@ -62,6 +62,43 @@ mv -v gmp-&gmp-version; gmp
tar -zxf ../mpc-&mpc-version;.tar.gz
mv -v mpc-&mpc-version; mpc
+ The following command will change the location of GCC's default
+ dynamic linker to use the one installed in /tools. It also removes /usr/include from GCC's include search path.
+ Issue:
+
+for file in \
+ $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
+do
+ cp -uv $file{,.orig}
+ sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
+ -e 's@/usr@/tools@g' $file.orig > $file
+ echo '
+#undef STANDARD_STARTFILE_PREFIX_1
+#undef STANDARD_STARTFILE_PREFIX_2
+#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
+#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
+ touch $file.orig
+done
+
+ In case the above seems hard to follow, let's break it down a bit.
+ First we find all the files under the gcc/config directory that are named either
+ linux.h, linux64.h or
+ sysv4.h. For each file found, we copy it to a file of
+ the same name but with an added suffix of .orig
. Then the
+ first sed expression prepends /tools
to every instance of
+ /lib/ld
, /lib64/ld
or
+ /lib32/ld
, while the second one replaces hard-coded
+ instances of /usr
. Next, we add our define statements which
+ alter the default startfile prefix to the end of the file. Note that the
+ trailing /
in /tools/lib/
is required.
+ 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 commands are
+ inadvertently run twice.
+
The GCC documentation recommends building GCC outside of the
source directory in a dedicated build directory:
@@ -73,6 +110,11 @@ cd ../gcc-build
../gcc-&gcc-version;/configure \
--target=$LFS_TGT \
--prefix=/tools \
+ --with-sysroot=$LFS \
+ --with-newlib \
+ --without-headers \
+ --with-local-prefix=/tools \
+ --with-native-system-header-dir=/tools/include \
--disable-nls \
--disable-shared \
--disable-multilib \
@@ -83,14 +125,53 @@ cd ../gcc-build
--disable-libgomp \
--disable-libquadmath \
--enable-languages=c \
- --without-ppl \
- --without-cloog \
--with-mpfr-include=$(pwd)/../gcc-&gcc-version;/mpfr/src \
--with-mpfr-lib=$(pwd)/mpfr/src/.libs
The meaning of the configure options:
+
+ --with-newlib
+
+ Since a working C library is not yet available, this ensures
+ that the inhibit_libc constant is defined when building libgcc. This prevents
+ the compiling of any code that requires libc support.
+
+
+
+
+ --without-headers
+
+ When creating a complete cross-compiler, GCC requires
+ standard headers compatible with the target system. For our
+ purposes these headers will not be needed. This switch prevents
+ GCC from looking for them.
+
+
+
+
+ --with-local-prefix=/tools
+
+ The local prefix is the location in the system that GCC will search
+ for locally installed include files. The default is /usr/local.
+ Setting this to /tools helps keep the host location of
+ /usr/local out of this GCC's search path.
+
+
+
+
+ --with-native-system-header-dir=/tools/include
+
+ By default GCC searches /usr/include for system
+ headers. In conjunction with the sysroot switch, this would translate normally
+ to $LFS/usr/include. However the headers that will be installed
+ in the next two sections will go to $LFS/tools/include. This
+ switch ensures that gcc will find them correctly. In the second pass of GCC, this
+ same switch will ensure that no headers from the host system are found.
+
+
+
--disable-shared
@@ -127,15 +208,6 @@ cd ../gcc-build
-
- --without-ppl, --without-cloog
-
- These switches prevent GCC from building against the PPL and
- CLooG libraries which may be present on the host system, but will not
- be available in the chroot environment.
-
-
-
Compile GCC by running:
diff --git a/chapter05/gcc-pass2.xml b/chapter05/gcc-pass2.xml
index e2f3cd09c..0ed5c11aa 100644
--- a/chapter05/gcc-pass2.xml
+++ b/chapter05/gcc-pass2.xml
@@ -43,15 +43,20 @@
Installation of GCC
- 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:
+ Our first build of GCC has installed a couple of internal system
+ headers. Normally one of them, limits.h will in turn
+ include the corresponding system limits.h header, in
+ this case, /tools/include/limits.h. However, at the
+ time of the first build of gcc /tools/include/limits.h
+ did not exist, so the internal header that GCC installed is a partial,
+ self-contained file and does not include the extended features of the
+ system header. This was adequate for building the temporary libc, but this
+ build of GCC now requires the full internal header. Create a full version
+ of the internal header using a command that is identical to what the GCC
+ build system does in normal circumstances:
-patch -Np1 -i ../&gcc-startfiles-patch;
+cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
+ `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
Under normal circumstances the GCC fixincludes script
is run in order to fix potentially broken header files. As GCC-&gcc-version;
@@ -76,14 +81,9 @@ sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
- The following command will change the location of GCC's default
- 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
- ensures that the new dynamic linker is used during the actual build of
- GCC. That is, all of the binaries created during the build will link
- against the new Glibc. Issue:
+ Once again, change the location of GCC's default dynamic linker to
+ use the one installed in /tools.
for file in \
$(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
@@ -94,40 +94,11 @@ do
echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
-#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib"
+#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
touch $file.orig
done
- In case the above seems hard to follow, let's break it down a bit.
- First we find all the files under the
- gcc/config directory that are named
- either linux.h, linux64.h or
- sysv4.h.
- For each file found, we copy it to a file of the same name but with an added
- suffix of .orig
. Then the first sed expression prepends
- /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 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 commands are inadvertently run twice.
-
-
- On x86_64, unsetting the multilib spec for GCC ensures that it
- won't attempt to link against libraries on the host:
-
-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, MPFR and MPC
packages. Unpack the tarballs and move them into the required directory
names:
@@ -149,12 +120,13 @@ cd ../gcc-build
Now prepare GCC for compilation:
-CC="$LFS_TGT-gcc -B/tools/lib/" \
+CC="$LFS_TGT-gcc" \
AR=$LFS_TGT-ar \
RANLIB=$LFS_TGT-ranlib \
../gcc-&gcc-version;/configure \
--prefix=/tools \
--with-local-prefix=/tools \
+ --with-native-system-header-dir=/tools/include \
--enable-clocale=gnu \
--enable-shared \
--enable-threads=posix \
@@ -164,8 +136,6 @@ RANLIB=$LFS_TGT-ranlib \
--disable-multilib \
--disable-bootstrap \
--disable-libgomp \
- --without-ppl \
- --without-cloog \
--with-mpfr-include=$(pwd)/../gcc-&gcc-version;/mpfr/src \
--with-mpfr-lib=$(pwd)/mpfr/src/.libs
diff --git a/chapter05/glibc.xml b/chapter05/glibc.xml
index 262a85a9f..17caba3d7 100644
--- a/chapter05/glibc.xml
+++ b/chapter05/glibc.xml
@@ -202,6 +202,42 @@ esac
make install
+
+ 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
+$LFS_TGT-gcc 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. 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.
+
+ Once all is well, clean up the test files:
+
+rm -v dummy.c a.out
+
+
+
+ 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/toolchaintechnotes.xml b/chapter05/toolchaintechnotes.xml
index 2932b957f..398f3d104 100644
--- a/chapter05/toolchaintechnotes.xml
+++ b/chapter05/toolchaintechnotes.xml
@@ -71,9 +71,8 @@
capable hardware.
- Careful manipulation of gcc's
- specs file tells the compiler which target dynamic
- linker will be used
+ Careful manipulation of the GCC source tells the compiler which target
+ dynamic linker will be used.
@@ -118,6 +117,10 @@ checking what linker to use... /tools/i686-lfs-linux-gnu/bin/ld
detailed information about the preprocessor, compilation, and assembly stages,
including gcc's included search paths and their order.
+ Next installed are sanitized Linux API headers. These allow the standard
+ C library (Glibc) to interface with features that the Linux kernel will
+ provide.
+
The next package installed is Glibc. The most important considerations
for building Glibc are the compiler, binary tools, and kernel headers. The
compiler is generally not an issue since Glibc will always use the compiler
@@ -136,31 +139,19 @@ checking what linker to use... /tools/i686-lfs-linux-gnu/bin/ld
package—it is very self-sufficient in terms of its build machinery and
generally does not rely on toolchain defaults.
- After the Glibc installation, change gcc's specs file
- to point to the new dynamic linker in /tools/lib. This last step is vital in ensuring
- that searching and linking take place only within the /tools prefix. A hard-wired
- path to a dynamic linker is embedded into every Executable and Link Format
- (ELF)-shared executable. This can be inspected by running:
- readelf -l <name of binary> | grep interpreter.
- Amending gcc's specs file ensures that every program
- compiled from here through the end of this chapter will use the new dynamic
- linker in /tools/lib.
-
- For the second pass of GCC, its sources also need to be modified
- to tell GCC to use the new dynamic linker. Failure to do
- so will result in the GCC programs themselves having the name of the
- dynamic linker from the host system's /lib directory embedded into them, which
- would defeat the goal of getting away from the host.
-
During the second pass of Binutils, we are able to utilize the
--with-lib-path configure switch to control
- ld's library search path. From this point onwards,
- the core toolchain is self-contained and self-hosted. The remainder of
- the packages all build against
- the new Glibc in /tools.
+ ld's library search path.
+
+ For the second pass of GCC, its sources also need to be modified to
+ tell GCC to use the new dynamic linker. Failure to do so will result in the
+ GCC programs themselves having the name of the dynamic linker from the host
+ system's /lib directory embedded into
+ them, which would defeat the goal of getting away from the host. From this
+ point onwards, the core toolchain is self-contained and self-hosted. The
+ remainder of the packages all build
+ against the new Glibc in /tools.
Upon entering the chroot environment in , the first major package to be
@@ -170,52 +161,4 @@ checking what linker to use... /tools/i686-lfs-linux-gnu/bin/ld
toolchain defaults, and then proceed in building the rest of the target
LFS system.
-
-
diff --git a/chapter06/readjusting.xml b/chapter06/adjusting.xml
similarity index 100%
rename from chapter06/readjusting.xml
rename to chapter06/adjusting.xml
diff --git a/chapter06/chapter06.xml b/chapter06/chapter06.xml
index 0ea2347f4..71a37a182 100644
--- a/chapter06/chapter06.xml
+++ b/chapter06/chapter06.xml
@@ -20,7 +20,7 @@
-
+
diff --git a/chapter06/gcc.xml b/chapter06/gcc.xml
index c18eb1404..1bec4066d 100644
--- a/chapter06/gcc.xml
+++ b/chapter06/gcc.xml
@@ -156,27 +156,27 @@ cd ../gcc-build
the same sanity checks as we did earlier in the chapter:
/usr/lib/gcc/i686-pc-linux-gnu/&gcc-version;/../../../crt1.o succeeded
@@ -193,13 +193,13 @@ cd ../gcc-build
/usr/lib directory.
grep -B4 '^ /usr/include' dummy.log
#include <...> search starts here:
@@ -217,15 +217,15 @@ cd ../gcc-build
directory is required to be in place.
SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
@@ -246,47 +246,47 @@ SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");
Finally, move a misplaced file:
diff --git a/general.ent b/general.ent
index 090d2e866..119ed6a53 100644
--- a/general.ent
+++ b/general.ent
@@ -1,5 +1,5 @@
-
-
+
+
diff --git a/packages.ent b/packages.ent
index 6d4d8f0ea..e5aa25e22 100644
--- a/packages.ent
+++ b/packages.ent
@@ -373,9 +373,9 @@
-
+
-
+