readjusting.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. <para>Now that the final C libraries have been installed, it is time to adjust
  10. the toolchain again. The toolchain will be adjusted so that it will link any
  11. newly compiled program against these new libraries. This is the same process
  12. used in the <quote>Adjusting</quote> phase in the beginning of <xref
  13. linkend="chapter-temporary-tools"/>, but with the adjustments reversed. In <xref
  14. linkend="chapter-temporary-tools"/>, the chain was guided from the host's
  15. <filename class="directory">/{,usr/}lib</filename> directories to the new
  16. <filename class="directory">/tools/lib</filename> directory. Now, the chain will
  17. be guided from that same <filename class="directory">/tools/lib</filename>
  18. directory to the LFS <filename class="directory">/{,usr/}lib</filename>
  19. directories.</para>
  20. <para>Start by adjusting the linker. The source and build directories from the
  21. second pass of Binutils were retained for this purpose. Install the adjusted
  22. linker by running the following command from within the <filename
  23. class="directory">binutils-build</filename> directory:</para>
  24. <screen><userinput>make -C ld INSTALL=/tools/bin/install install</userinput></screen>
  25. <note><para>If the earlier warning to retain the Binutils source and
  26. build directories from the second pass in <xref
  27. linkend="chapter-temporary-tools"/> was missed, or if they were
  28. accidentally deleted or are inaccessible, ignore the above command.
  29. The result will be that the next package, Binutils, will link against
  30. the C libraries in <filename class="directory">/tools</filename>
  31. rather than in <filename class="directory">/{,usr/}lib</filename>.
  32. This is not ideal, however, testing has shown that the resulting
  33. Binutils program binaries should be identical.</para></note>
  34. <para>From now on, every compiled program will link only against the
  35. libraries in <filename class="directory">/usr/lib</filename> and
  36. <filename class="directory">/lib</filename>. The extra
  37. <parameter>INSTALL=/tools/bin/install</parameter> option is needed
  38. because the <filename>Makefile</filename> file created during the
  39. second pass still contains the reference to
  40. <command>/usr/bin/install</command>, which has not been installed yet.
  41. Some host distributions contain a <filename
  42. class="symlink">ginstall</filename> symbolic link which takes
  43. precedence in the <filename>Makefile</filename> file and can cause a
  44. problem. The above command takes care of this issue.</para>
  45. <para>Remove the Binutils source and build directories now.</para>
  46. <para>Next, amend the GCC specs file so that it points to the new
  47. dynamic linker. A <command>perl</command> command accomplishes this:</para>
  48. <screen><userinput>perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' \
  49. -e 's@\*startfile_prefix_spec:\n@$_/usr/lib/ @g;' \
  50. `gcc --print-file specs`</userinput></screen>
  51. <para>It is a good idea to visually inspect the specs file to verify the intended
  52. change was actually made.</para>
  53. <important><para>If working on a platform where the name of the
  54. dynamic linker is something other than
  55. <filename class="libraryfile">ld-linux.so.2</filename>, substitute
  56. <quote>ld-linux.so.2</quote> with the name of the platform's
  57. dynamic linker in the above commands. Refer back to <xref
  58. linkend="ch-tools-toolchaintechnotes" role=","/> if
  59. necessary.</para></important>
  60. <caution><para>It is imperative at this point to stop and ensure that
  61. the basic functions (compiling and linking) of the adjusted toolchain
  62. are working as expected. To do this, perform a sanity
  63. check:</para>
  64. <screen><userinput>echo 'main(){}' &gt; dummy.c
  65. cc dummy.c
  66. readelf -l a.out | grep ': /lib'</userinput></screen>
  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. <screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
  71. <para>Note that <filename class="directory">/lib</filename> is now
  72. the prefix of our dynamic linker.</para>
  73. <para>If the output does not appear as shown above or is not received
  74. at all, then something is seriously wrong. Investigate and retrace the
  75. steps to find out where the problem is and correct it. The most likely
  76. reason is that something went wrong with the specs file amendment
  77. above. Any issues will need to be resolved before continuing on with
  78. the process.</para>
  79. <para>Once everything is working correctly, clean up the test
  80. files:</para>
  81. <screen><userinput>rm dummy.c a.out</userinput></screen></caution>
  82. </sect1>