readjusting.xml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 a similar 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>First, create a symlink to the adjusted linker we created in chapter 5.</para>
  21. <screen><userinput>ln -sv /tools/bin/ld-new /usr/bin/ld</userinput></screen>
  22. <para>Next, amend the GCC specs file so that it points to the new
  23. dynamic linker. A <command>sed</command> command accomplishes this:</para>
  24. <screen><userinput>SPECFILE=`dirname $(gcc -print-libgcc-file-name)`/specs &amp;&amp;
  25. gcc -dumpspecs > $SPECFILE &amp;&amp;
  26. sed -i -e '/^\*link:$/{n;s,$, -L/usr/lib,}' \
  27. -e 's@^/tools/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' $SPECFILE &amp;&amp;
  28. unset SPECFILE</userinput></screen>
  29. <para>It is a good idea to visually inspect the specs file to verify the intended
  30. change was actually made.</para>
  31. <important><para>If working on a platform where the name of the
  32. dynamic linker is something other than
  33. <filename class="libraryfile">ld-linux.so.2</filename>, substitute
  34. <quote>ld-linux.so.2</quote> with the name of the platform's
  35. dynamic linker in the above commands. Refer back to <xref
  36. linkend="ch-tools-toolchaintechnotes" role=","/> if
  37. necessary.</para></important>
  38. <para>Now create a temporary wrapper script for <filename>gcc</filename>.
  39. This script will point to the real <filename>gcc</filename>
  40. in <filename class="directory">/tools</filename> but with adjusted parameters
  41. to ensure that GCC in the next section links to our newly installed Glibc.</para>
  42. <screen><userinput>cat &gt; /usr/bin/gcc &lt;&lt; "EOF"
  43. #!/bin/bash
  44. /tools/bin/gcc -B/usr/lib/ -B/usr/bin/ $@
  45. EOF
  46. chmod 755 /usr/bin/gcc
  47. ln -s gcc /usr/bin/cc</userinput></screen>
  48. <caution><para>It is imperative at this point to stop and ensure that
  49. the basic functions (compiling and linking) of the adjusted toolchain
  50. are working as expected. To do this, perform a sanity
  51. check:</para>
  52. <screen><userinput>echo 'main(){}' &gt; dummy.c
  53. cc dummy.c -Wl,--verbose &amp;&gt; dummy.log
  54. readelf -l a.out | grep ': /lib'</userinput></screen>
  55. <para>If everything is working correctly, there should be no errors,
  56. and the output of the last command will be (allowing for
  57. platform-specific differences in dynamic linker name):</para>
  58. <screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
  59. <para>Note that <filename class="directory">/lib</filename> is now
  60. the prefix of our dynamic linker.</para>
  61. <para>Now make sure that we're setup to use the correct start files:</para>
  62. <screen><userinput>grep "/usr/lib/crt.* " dummy.log</userinput></screen>
  63. <para>If everything is working correctly, there should be no errors,
  64. and the output of the last command will be:</para>
  65. <screen><computeroutput>attempt to open /usr/lib/crt1.o succeeded
  66. attempt to open /usr/lib/crti.o succeeded
  67. attempt to open /usr/lib/crtn.o succeeded</computeroutput></screen>
  68. <para>Next make sure that we're using the correct libc:</para>
  69. <screen><userinput>grep "/lib/libc.so.6 " dummy.log</userinput></screen>
  70. <para>If everything is working correctly, there should be no errors,
  71. and the output of the last command will be:</para>
  72. <screen><computeroutput>attempt to open /lib/libc.so.6 succeeded</computeroutput></screen>
  73. <para>Lastly, make sure GCC is using the correct dynamic linker:</para>
  74. <screen><userinput>grep found dummy.log</userinput></screen>
  75. <para>If everything is working correctly, there should be no errors,
  76. and the output of the last command will be (allowing for
  77. platform-specific differences in dynamic linker name):</para>
  78. <screen><computeroutput>found ld-linux.so.2 at /lib/ld-linux.so.2</computeroutput></screen>
  79. <para>If the output does not appear as shown above or is not received
  80. at all, then something is seriously wrong. Investigate and retrace the
  81. steps to find out where the problem is and correct it. The most likely
  82. reason is that something went wrong with the specs file amendment
  83. above. Any issues will need to be resolved before continuing on with
  84. the process.</para>
  85. <para>Once everything is working correctly, clean up the test
  86. files:</para>
  87. <screen><userinput>rm -v dummy.c a.out dummy.log</userinput></screen></caution>
  88. </sect1>