Changeset 1668d8e for chapter05/toolchaintechnotes.xml
- Timestamp:
- 10/11/2003 10:51:08 AM (21 years ago)
- Branches:
- 10.0, 10.0-rc1, 10.1, 10.1-rc1, 11.0, 11.0-rc1, 11.0-rc2, 11.0-rc3, 11.1, 11.1-rc1, 11.2, 11.2-rc1, 11.3, 11.3-rc1, 12.0, 12.0-rc1, 12.1, 12.1-rc1, 6.0, 6.1, 6.1.1, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.5-systemd, 7.6, 7.6-systemd, 7.7, 7.7-systemd, 7.8, 7.8-systemd, 7.9, 7.9-systemd, 8.0, 8.1, 8.2, 8.3, 8.4, 9.0, 9.1, arm, bdubbs/gcc13, ml-11.0, multilib, renodr/libudev-from-systemd, s6-init, trunk, v5_0, v5_1, v5_1_1, xry111/arm64, xry111/arm64-12.0, xry111/clfs-ng, xry111/lfs-next, xry111/loongarch, xry111/loongarch-12.0, xry111/loongarch-12.1, xry111/mips64el, xry111/pip3, xry111/rust-wip-20221008, xry111/update-glibc
- Children:
- 313e0960
- Parents:
- 1f0f472
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chapter05/toolchaintechnotes.xml
r1f0f472 r1668d8e 14 14 build a self-contained and self-hosted toolchain. It should be noted that the 15 15 build process has been designed in such a way so as to minimize the risks for 16 new readers and also provide maximum educational value at the same time. In 17 other words, more advanced techniques could be used to achieve the same 18 goals.</para> 16 new readers and provide maximum educational value at the same time. In other 17 words, more advanced techniques could be used to build the system.</para> 19 18 20 19 <important> … … 57 56 choose.</para></listitem> 58 57 59 <listitem><para>Careful manipulation of GCC's <emphasis>specs</emphasis> file to 60 tell GCC which target dynamic linker will be used.</para></listitem> 58 <listitem><para>Careful manipulation of <userinput>gcc</userinput>'s 59 <emphasis>specs</emphasis> file to tell the compiler which target dynamic 60 linker will be used.</para></listitem> 61 61 </itemizedlist> 62 62 63 63 <para>Binutils is installed first because both GCC and Glibc perform various 64 64 feature tests on the assembler and linker during their respective runs of 65 < filename>./configure</filename> to determine which software features to enable65 <userinput>./configure</userinput> to determine which software features to enable 66 66 or disable. This is more important than one might first realize. An incorrectly 67 67 configured GCC or Glibc can result in a subtly broken toolchain where the impact 68 of such breakage might not show up until near the end of abuild of a whole68 of such breakage might not show up until near the end of the build of a whole 69 69 distribution. Thankfully, a test suite failure will usually alert us before too 70 much harm is done.</para>70 much time is wasted.</para> 71 71 72 72 <para>Binutils installs its assembler and linker into two locations, 73 73 <filename class="directory">/tools/bin</filename> and 74 74 <filename class="directory">/tools/$TARGET_TRIPLET/bin</filename>. In reality, 75 the tools in one location are hard linked to the other. An important facet of ld 76 is its library search order. Detailed information can be obtained from ld by 77 passing it the <emphasis>--verbose</emphasis> flag. For example: 78 <userinput>`ld --verbose | grep SEARCH`</userinput> will show you the current 79 search paths and order. You can see what files are actually linked by ld by 80 compiling a dummy program and passing the --verbose switch. For example: 75 the tools in one location are hard linked to the other. An important facet of 76 the linker is its library search order. Detailed information can be obtained 77 from <userinput>ld</userinput> by passing it the <emphasis>--verbose</emphasis> 78 flag. For example: <userinput>`ld --verbose | grep SEARCH`</userinput> will 79 show you the current search paths and their order. You can see what files are 80 actually linked by <userinput>ld</userinput> by compiling a dummy program and 81 passing the <emphasis>--verbose</emphasis> switch. For example: 81 82 <userinput>`gcc dummy.c -Wl,--verbose 2>&1 | grep succeeded`</userinput> 82 83 will show you all the files successfully opened during the link.</para> 83 84 84 85 <para>The next package installed is GCC and during its run of 85 < filename>./configure</filename> you'll see, for example:</para>86 <userinput>./configure</userinput> you'll see, for example:</para> 86 87 87 88 <blockquote><screen>checking what assembler to use... /tools/i686-pc-linux-gnu/bin/as … … 90 91 <para>This is important for the reasons mentioned above. It also demonstrates 91 92 that GCC's configure script does not search the $PATH directories to find which 92 tools to use. However, during the actual operation of GCC itself, the same 93 search paths are not necessarily used. You can find out which standard linker 94 GCC will use by running: <userinput>`gcc -print-prog-name=ld`</userinput>. 95 Detailed information can be obtained from GCC by passing it the 96 <emphasis>-v</emphasis> flag while compiling a dummy program. For example: 97 <userinput>`gcc -v dummy.c`</userinput> will show you detailed information about 98 the preprocessor, compilation and assembly stages, including GCC's include 99 search paths and order.</para> 93 tools to use. However, during the actual operation of <userinput>gcc</userinput> 94 itself, the same search paths are not necessarily used. You can find out which 95 standard linker <userinput>gcc</userinput> will use by running: 96 <userinput>`gcc -print-prog-name=ld`</userinput>. 97 Detailed information can be obtained from <userinput>gcc</userinput> by passing 98 it the <emphasis>-v</emphasis> flag while compiling a dummy program. For 99 example: <userinput>`gcc -v dummy.c`</userinput> will show you detailed 100 information about the preprocessor, compilation and assembly stages, including 101 <userinput>gcc</userinput>'s include search paths and their order.</para> 100 102 101 103 <para>The next package installed is Glibc. The most important considerations for 102 104 building Glibc are the compiler, binary tools and kernel headers. The compiler 103 is generally no problem as it will always use the GCC found in a $PATH104 directory. The binary tools and kernel headers can be a little more troublesome. 105 Therefore we take no risks and we use the available configure switches to 106 enforce the correct selections. After the run of107 < filename>./configure</filename> you can check the contents of the105 is generally no problem as Glibc will always use the <userinput>gcc</userinput> 106 found in a $PATH directory. The binary tools and kernel headers can be a little 107 more troublesome. Therefore we take no risks and use the available configure 108 switches to enforce the correct selections. After the run of 109 <userinput>./configure</userinput> you can check the contents of the 108 110 <filename>config.make</filename> file in the 109 111 <filename class="directory">glibc-build</filename> directory for all the 110 112 important details. You'll note some interesting items like the use of 111 113 <userinput>CC="gcc -B/tools/bin/"</userinput> to control which binary tools are 112 used and also the use of the <emphasis>-nostdinc</emphasis> and113 <emphasis>-isystem</emphasis> flags to control the GCC include search path.114 These items help to highlight an important aspect of the Glibc package: it is 115 very self sufficient in terms of its build machinery and generally does not rely 116 on toolchain defaults.</para>114 used, and also the use of the <emphasis>-nostdinc</emphasis> and 115 <emphasis>-isystem</emphasis> flags to control the compiler's include search 116 path. These items help to highlight an important aspect of the Glibc package: 117 it is very self-sufficient in terms of its build machinery and generally does 118 not rely on toolchain defaults.</para> 117 119 118 120 <para>After the Glibc installation, we make some adjustments to ensure that 119 searching and linking take place only within our /tools prefix. We install an120 adjusted ld, which has a hard-wired search path limited to 121 <filename class="directory">/tools/lib</filename>. Then we amend GCC's specs 122 file to point to our new dynamic linker in 123 <filename class="directory">/tools/lib</filename>. This last step is121 searching and linking take place only within our <filename>/tools</filename> 122 prefix. We install an adjusted <userinput>ld</userinput>, which has a hard-wired 123 search path limited to <filename class="directory">/tools/lib</filename>. Then 124 we amend <userinput>gcc</userinput>'s specs file to point to our new dynamic 125 linker in <filename class="directory">/tools/lib</filename>. This last step is 124 126 <emphasis>vital</emphasis> to the whole process. As mentioned above, a 125 127 hard-wired path to a dynamic linker is embedded into every ELF shared 126 128 executable. You can inspect this by running: 127 129 <userinput>`readelf -l <name of binary> | grep interpreter`</userinput>. 128 By amending the GCC specs file, we are ensuring that every program compiled from129 here through the end of Chapter 5 will use our new dynamic linker in 130 <filename class="directory">/tools/lib</filename>.</para>130 By amending <userinput>gcc</userinput>'s specs file, we are ensuring that every 131 program compiled from here through the end of Chapter 5 will use our new 132 dynamic linker in <filename class="directory">/tools/lib</filename>.</para> 131 133 132 134 <para>The need to use the new dynamic linker is also the reason why we apply the 133 specs patch for the second pass of GCC. Failure to do so will result in the GCC134 programs themselves having the dynamic linker from the host system's135 Specs patch for the second pass of GCC. Failure to do so will result in the GCC 136 programs themselves having the name of the dynamic linker from the host system's 135 137 <filename class="directory">/lib</filename> directory embedded into them, which 136 would defeat our goal of getting away from the host system.</para>138 would defeat our goal of getting away from the host.</para> 137 139 138 140 <para>During the second pass of Binutils, we are able to utilize the 139 <userinput>--with-lib-path</userinput> configure switch to control ld's library 140 search path. From this point onwards, the core toolchain is self-contained and 141 self-hosted. The remainder of the Chapter 5 packages all build against the new 142 Glibc in <filename class="directory">/tools</filename> and all is well.</para> 141 <emphasis>--with-lib-path</emphasis> configure switch to control 142 <userinput>ld</userinput>'s library search path. From this point onwards, the 143 core toolchain is self-contained and self-hosted. The remainder of the 144 Chapter 5 packages all build against the new Glibc in 145 <filename class="directory">/tools</filename> and all is well.</para> 143 146 144 147 <para>Upon entering the chroot environment in Chapter 6, the first major package 145 we install is Glibc, due to its self 148 we install is Glibc, due to its self-sufficient nature that we mentioned above. 146 149 Once this Glibc is installed into <filename class="directory">/usr</filename>, 147 150 we perform a quick changeover of the toolchain defaults, then proceed for real … … 164 167 resulting in a rather bulky program. When a program is dynamically linked, what 165 168 is included is a reference to the dynamic linker, the name of the library, and 166 the name of the function, resulting in a much smaller executable. A third way is167 to use the programming interface of the dynamic linker. See the168 <emphasis>dlopen</emphasis> man page for more information. </para>169 the name of the function, resulting in a much smaller executable. (A third way 170 is to use the programming interface of the dynamic linker. See the 171 <emphasis>dlopen</emphasis> man page for more information.)</para> 169 172 170 173 <para>Dynamic linking is the default on Linux and has three major advantages
Note:
See TracChangeset
for help on using the changeset viewer.