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>
|
---|
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
|
---|
41 | created during the second pass still contains the reference to
|
---|
42 | <command>/usr/bin/install</command>, 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>
|
---|
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 |
|
---|
55 | <screen><userinput>perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' \
|
---|
56 | -e 's@\*startfile_prefix_spec:\n@$_/usr/lib/@g;' \
|
---|
57 | `gcc --print-file specs`</userinput></screen>
|
---|
58 |
|
---|
59 | <para>Again, cutting and pasting the above is recommended. And just like
|
---|
60 | before, it is a good idea to visually inspect the specs file to verify the
|
---|
61 | intended change was actually made.</para>
|
---|
62 |
|
---|
63 | <important><para>If you are working on a platform where the name of the dynamic
|
---|
64 | linker is something other than <filename>ld-linux.so.2</filename>, you
|
---|
65 | <emphasis>must</emphasis> substitute <filename>ld-linux.so.2</filename> with the
|
---|
66 | name of your platform's dynamic linker in the above commands. Refer back to
|
---|
67 | <xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
|
---|
68 |
|
---|
69 |
|
---|
70 | <caution><para>It is imperative at this point to stop and ensure that the
|
---|
71 | basic functions (compiling and linking) of the adjusted toolchain are working
|
---|
72 | as expected. For this we are going to perform a simple sanity check:</para>
|
---|
73 |
|
---|
74 | <screen><userinput>echo 'main(){}' > dummy.c
|
---|
75 | cc dummy.c
|
---|
76 | readelf -l a.out | grep ': /lib'</userinput></screen>
|
---|
77 |
|
---|
78 | <para>If everything is working correctly, there should be no errors, and the
|
---|
79 | output of the last command will be (allowing for platform specific differences
|
---|
80 | in dynamic linker name):</para>
|
---|
81 |
|
---|
82 | <screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
|
---|
83 |
|
---|
84 | <para>Note especially that <filename class="directory">/lib</filename> is now
|
---|
85 | the prefix of our dynamic linker.</para>
|
---|
86 |
|
---|
87 | <para> If you did not receive the output
|
---|
88 | as shown above, or received no output at all, then something is seriously wrong.
|
---|
89 | You will need to investigate and retrace your steps to find out where the
|
---|
90 | problem is and correct it. There is no point in continuing until this is done.
|
---|
91 | Most likely something went wrong with the specs file amendment above.</para>
|
---|
92 |
|
---|
93 | <para>Once you are satisfied that all is well, clean up the test files:</para>
|
---|
94 |
|
---|
95 | <screen><userinput>rm dummy.c a.out</userinput></screen>
|
---|
96 | </caution>
|
---|
97 |
|
---|
98 |
|
---|
99 | </sect1>
|
---|