readjusting.xml 4.8 KB

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