adjusting.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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, we want all
  10. the tools compiled in the rest of this chapter to be linked against these
  11. libraries. To accomplish this, we need to adjust the linker and the compiler's
  12. specs file. Some people would say that it is <emphasis><quote>black magic juju
  13. below this line</quote></emphasis>, but it is really very simple.</para>
  14. <para>First install the adjusted linker (adjusted at the end of the first pass
  15. of Binutils) by running the following command from within
  16. the <filename class="directory">binutils-build</filename> directory:</para>
  17. <screen><userinput>make -C ld install</userinput></screen>
  18. <para>From this point onwards everything will link <emphasis>only</emphasis>
  19. against the libraries in <filename>/tools/lib</filename>.</para>
  20. <note><para>If you somehow missed the earlier warning to retain the Binutils
  21. source and build directories from the first pass or otherwise accidentally
  22. deleted them or just don't have access to them, don't worry, all is not lost.
  23. Just ignore the above command. The result is 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 we install the
  26. second pass of Binutils a bit further on.</para></note>
  27. <para>Now that the adjusted linker is installed, you have to
  28. <emphasis>remove</emphasis> the Binutils build and source directories.</para>
  29. <para>The next thing to do is to amend our GCC specs file so that it points
  30. to the new dynamic linker. A simple sed will accomplish this:</para>
  31. <!-- Ampersands are needed to allow cut and paste -->
  32. <screen><userinput>SPECFILE=/tools/lib/gcc/*/*/specs &amp;&amp;
  33. sed -e '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>We recommend that you cut-and-paste the above rather than try and type it
  38. all in. Or you can edit the specs file by hand if you want to: just replace the
  39. occurrence of <quote>/lib/ld-linux.so.2</quote> with
  40. <quote>/tools/lib/ld-linux.so.2</quote>. Be sure to visually inspect the specs
  41. file to verify the intended change was actually made.</para>
  42. <important><para>If you are working on a platform where the name of the dynamic
  43. linker is something other than <filename>ld-linux.so.2</filename>, you
  44. <emphasis>must</emphasis> replace <filename>ld-linux.so.2</filename> with the
  45. name of your platform's dynamic linker in the above commands. Refer back to
  46. <xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
  47. <para>Lastly, there is a possibility that some include files from the host
  48. system have found their way into GCC's private include dir. This can happen
  49. because of GCC's <quote>fixincludes</quote> process which runs as part of the
  50. GCC build. We'll explain more about this further on in this chapter. For now,
  51. run the following commands to eliminate this possibility:</para>
  52. <screen><userinput>rm -f /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h}</userinput></screen>
  53. <caution><para>It is imperative at this point to stop and ensure that the basic
  54. functions (compiling and linking) of the new toolchain are working as expected.
  55. For this we are going to perform a simple sanity check:</para>
  56. <screen><userinput>echo 'main(){}' &gt; dummy.c
  57. cc dummy.c
  58. readelf -l a.out | grep ': /tools'</userinput></screen>
  59. <para>If everything is working correctly, there should be no errors, and the
  60. output of the last command will be (allowing for platform specific differences
  61. in dynamic linker name):</para>
  62. <blockquote><screen>[Requesting program interpreter: /tools/lib/ld-linux.so.2]</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 you did not receive the output
  66. as shown above, or received no output at all, then something is seriously wrong.
  67. 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, redo the sanity check using <command>gcc</command> instead of
  70. <command>cc</command>. If this works it means the
  71. <filename class="symlink">/tools/bin/cc</filename> symlink is missing. Revisit
  72. <xref linkend="ch-tools-gcc-pass1"/> and fix 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. ensuring to cut-and-paste the commands as was recommended.</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>