[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-tools-adjusting">
|
---|
| 7 | <title>Adjusting the toolchain</title>
|
---|
| 8 | <?dbhtml filename="adjusting.html"?>
|
---|
| 9 |
|
---|
[f904a87] | 10 | <para>Now that the temporary C libraries have been installed, all
|
---|
| 11 | the tools compiled in the rest of this chapter should be linked against these
|
---|
[d9f0c46] | 12 | libraries. In order to accomplish this, the linker and the compiler's
|
---|
[f904a87] | 13 | specs file, need to be adjsted.</para>
|
---|
| 14 |
|
---|
| 15 | <para> Some people would say that there is <emphasis><quote>black magic juju
|
---|
[673b0d8] | 16 | below this line</quote></emphasis>, but it is really very simple.</para>
|
---|
| 17 |
|
---|
[d9f0c46] | 18 | <para>First, the linker, adjusted at the end of the first pass of Binutils, is
|
---|
| 19 | installed by running the following command from within
|
---|
[673b0d8] | 20 | the <filename class="directory">binutils-build</filename> directory:</para>
|
---|
| 21 |
|
---|
| 22 | <screen><userinput>make -C ld install</userinput></screen>
|
---|
| 23 |
|
---|
| 24 | <para>From this point onwards everything will link <emphasis>only</emphasis>
|
---|
[574b0ea] | 25 | against the libraries in <filename class="directory">/tools/lib</filename>.</para>
|
---|
[673b0d8] | 26 |
|
---|
[f904a87] | 27 | <note><para>If you missed the earlier warning to retain the Binutils
|
---|
| 28 | source and build directories from the first pass, dont worry - all is not lost.
|
---|
| 29 | Just ignore the above command. This results in a small chance of the subsequent
|
---|
[673b0d8] | 30 | testing programs linking against libraries on the host. This is not ideal, but
|
---|
[f904a87] | 31 | it's not a major problem. The situation is corrected when the second pass of
|
---|
| 32 | Binutils is installed later on.</para></note>
|
---|
[673b0d8] | 33 |
|
---|
[f904a87] | 34 | <para>Now that the adjusted linker is installed, the Binutils build and source
|
---|
[9c5c7c9a] | 35 | directories should be <emphasis>removed</emphasis>.</para>
|
---|
[673b0d8] | 36 |
|
---|
[f904a87] | 37 | <para>The next task is to amend our GCC specs file so that it points
|
---|
| 38 | to the new dynamic linker. A simple sed script will accomplish this:</para>
|
---|
[673b0d8] | 39 |
|
---|
| 40 | <!-- Ampersands are needed to allow cut and paste -->
|
---|
| 41 |
|
---|
[9109cd4] | 42 | <screen><userinput>SPECFILE=`gcc --print-file specs` &&
|
---|
[2ec4b60] | 43 | sed 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \
|
---|
[673b0d8] | 44 | $SPECFILE > tempspecfile &&
|
---|
| 45 | mv -f tempspecfile $SPECFILE &&
|
---|
| 46 | unset SPECFILE</userinput></screen>
|
---|
| 47 |
|
---|
[d9f0c46] | 48 | <para>It is recommended that the above command be cut-and-pasted in order to
|
---|
| 49 | ensure correctness - Alternatively, the specs file can be edited by hand. This
|
---|
| 50 | is done simply by replacing every occurrence of
|
---|
| 51 | <quote>/lib/ld-linux.so.2</quote> with <quote>/tools/lib/ld-linux.so.2</quote>.
|
---|
| 52 | </para>
|
---|
[f904a87] | 53 |
|
---|
[9c5c7c9a] | 54 | <para> Be sure to visually inspect the specs file in order to verify the intended changes have been made.</para>
|
---|
[673b0d8] | 55 |
|
---|
| 56 | <important><para>If you are working on a platform where the name of the dynamic
|
---|
| 57 | linker is something other than <filename>ld-linux.so.2</filename>, you
|
---|
| 58 | <emphasis>must</emphasis> replace <filename>ld-linux.so.2</filename> with the
|
---|
| 59 | name of your platform's dynamic linker in the above commands. Refer back to
|
---|
| 60 | <xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
|
---|
| 61 |
|
---|
| 62 | <para>Lastly, there is a possibility that some include files from the host
|
---|
| 63 | system have found their way into GCC's private include dir. This can happen
|
---|
[f904a87] | 64 | as a result of of GCC's <quote>fixincludes</quote> process which runs as part
|
---|
| 65 | of the GCC build. We'll explain more about this further on in this chapter.
|
---|
| 66 | Run the following commands to eliminate this possibility:</para>
|
---|
[673b0d8] | 67 |
|
---|
[c8ba565] | 68 | <screen><userinput>rm -f /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h}</userinput></screen>
|
---|
[673b0d8] | 69 |
|
---|
| 70 |
|
---|
| 71 | <caution><para>It is imperative at this point to stop and ensure that the basic
|
---|
| 72 | functions (compiling and linking) of the new toolchain are working as expected.
|
---|
[d9f0c46] | 73 | To perform a simple sanity check, run the following commands:</para>
|
---|
[673b0d8] | 74 |
|
---|
| 75 | <screen><userinput>echo 'main(){}' > dummy.c
|
---|
| 76 | cc dummy.c
|
---|
| 77 | readelf -l a.out | grep ': /tools'</userinput></screen>
|
---|
| 78 |
|
---|
| 79 | <para>If everything is working correctly, there should be no errors, and the
|
---|
[f904a87] | 80 | output of the last command will be of the form:</para>
|
---|
[673b0d8] | 81 |
|
---|
[574b0ea] | 82 | <blockquote><screen><computeroutput>[Requesting program interpreter: /tools/lib/ld-linux.so.2]</computeroutput></screen></blockquote>
|
---|
[673b0d8] | 83 |
|
---|
| 84 | <para>Note especially that <filename class="directory">/tools/lib</filename>
|
---|
| 85 | appears as the prefix of our dynamic linker.</para>
|
---|
| 86 |
|
---|
[f904a87] | 87 | <para>If the output is not
|
---|
| 88 | as shown above, or there was no output at all, then something is seriously
|
---|
| 89 | wrong. You will need to investigate and retrace your steps to find out where the
|
---|
[673b0d8] | 90 | problem is and correct it. There is no point in continuing until this is done.
|
---|
[f904a87] | 91 | First, perform the sanity check again, using <command>gcc</command> instead of
|
---|
[d9f0c46] | 92 | <command>cc</command>. If this works, then the
|
---|
[673b0d8] | 93 | <filename class="symlink">/tools/bin/cc</filename> symlink is missing. Revisit
|
---|
[f904a87] | 94 | <xref linkend="ch-tools-gcc-pass1"/> and install the symlink. Second, ensure your PATH
|
---|
[673b0d8] | 95 | is correct. You can check this by running <userinput>echo $PATH</userinput> and
|
---|
| 96 | verifying that <filename class="directory">/tools/bin</filename> is at the head
|
---|
| 97 | of the list. If the PATH is wrong it could mean you're not logged in as user
|
---|
| 98 | <emphasis>lfs</emphasis> or something went wrong back in
|
---|
| 99 | <xref linkend="ch-tools-settingenviron"/>. Third, something may have gone wrong with
|
---|
| 100 | the specs file amendment above. In this case redo the specs file amendment
|
---|
[f904a87] | 101 | being careful to cut-and-paste the commands.</para>
|
---|
[673b0d8] | 102 |
|
---|
| 103 | <para>Once you are satisfied that all is well, clean up the test files:</para>
|
---|
| 104 |
|
---|
| 105 | <screen><userinput>rm dummy.c a.out</userinput></screen>
|
---|
| 106 | </caution>
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | </sect1>
|
---|