binutils-pass2.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-tools-binutils-pass2" role="wrap">
  8. <?dbhtml filename="binutils-pass2.html"?>
  9. <sect1info condition="script">
  10. <productname>binutils-pass2</productname>
  11. <productnumber>&binutils-version;</productnumber>
  12. <address>&binutils-url;</address>
  13. </sect1info>
  14. <title>Binutils-&binutils-version; - 第二遍</title>
  15. <indexterm zone="ch-tools-binutils-pass2">
  16. <primary sortas="a-Binutils">Binutils</primary>
  17. <secondary>tools, pass 2</secondary>
  18. </indexterm>
  19. <sect2 role="package">
  20. <title/>
  21. <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
  22. href="../chapter06/binutils.xml"
  23. xpointer="xpointer(/sect1/sect2[1]/para[1])"/>
  24. <segmentedlist>
  25. <segtitle>&buildtime;</segtitle>
  26. <segtitle>&diskspace;</segtitle>
  27. <seglistitem>
  28. <seg>&binutils-ch5p2-sbu;</seg>
  29. <seg>&binutils-ch5p2-du;</seg>
  30. </seglistitem>
  31. </segmentedlist>
  32. </sect2>
  33. <sect2 role="installation">
  34. <title>安装 Binutils</title>
  35. <para>再一次地,创建一个单独的构建目录:</para>
  36. <screen><userinput remap="pre">mkdir -v build
  37. cd build</userinput></screen>
  38. <para>准备安装 Binutils:</para>
  39. <screen><userinput remap="configure">CC=$LFS_TGT-gcc \
  40. AR=$LFS_TGT-ar \
  41. RANLIB=$LFS_TGT-ranlib \
  42. ../configure \
  43. --prefix=/tools \
  44. --disable-nls \
  45. --disable-werror \
  46. --with-lib-path=/tools/lib \
  47. --with-sysroot</userinput></screen>
  48. <variablelist>
  49. <title>配置选项的含义:</title>
  50. <varlistentry>
  51. <term><parameter>CC=$LFS_TGT-gcc AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib</parameter></term>
  52. <listitem>
  53. <!--para>Because this is really a native build of Binutils, setting these
  54. variables ensures that the build system uses the cross-compiler and
  55. associated tools instead of the ones on the host system.</para-->
  56. <para>这次编译 Binutils 是本地编译而不是交叉编译,
  57. 设置这些变量可以强制构建系统使用交叉编译器和相关工具,
  58. 而不是宿主系统的编译器和工具。</para>
  59. </listitem>
  60. </varlistentry>
  61. <varlistentry>
  62. <term><parameter>--with-lib-path=/tools/lib</parameter></term>
  63. <listitem>
  64. <!--para>This tells the configure script to specify the library
  65. search path during the compilation of Binutils, resulting in
  66. <filename class="directory">/tools/lib</filename> being passed
  67. to the linker. This prevents the linker from searching through
  68. library directories on the host.</para-->
  69. <para>这个选项使得配置脚本在编译 Binutils 时指定库文件搜索目录,
  70. 将 <filename class="directory">/tools/lib</filename>
  71. 传递给链接器。这保证链接器不会搜索宿主系统的库文件目录。
  72. </para>
  73. </listitem>
  74. </varlistentry>
  75. <varlistentry>
  76. <term><parameter>--with-sysroot</parameter></term>
  77. <listitem>
  78. <!--para>The sysroot feature enables the linker to find shared objects
  79. which are required by other shared objects explicitly included on the
  80. linker's command line. Without this, some packages may not build
  81. successfully on some hosts.</para-->
  82. <para>在链接时,某些共享对象可能要求其他共享对象,sysroot
  83. 特性允许链接器查找它们。如果不启用它,在某些宿主环境中,
  84. 一些软件包无法成功构建。</para>
  85. <note><title>译注</title>
  86. <para>这个选项看上去很奇怪,而且解释不够清晰。
  87. 译者查资料得知,
  88. 从 Binutils 2.17 起,为保证和动态链接器的一致性,
  89. <command>ld</command>在搜索 DT_NEEDED
  90. 要求的共享对象时,先搜索
  91. <filename>/etc/ld.so.conf</filename> 指定的目录,
  92. 再搜索配置时指定的默认目录。如果不启用 sysroot 功能,
  93. 且宿主系统使用了 <filename>/etc/ld.so.conf</filename>,
  94. 那么宿主环境中的共享对象会污染工具链,
  95. 进而导致一系列严重问题。
  96. 如果您不想使用这个看上去奇怪的选项,可以执行
  97. <userinput>touch /tools/etc/ld.so.conf</userinput>
  98. 创建一个空的 <filename>ld.so.conf</filename> 文件,
  99. 覆盖宿主系统的设置。参阅
  100. <ulink url="http://lists.linuxfromscratch.org/pipermail/lfs-dev/2012-December/067457.html">lfs-dev 列表中的讨论</ulink>,以及
  101. <ulink url="https://sourceware.org/bugzilla/show_bug.cgi?id=2290">ld/2290</ulink>。
  102. 另外 <filename>ld(1)</filename>
  103. 中关于这个搜索顺序的描述尚未更新。
  104. </para>
  105. </note>
  106. </listitem>
  107. </varlistentry>
  108. </variablelist>
  109. <para>编译该软件包:</para>
  110. <screen><userinput remap="make">make</userinput></screen>
  111. <para>安装该软件包:</para>
  112. <screen><userinput remap="install">make install</userinput></screen>
  113. <!--para>Now prepare the linker for the <quote>Re-adjusting</quote> phase in
  114. the next chapter:</para-->
  115. <para>现在,为下一章的 <quote>重新调整</quote> 阶段准备链接器:</para>
  116. <screen><userinput remap="adjust">make -C ld clean
  117. make -C ld LIB_PATH=/usr/lib:/lib
  118. cp -v ld/ld-new /tools/bin</userinput></screen>
  119. <variablelist>
  120. <title>make 命令参数的含义:</title>
  121. <varlistentry>
  122. <term><parameter>-C ld clean</parameter></term>
  123. <listitem>
  124. <!--para>This tells the make program to remove all compiled
  125. files in the <filename class="directory">ld</filename>
  126. subdirectory.</para-->
  127. <para>该选项告诉 make 程序移除
  128. <filename class="directory">ld</filename>
  129. 子目录中所有编译得到的文件。</para>
  130. </listitem>
  131. </varlistentry>
  132. <varlistentry>
  133. <term><parameter>-C ld LIB_PATH=/usr/lib:/lib</parameter></term>
  134. <listitem>
  135. <!--para>This option rebuilds everything in the <filename
  136. class="directory">ld</filename> subdirectory. Specifying the
  137. <envar>LIB_PATH</envar> Makefile variable on the command line
  138. allows us to override the default value of the temporary tools
  139. and point it to the proper final path. The value of this variable
  140. specifies the linker's default library search path. This
  141. preparation is used in the next chapter.</para-->
  142. <para>该选项重新构建 <filename class="directory">ld</filename>
  143. 子目录中的一切。在命令行指定 <envar>LIB_PATH</envar>
  144. Makefile 变量,即可覆盖临时工具的默认值,
  145. 并将其指向正确的最终路径。
  146. 该变量的值指定链接器的默认库文件搜索路径,
  147. 这个准备好的链接器将在下一章使用。</para>
  148. </listitem>
  149. </varlistentry>
  150. </variablelist>
  151. </sect2>
  152. <sect2 role="content">
  153. <title/>
  154. <para>该软件包的更多信息可以在
  155. <xref linkend="contents-binutils"/> 中找到。</para>
  156. </sect2>
  157. </sect1>