From 2914987be2f15790bf042ec4f1e39361e6937dc8 Mon Sep 17 00:00:00 2001 From: Jeremy Huntwork Date: Thu, 26 Jan 2006 14:45:36 +0000 Subject: Adjust chapter 5 binutils to build a static ld-new for use in the chapter 6 readjusting section. Also add some extended sanity checks. These fixes are adapted from DIY-Linux and Greg Schafer. Thanks to Dan Nicholson for the report, as well. git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@7308 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689 --- chapter01/changelog.xml | 6 +++++ chapter05/binutils-pass2.xml | 9 +++++++- chapter06/readjusting.xml | 55 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/chapter01/changelog.xml b/chapter01/changelog.xml index e3343ee98..1b52bd3e5 100644 --- a/chapter01/changelog.xml +++ b/chapter01/changelog.xml @@ -43,6 +43,12 @@ [jhuntwork] - Modify chapter 6 Glibc's make install command to allow test-installation.pl to run. + + [jhuntwork] - Adjust chapter 5 binutils to build a static ld-new + for use in the chapter 6 readjusting section. Also add some extended + sanity checks. These fixes are adapted from DIY-Linux and Greg Schafer. + Thanks to Dan Nicholson for the report, as well. + diff --git a/chapter05/binutils-pass2.xml b/chapter05/binutils-pass2.xml index d1bbec87f..ebc0f30e7 100644 --- a/chapter05/binutils-pass2.xml +++ b/chapter05/binutils-pass2.xml @@ -49,7 +49,7 @@ cd ../binutils-build Prepare Binutils for compilation: ../binutils-&binutils-version;/configure --prefix=/tools \ - --disable-nls --enable-shared --with-lib-path=/tools/lib + --disable-nls --with-lib-path=/tools/lib The meaning of the new configure options: @@ -80,6 +80,13 @@ cd ../binutils-build Install the package: + Now prepare the linker for the Re-adjusting phase in + the next chapter: + +make -C ld clean +make -C ld LDFLAGS="-s" LIB_PATH=/usr/lib:/lib +cp -v ld/ld-new /tools/bin + make install diff --git a/chapter06/readjusting.xml b/chapter06/readjusting.xml index 4c2a82f75..ef46f1a3d 100644 --- a/chapter06/readjusting.xml +++ b/chapter06/readjusting.xml @@ -19,12 +19,17 @@ be guided from that same /tools/lib directory to the LFS /{,usr/}lib directories. -First, amend the GCC specs file so that it points to the new +First, create a symlink to the adjusted linker we created in chapter 5. + +ln -sv /tools/bin/ld-new /usr/bin/ld + +Next, amend the GCC specs file so that it points to the new dynamic linker. A sed command accomplishes this: SPECFILE=`dirname $(gcc -print-libgcc-file-name)`/specs && gcc -dumpspecs > $SPECFILE && -sed -i 's@^/tools/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' $SPECFILE && +sed -i -e '/^\*link:$/{n;s,$, -L/usr/lib,}' \ + -e 's@^/tools/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' $SPECFILE && unset SPECFILE It is a good idea to visually inspect the specs file to verify the intended @@ -38,20 +43,16 @@ dynamic linker in the above commands. Refer back to if necessary. -Now create temporary wrapper scripts for gcc and -ld. These scripts will point to their real counterparts +Now create a temporary wrapper script for gcc. +This script will point to the real gcc in /tools but with adjusted parameters to ensure that GCC in the next section links to our newly installed Glibc. cat > /usr/bin/gcc << "EOF" #!/bin/bash -/tools/bin/gcc -B/usr/lib $@ -EOF -cat > /usr/bin/ld << "EOF" -#!/bin/bash -/tools/bin/ld -nostdlib -L/usr/lib -L/lib $@ +/tools/bin/gcc -B/usr/lib/ -B/usr/bin/ $@ EOF -chmod 755 /usr/bin/{ld,gcc} +chmod 755 /usr/bin/gcc ln -s gcc /usr/bin/cc It is imperative at this point to stop and ensure that @@ -60,7 +61,7 @@ are working as expected. To do this, perform a sanity check: echo 'main(){}' > dummy.c -cc dummy.c +cc dummy.c -Wl,--verbose &> dummy.log readelf -l a.out | grep ': /lib' If everything is working correctly, there should be no errors, @@ -72,6 +73,36 @@ platform-specific differences in dynamic linker name): Note that /lib is now the prefix of our dynamic linker. +Now make sure that we're setup to use the correct start files: + +grep "/usr/lib/crt.* " dummy.log + +If everything is working correctly, there should be no errors, +and the output of the last command will be: + +attempt to open /usr/lib/crt1.o succeeded +attempt to open /usr/lib/crti.o succeeded +attempt to open /usr/lib/crtn.o succeeded + +Next make sure that we're using the correct libc: + +grep "/lib/libc.so.6 " dummy.log + +If everything is working correctly, there should be no errors, +and the output of the last command will be: + +attempt to open /lib/libc.so.6 succeeded + +Lastly, make sure GCC is using the correct dynamic linker: + +grep found dummy.log + +If everything is working correctly, there should be no errors, +and the output of the last command will be (allowing for +platform-specific differences in dynamic linker name): + +found ld-linux.so.2 at /lib/ld-linux.so.2 + If the output does not appear as shown above or is not received at all, then something is seriously wrong. Investigate and retrace the steps to find out where the problem is and correct it. The most likely @@ -82,7 +113,7 @@ the process. Once everything is working correctly, clean up the test files: -rm -v dummy.c a.out +rm -v dummy.c a.out dummy.log -- cgit v1.2.3-54-g00ecf