[673b0d8] | 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">
|
---|
| 4 | %general-entities;
|
---|
| 5 | ]>
|
---|
| 6 | <sect1 id="ch-system-readjusting">
|
---|
| 7 | <title>Re-adjusting the toolchain</title>
|
---|
| 8 | <?dbhtml filename="readjusting.html"?>
|
---|
| 9 |
|
---|
| 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>
|
---|
| 19 |
|
---|
| 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>
|
---|
| 24 |
|
---|
| 25 | <screen><userinput>make -C ld INSTALL=/tools/bin/install install</userinput></screen>
|
---|
| 26 |
|
---|
| 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>
|
---|
| 36 |
|
---|
| 37 | <para>From now on every compiled program will link <emphasis>only</emphasis>
|
---|
[8ad7980] | 38 | against the libraries in <filename class="directory">/usr/lib</filename> and
|
---|
| 39 | <filename class="directory">/lib</filename>. The extra
|
---|
| 40 | <parameter>INSTALL=/tools/bin/install</parameter> is needed because the Makefile
|
---|
[673b0d8] | 41 | created during the second pass still contains the reference to
|
---|
[8ad7980] | 42 | <command>/usr/bin/install</command>, which we obviously haven't installed yet.
|
---|
[673b0d8] | 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>
|
---|
| 46 |
|
---|
| 47 | <para>You can now remove the Binutils source and build directories.</para>
|
---|
| 48 |
|
---|
| 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
|
---|
| 51 | this:</para>
|
---|
| 52 |
|
---|
| 53 | <!-- Ampersands are needed to allow cut and paste -->
|
---|
| 54 |
|
---|
[2ec4b60] | 55 | <screen><userinput>sed -i 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g' \
|
---|
| 56 | `gcc --print-file specs`</userinput></screen>
|
---|
[673b0d8] | 57 |
|
---|
| 58 | <para>Again, cutting and pasting the above is recommended. And just like
|
---|
| 59 | before, it is a good idea to visually inspect the specs file to verify the
|
---|
| 60 | intended change was actually made.</para>
|
---|
| 61 |
|
---|
| 62 | <important><para>If you are working on a platform where the name of the dynamic
|
---|
| 63 | linker is something other than <filename>ld-linux.so.2</filename>, you
|
---|
| 64 | <emphasis>must</emphasis> substitute <filename>ld-linux.so.2</filename> with the
|
---|
| 65 | name of your platform's dynamic linker in the above commands. Refer back to
|
---|
| 66 | <xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | <caution><para>It is imperative at this point to stop and ensure that the
|
---|
| 70 | basic functions (compiling and linking) of the adjusted toolchain are working
|
---|
| 71 | as expected. For this we are going to perform a simple sanity check:</para>
|
---|
| 72 |
|
---|
| 73 | <screen><userinput>echo 'main(){}' > dummy.c
|
---|
| 74 | cc dummy.c
|
---|
| 75 | readelf -l a.out | grep ': /lib'</userinput></screen>
|
---|
| 76 |
|
---|
| 77 | <para>If everything is working correctly, there should be no errors, and the
|
---|
| 78 | output of the last command will be (allowing for platform specific differences
|
---|
| 79 | in dynamic linker name):</para>
|
---|
| 80 |
|
---|
[8ad7980] | 81 | <screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
|
---|
[673b0d8] | 82 |
|
---|
| 83 | <para>Note especially that <filename class="directory">/lib</filename> is now
|
---|
| 84 | the prefix of our dynamic linker.</para>
|
---|
| 85 |
|
---|
| 86 | <para> If you did not receive the output
|
---|
| 87 | as shown above, or received no output at all, then something is seriously wrong.
|
---|
| 88 | You will need to investigate and retrace your steps to find out where the
|
---|
| 89 | problem is and correct it. There is no point in continuing until this is done.
|
---|
| 90 | Most likely something went wrong with the specs file amendment above.</para>
|
---|
| 91 |
|
---|
| 92 | <para>Once you are satisfied that all is well, clean up the test files:</para>
|
---|
| 93 |
|
---|
| 94 | <screen><userinput>rm dummy.c a.out</userinput></screen>
|
---|
| 95 | </caution>
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | </sect1>
|
---|