chapter05.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <chapter id="chapter05">
  2. <title>Preparing the LFS system</title>
  3. <?dbhtml filename="chapter05.html" dir="chapter05"?>
  4. &c5-introduction;
  5. &c5-whystatic;
  6. &c5-creatingstage1dir;
  7. &c5-addinguser;
  8. &c5-settingenviron;
  9. &c5-binutils-pass1;
  10. &c5-gcc-pass1;
  11. &c5-kernelheaders;
  12. &c5-glibc;
  13. &c5-lockingglibc;
  14. &c5-tcl;
  15. &c5-expect;
  16. &c5-dejagnu;
  17. &c5-gcc-pass2;
  18. &c5-binutils-pass2;
  19. &c5-gawk;
  20. &c5-coreutils;
  21. &c5-bzip2;
  22. &c5-gzip;
  23. &c5-diffutils;
  24. &c5-findutils;
  25. &c5-make;
  26. &c5-grep;
  27. &c5-sed;
  28. &c5-gettext;
  29. &c5-ncurses;
  30. &c5-patch;
  31. &c5-tar;
  32. &c5-texinfo;
  33. &c5-bash;
  34. &c5-utillinux;
  35. &c5-perl;
  36. <sect1 id="ch05-adjustingtoolchain">
  37. <title>Re-adjusting the toolchain</title>
  38. <?dbhtml filename="adjustingtoolchain.html" dir="chapter05"?>
  39. <para>Now that we have compiled all the necessary tools, it is time to
  40. re-adjust our toolchain. We will set it up so that it will link any newly
  41. compiled program against the new Glibc, which is the first thing to get
  42. compiled in the next chapter. Basically, this is the reverse of what we did
  43. in the "Locking in" stage in the beginning of this chapter.</para>
  44. <para>The first thing to do is to adjust the linker scripts. For this we
  45. retained the <filename>binutils-build</filename> directory from the second
  46. pass over Binutils. Do the following:</para>
  47. <para><screen><userinput>cd binutils-build
  48. make -C ld INSTALL=/stage1/bin/install install-data-local</userinput></screen></para>
  49. <para>This installs the adjusted linker scripts. The linker scripts now contain
  50. no mention of <filename>/stage1/lib</filename>. From now on every compiled
  51. program will link <emphasis>only</emphasis> against the libraries in
  52. <filename>/usr/lib</filename> and <filename>/lib</filename>. The extra
  53. <userinput>INSTALL=/stage1/bin/install</userinput> is needed because the
  54. Makefile created during the second pass still contains the reference to
  55. <filename>/usr/bin/install</filename>, which we obviously haven't installed
  56. yet.</para>
  57. <para>You can now remove the Binutils source and build directories.</para>
  58. <para>The next thing to do is to amend our GCC specs file so that it points to
  59. the new dynamic linker. Just like earlier on, we use a sed to accomplish
  60. this:</para>
  61. <para><screen><userinput>CURRENTSPECFILE=/stage1/lib/gcc-lib/*/*/specs
  62. sed -e 's@/stage1/lib/ld.so.1@/lib/ld.so.1@g' \
  63. &nbsp;&nbsp;&nbsp;&nbsp;-e 's@/stage1/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' \
  64. &nbsp;&nbsp;&nbsp;&nbsp;$CURRENTSPECFILE > newspecfile
  65. mv newspecfile $CURRENTSPECFILE
  66. unset CURRENTSPECFILE</userinput></screen></para>
  67. <para>Again, cutting and pasting the above is recommended. And just like
  68. before, it is a good idea to check the linker scripts and the specs file to
  69. ensure the intended changes were actually made.</para>
  70. <para>Note that the linker scripts will still contain a reference to
  71. <filename>/stage1/i686-pc-linux-gnu/lib</filename>. This is unavoidable, but
  72. luckily does not present a problem. There are no libraries in that location
  73. as all the temporary stage1 libraries are located in
  74. <filename>/stage1/lib</filename>.</para>
  75. </sect1>
  76. <sect1 id="ch05-stripping">
  77. <title>Stripping</title>
  78. <?dbhtml filename="stripping.html" dir="chapter05"?>
  79. <para>If your LFS partition is rather small, you will be glad to learn that you
  80. can throw away some unnecessary things. The executables and libraries you have
  81. built so far contain about 130 MB of unneeded debugging symbols. Remove those
  82. symbols like this:</para>
  83. <para><screen><userinput>strip --strip-unneeded /stage1/{,s}bin/*
  84. strip --strip-debug /stage1/lib/*</userinput></screen></para>
  85. <para>The first of the above commands will skip some twenty files, reporting
  86. that it doesn't recognize their file format. Most of them are scripts instead
  87. of binaries.</para>
  88. <para>Take care <emphasis>not</emphasis> to use
  89. <userinput>--strip-unneeded</userinput> on the libraries -- they would be
  90. destroyed and you would have to build Glibc all over again.</para>
  91. <para>To save another couple of megabytes, you can throw away the documentation
  92. and some of the bigger unneeded programs:</para>
  93. <para><screen><userinput>rm -r /stage1/share/{doc,info,man}
  94. rm /stage1/bin/{addr2line,gprof,nm,size,strings,strip}</userinput></screen></para>
  95. <para>You will now need to have at least 700 MB of free space on your LFS
  96. filesystem to be able to build and install Glibc in the next phase.</para>
  97. </sect1>
  98. </chapter>