1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
8 <sect1 id="ch-tools-adjusting">
9 <?dbhtml filename="adjusting.html"?>
11 <title>Adjusting the Toolchain</title>
13 <para>Now that the temporary C libraries have been installed, all
14 tools compiled in the rest of this chapter should be linked against
15 these libraries. In order to accomplish this, the cross-compiler's
16 specs file needs to be adjusted to point to the new dynamic linker
17 in <filename class="directory">/tools</filename>.</para>
19 <para>This is done by dumping the compiler's <quote>specs</quote> file to a
20 location where it will look for it by default.
21 A simple <command>sed</command> substitution then alters the
22 dynamic linker that GCC will use. The principle here is to find all references
23 to the dynamic linker file in <filename class="directory">/lib</filename>
24 or possibly <filename class="directory">/lib64</filename> if the host system
25 is 64-bit capable, and adjust them to point to the new location in
26 <filename class="directory">/tools</filename>.</para>
28 <para>For the sake of accuracy, it is recommended to use a copy-and-paste
29 method when issuing the following command. Be sure to visually inspect the
30 specs file to verify that it has properly adjusted all references to the
31 dynamic linker location. Refer to <xref
32 linkend="ch-tools-toolchaintechnotes" role=","/> for the default name
33 of the dynamic linker, if necessary.</para>
35 <!-- Ampersands are needed to allow copy and paste -->
36 <screen><userinput>SPECS=`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/specs
37 $LFS_TGT-gcc -dumpspecs | sed \
38 -e 's@/lib\(64\)\?/ld@/tools&@g' \
39 -e "/^\*cpp:$/{n;s,$, -isystem /tools/include,}" > $SPECS
40 echo "New specs file is: $SPECS"
41 unset SPECS</userinput></screen>
44 <para>At this point, it is imperative to stop and ensure that the basic
45 functions (compiling and linking) of the new toolchain are working as
46 expected. To perform a sanity check, run the following commands:</para>
48 <screen><userinput>echo 'main(){}' > dummy.c
49 $LFS_TGT-gcc -B/tools/lib dummy.c
50 readelf -l a.out | grep ': /tools'</userinput></screen>
52 <para>If everything is working correctly, there should be no errors,
53 and the output of the last command will be of the form:</para>
55 <screen><computeroutput>[Requesting program interpreter: /tools/lib/ld-linux.so.2]</computeroutput></screen>
57 <para>Note that <filename class="directory">/tools/lib</filename>, or
58 <filename class="directory">/tools/lib64</filename> for 64-bit machines
59 appears as the prefix of the dynamic linker.</para>
61 <para>If the output is not shown as above or there was no output at all,
62 then something is wrong. Investigate and retrace the steps to find out
63 where the problem is and correct it. This issue must be resolved before
64 continuing on. Something may have gone wrong with the
65 specs file amendment above. In this case, redo the specs file amendment,
66 being careful to copy-and-paste the commands.</para>
68 <para>Once all is well, clean up the test files:</para>
70 <screen><userinput>rm -v dummy.c a.out</userinput></screen>
74 <note><para>Building Binutils in the next section will serve as an additional check that
75 the toolchain has been built properly. If Binutils fails to build, it is an
76 indication that something has gone wrong with the previous Binutils, GCC, or Glibc
77 installations.</para></note>