1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/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 final C libraries have been installed, it is time to adjust
|
---|
11 | the toolchain again. The toolchain will be adjusted so that it will link any
|
---|
12 | newly compiled program against these new libraries. This is a similar process
|
---|
13 | used in the <quote>Adjusting</quote> phase in the beginning of <xref
|
---|
14 | linkend="chapter-temporary-tools"/>, but with the adjustments reversed. In <xref
|
---|
15 | linkend="chapter-temporary-tools"/>, the chain was guided from the host's
|
---|
16 | <filename class="directory">/{,usr/}lib</filename> directories to the new
|
---|
17 | <filename class="directory">/tools/lib</filename> directory. Now, the chain will
|
---|
18 | be guided from that same <filename class="directory">/tools/lib</filename>
|
---|
19 | directory to the LFS <filename class="directory">/{,usr/}lib</filename>
|
---|
20 | directories.</para>
|
---|
21 |
|
---|
22 | <para>First, create a symlink to the adjusted linker we created in chapter 5.</para>
|
---|
23 |
|
---|
24 | <screen><userinput>ln -sv /tools/bin/ld-new /usr/bin/ld</userinput></screen>
|
---|
25 |
|
---|
26 | <para>Next, amend the GCC specs file so that it points to the new
|
---|
27 | dynamic linker. A <command>sed</command> command accomplishes this:</para>
|
---|
28 |
|
---|
29 | <screen><userinput>SPECFILE=`dirname $(gcc -print-libgcc-file-name)`/specs &&
|
---|
30 | gcc -dumpspecs > $SPECFILE &&
|
---|
31 | sed -i -e '/^\*link:$/{n;s,$, -L/usr/lib,}' \
|
---|
32 | -e 's@^/tools/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' $SPECFILE &&
|
---|
33 | unset SPECFILE</userinput></screen>
|
---|
34 |
|
---|
35 | <para>It is a good idea to visually inspect the specs file to verify the intended
|
---|
36 | change was actually made.</para>
|
---|
37 |
|
---|
38 | <important><para>If working on a platform where the name of the
|
---|
39 | dynamic linker is something other than
|
---|
40 | <filename class="libraryfile">ld-linux.so.2</filename>, substitute
|
---|
41 | <quote>ld-linux.so.2</quote> with the name of the platform's
|
---|
42 | dynamic linker in the above commands. Refer back to <xref
|
---|
43 | linkend="ch-tools-toolchaintechnotes" role=","/> if
|
---|
44 | necessary.</para></important>
|
---|
45 |
|
---|
46 | <para>Now create a temporary wrapper script for <filename>gcc</filename>.
|
---|
47 | This script will point to the real <filename>gcc</filename>
|
---|
48 | in <filename class="directory">/tools</filename> but with adjusted parameters
|
---|
49 | to ensure that GCC in the next section links to our newly installed Glibc.</para>
|
---|
50 |
|
---|
51 | <screen><userinput>cat > /usr/bin/gcc << "EOF"
|
---|
52 | #!/bin/bash
|
---|
53 | /tools/bin/gcc -B/usr/lib/ -B/usr/bin/ $@
|
---|
54 | EOF
|
---|
55 | chmod 755 /usr/bin/gcc
|
---|
56 | ln -s gcc /usr/bin/cc</userinput></screen>
|
---|
57 |
|
---|
58 | <caution><para>It is imperative at this point to stop and ensure that
|
---|
59 | the basic functions (compiling and linking) of the adjusted toolchain
|
---|
60 | are working as expected. To do this, perform a sanity
|
---|
61 | check:</para>
|
---|
62 |
|
---|
63 | <screen><userinput>echo 'main(){}' > dummy.c
|
---|
64 | cc dummy.c -Wl,--verbose &> dummy.log
|
---|
65 | readelf -l a.out | grep ': /lib'</userinput></screen>
|
---|
66 |
|
---|
67 | <para>If everything is working correctly, there should be no errors,
|
---|
68 | and the output of the last command will be (allowing for
|
---|
69 | platform-specific differences in dynamic linker name):</para>
|
---|
70 |
|
---|
71 | <screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
|
---|
72 |
|
---|
73 | <para>Note that <filename class="directory">/lib</filename> is now
|
---|
74 | the prefix of our dynamic linker.</para>
|
---|
75 |
|
---|
76 | <para>Now make sure that we're setup to use the correct start files:</para>
|
---|
77 |
|
---|
78 | <screen><userinput>grep "/usr/lib/crt.* " dummy.log</userinput></screen>
|
---|
79 |
|
---|
80 | <para>If everything is working correctly, there should be no errors,
|
---|
81 | and the output of the last command will be:</para>
|
---|
82 |
|
---|
83 | <screen><computeroutput>attempt to open /usr/lib/crt1.o succeeded
|
---|
84 | attempt to open /usr/lib/crti.o succeeded
|
---|
85 | attempt to open /usr/lib/crtn.o succeeded</computeroutput></screen>
|
---|
86 |
|
---|
87 | <para>Next make sure that we're using the correct libc:</para>
|
---|
88 |
|
---|
89 | <screen><userinput>grep "/lib/libc.so.6 " dummy.log</userinput></screen>
|
---|
90 |
|
---|
91 | <para>If everything is working correctly, there should be no errors,
|
---|
92 | and the output of the last command will be:</para>
|
---|
93 |
|
---|
94 | <screen><computeroutput>attempt to open /lib/libc.so.6 succeeded</computeroutput></screen>
|
---|
95 |
|
---|
96 | <para>Lastly, make sure GCC is using the correct dynamic linker:</para>
|
---|
97 |
|
---|
98 | <screen><userinput>grep found dummy.log</userinput></screen>
|
---|
99 |
|
---|
100 | <para>If everything is working correctly, there should be no errors,
|
---|
101 | and the output of the last command will be (allowing for
|
---|
102 | platform-specific differences in dynamic linker name):</para>
|
---|
103 |
|
---|
104 | <screen><computeroutput>found ld-linux.so.2 at /lib/ld-linux.so.2</computeroutput></screen>
|
---|
105 |
|
---|
106 | <para>If the output does not appear as shown above or is not received
|
---|
107 | at all, then something is seriously wrong. Investigate and retrace the
|
---|
108 | steps to find out where the problem is and correct it. The most likely
|
---|
109 | reason is that something went wrong with the specs file amendment
|
---|
110 | above. Any issues will need to be resolved before continuing on with
|
---|
111 | the process.</para>
|
---|
112 |
|
---|
113 | <para>Once everything is working correctly, clean up the test
|
---|
114 | files:</para>
|
---|
115 |
|
---|
116 | <screen><userinput>rm -v dummy.c a.out dummy.log</userinput></screen></caution>
|
---|
117 |
|
---|
118 | </sect1>
|
---|
119 |
|
---|