readjusting.xml 3.8 KB

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