readjusting.xml 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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-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's time to
  10. adjust our toolchain again. We'll adjust it so that it will link any newly
  11. compiled program against these new libraries. This is in fact the same thing we
  12. did in the <quote>Adjusting</quote> phase in the beginning of the previous
  13. chapter, even though it looks like the reverse: then we guided the chain from
  14. the host's <filename class="directory">/{,usr/}lib</filename> to the new
  15. <filename class="directory">/tools/lib</filename>, now we guide it from that
  16. same <filename class="directory">/tools/lib</filename> to the LFS's <filename
  17. class="directory">/{,usr/}lib</filename>.</para>
  18. <para>First we adjust the linker. For this we retained the
  19. source and build directories from the second pass over Binutils. Install the
  20. adjusted linker by running the following from within the
  21. <filename class="directory">binutils-build</filename> directory:</para>
  22. <screen><userinput>make -C ld INSTALL=/tools/bin/install install</userinput></screen>
  23. <note><para>If you somehow missed the earlier warning to retain the Binutils
  24. source and build directories from the second pass in
  25. <xref linkend="chapter-temporary-tools"/>, or otherwise accidentally deleted them or just
  26. don't have access to them, don't worry, all is not lost. Just ignore the above
  27. command. The result will be that the next package, Binutils, will link against
  28. the C libraries in <filename class="directory">/tools</filename> rather
  29. than in <filename class="directory">/{,usr/}lib</filename>. This is not ideal,
  30. however, our testing has shown that the resulting Binutils program binaries
  31. should be identical.</para></note>
  32. <para>From now on every compiled program will link <emphasis>only</emphasis>
  33. against the libraries in <filename class="directory">/usr/lib</filename> and
  34. <filename class="directory">/lib</filename>. The extra
  35. <parameter>INSTALL=/tools/bin/install</parameter> is needed because the Makefile
  36. created during the second pass still contains the reference to
  37. <command>/usr/bin/install</command>, which we obviously haven't installed yet.
  38. Some host distributions contain a <filename class="symlink">ginstall</filename>
  39. symbolic link which takes precedence in the Makefile and thus can cause a
  40. problem here. The above command takes care of this also.</para>
  41. <para>You can now remove the Binutils source and build directories.</para>
  42. <para>The next thing to do is to amend our GCC specs file so that it points
  43. to the new dynamic linker. Just like earlier on, we use a sed to accomplish
  44. this:</para>
  45. <!-- Ampersands are needed to allow cut and paste -->
  46. <screen><userinput>sed -i 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g' \
  47. `gcc --print-file specs`</userinput></screen>
  48. <para>Again, cutting and pasting the above is recommended. And just like
  49. before, it is a good idea to visually inspect the specs file to verify the
  50. intended change was actually made.</para>
  51. <important><para>If you are working on a platform where the name of the dynamic
  52. linker is something other than <filename>ld-linux.so.2</filename>, you
  53. <emphasis>must</emphasis> substitute <filename>ld-linux.so.2</filename> with the
  54. name of your platform's dynamic linker in the above commands. Refer back to
  55. <xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
  56. <caution><para>It is imperative at this point to stop and ensure that the
  57. basic functions (compiling and linking) of the adjusted toolchain are working
  58. as expected. For this we are going to perform a simple sanity check:</para>
  59. <screen><userinput>echo 'main(){}' &gt; dummy.c
  60. cc dummy.c
  61. readelf -l a.out | grep ': /lib'</userinput></screen>
  62. <para>If everything is working correctly, there should be no errors, and the
  63. output of the last command will be (allowing for platform specific differences
  64. in dynamic linker name):</para>
  65. <screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
  66. <para>Note especially that <filename class="directory">/lib</filename> is now
  67. the prefix of our dynamic linker.</para>
  68. <para> If you did not receive the output
  69. as shown above, or received no output at all, then something is seriously wrong.
  70. You will need to investigate and retrace your steps to find out where the
  71. problem is and correct it. There is no point in continuing until this is done.
  72. Most likely something went wrong with the specs file amendment above.</para>
  73. <para>Once you are satisfied that all is well, clean up the test files:</para>
  74. <screen><userinput>rm dummy.c a.out</userinput></screen>
  75. </caution>
  76. </sect1>