1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
3 <!ENTITY % general-entities SYSTEM "../general.ent">
6 <sect1 id="ch-system-readjusting">
7 <title>Re-adjusting the toolchain</title>
8 <?dbhtml filename="readjusting.html"?>
10 <para>Now that the new and final C libraries have been installed, it's time to
11 adjust our toolchain again. We'll adjust it so that it will link any newly
12 compiled program against these new libraries. This is in fact the same thing we
13 did in the <quote>Adjusting</quote> phase in the beginning of the previous
14 chapter, even though it looks like the reverse: then we guided the chain from
15 the host's <filename class="directory">/{,usr/}lib</filename> to the new
16 <filename class="directory">/tools/lib</filename>, now we guide it from that
17 same <filename class="directory">/tools/lib</filename> to the LFS's <filename
18 class="directory">/{,usr/}lib</filename>.</para>
20 <para>First we adjust the linker. For this we retained the
21 source and build directories from the second pass over Binutils. Install the
22 adjusted linker by running the following from within the
23 <filename class="directory">binutils-build</filename> directory:</para>
25 <screen><userinput>make -C ld INSTALL=/tools/bin/install install</userinput></screen>
27 <note><para>If you somehow missed the earlier warning to retain the Binutils
28 source and build directories from the second pass in
29 <xref linkend="chapter-temporary-tools"/>, or otherwise accidentally deleted them or just
30 don't have access to them, don't worry, all is not lost. Just ignore the above
31 command. The result will be that the next package, Binutils, will link against
32 the C libraries in <filename class="directory">/tools</filename> rather
33 than in <filename class="directory">/{,usr/}lib</filename>. This is not ideal,
34 however, our testing has shown that the resulting Binutils program binaries
35 should be identical.</para></note>
37 <para>From now on every compiled program will link <emphasis>only</emphasis>
38 against the libraries in <filename>/usr/lib</filename> and
39 <filename>/lib</filename>. The extra
40 <emphasis>INSTALL=/tools/bin/install</emphasis> is needed because the Makefile
41 created during the second pass still contains the reference to
42 <filename>/usr/bin/install</filename>, which we obviously haven't installed yet.
43 Some host distributions contain a <filename class="symlink">ginstall</filename>
44 symbolic link which takes precedence in the Makefile and thus can cause a
45 problem here. The above command takes care of this also.</para>
47 <para>You can now remove the Binutils source and build directories.</para>
49 <para>The next thing to do is to amend our GCC specs file so that it points
50 to the new dynamic linker. Just like earlier on, we use a sed to accomplish
53 <!-- Ampersands are needed to allow cut and paste -->
55 <screen><userinput>SPECFILE=/tools/lib/gcc-lib/*/*/specs &&
56 sed -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g' \
57 $SPECFILE > newspecfile &&
58 mv -f newspecfile $SPECFILE &&
59 unset SPECFILE</userinput></screen>
61 <para>Again, cutting and pasting the above is recommended. And just like
62 before, it is a good idea to visually inspect the specs file to verify the
63 intended change was actually made.</para>
65 <important><para>If you are working on a platform where the name of the dynamic
66 linker is something other than <filename>ld-linux.so.2</filename>, you
67 <emphasis>must</emphasis> substitute <filename>ld-linux.so.2</filename> with the
68 name of your platform's dynamic linker in the above commands. Refer back to
69 <xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
72 <caution><para>It is imperative at this point to stop and ensure that the
73 basic functions (compiling and linking) of the adjusted toolchain are working
74 as expected. For this we are going to perform a simple sanity check:</para>
76 <screen><userinput>echo 'main(){}' > dummy.c
78 readelf -l a.out | grep ': /lib'</userinput></screen>
80 <para>If everything is working correctly, there should be no errors, and the
81 output of the last command will be (allowing for platform specific differences
82 in dynamic linker name):</para>
84 <blockquote><screen>[Requesting program interpreter: /lib/ld-linux.so.2]</screen></blockquote>
86 <para>Note especially that <filename class="directory">/lib</filename> is now
87 the prefix of our dynamic linker.</para>
89 <para> If you did not receive the output
90 as shown above, or received no output at all, then something is seriously wrong.
91 You will need to investigate and retrace your steps to find out where the
92 problem is and correct it. There is no point in continuing until this is done.
93 Most likely something went wrong with the specs file amendment above.</para>
95 <para>Once you are satisfied that all is well, clean up the test files:</para>
97 <screen><userinput>rm dummy.c a.out</userinput></screen>