adjusting.xml 5.3 KB

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