[bc82645e] | 1 | <sect1 id="ch05-locking-glibc">
|
---|
| 2 | <title>"Locking in" Glibc</title>
|
---|
| 3 | <?dbhtml filename="lockingglibc.html" dir="chapter05"?>
|
---|
| 4 |
|
---|
[1f30432] | 5 | <para>Now that the temporary C libraries have been installed, we want all
|
---|
| 6 | the tools compiled in the rest of this chapter to be linked against these
|
---|
[d1391f0] | 7 | libraries. To accomplish this, we need to adjust the linker and the compiler's
|
---|
| 8 | specs file.</para>
|
---|
[bc82645e] | 9 |
|
---|
[d1391f0] | 10 | <para>First install the adjusted linker by running the following from within
|
---|
| 11 | the <filename class="directory">binutils-build</filename> directory:</para>
|
---|
[2cff2cc] | 12 |
|
---|
[21ba4e3] | 13 | <screen><userinput>make -C ld install</userinput></screen>
|
---|
[bc82645e] | 14 |
|
---|
[d1391f0] | 15 | <para>The linker was adjusted a little while back, at the end of the first
|
---|
| 16 | pass of Binutils. From this point onwards everything will link <emphasis>only
|
---|
| 17 | </emphasis> against the libraries in <filename>/tools/lib</filename>.</para>
|
---|
[78deb7d] | 18 |
|
---|
[d1391f0] | 19 | <para>Now that the adjusted linker is installed, you have to remove the
|
---|
| 20 | Binutils build and source directories.</para>
|
---|
[66e4325] | 21 |
|
---|
[c9398bc] | 22 | <para>The next thing to do is to amend our GCC specs file so that it points
|
---|
[66e4325] | 23 | to the new dynamic linker. A simple sed will accomplish this:</para>
|
---|
| 24 |
|
---|
[21ba4e3] | 25 | <screen><userinput>SPECFILE=/tools/lib/gcc-lib/*/*/specs
|
---|
[f57e3d1] | 26 | sed -e 's@/lib/ld-linux.so.2@/tools/lib/ld-linux.so.2@g' \
|
---|
[1f30432] | 27 | $SPECFILE > tempspecfile
|
---|
| 28 | mv tempspecfile $SPECFILE
|
---|
[21ba4e3] | 29 | unset SPECFILE</userinput></screen>
|
---|
[bc82645e] | 30 |
|
---|
[f57e3d1] | 31 | <para>We recommend that you cut-and-paste the above rather than try and type it
|
---|
| 32 | all in. Or you can edit the specs file by hand if you want to: just replace any
|
---|
| 33 | occurrence of "/lib/ld-linux.so.2" with "/tools/lib/ld-linux.so.2".</para>
|
---|
| 34 |
|
---|
| 35 | <important><para>If you are working on a platform where the name of the dynamic
|
---|
| 36 | linker is something other than <filename>ld-linux.so.2</filename>, you
|
---|
| 37 | <emphasis>must</emphasis> substitute <filename>ld-linux.so.2</filename> with the
|
---|
[cd40510a] | 38 | name of your platform's dynamic linker in the above commands. Refer back to
|
---|
| 39 | <xref linkend="ch05-toolchaintechnotes"/> if necessary.</para></important>
|
---|
[66e4325] | 40 |
|
---|
[be2dd91] | 41 | <para>Lastly, there is a possibility that some include files from the host
|
---|
[1e163254] | 42 | system have found their way into GCC's private include dir. This can happen
|
---|
[fa2e693] | 43 | because of GCC's "fixincludes" process which runs as part of the GCC build.
|
---|
| 44 | We'll explain more about this further on in this chapter. For now, run the
|
---|
[783c041] | 45 | following commands to eliminate this possibility:</para>
|
---|
[be2dd91] | 46 |
|
---|
[21ba4e3] | 47 | <screen><userinput>rm -f /tools/lib/gcc-lib/*/*/include/{pthread.h,bits/sigthread.h}</userinput></screen>
|
---|
[40b88c2] | 48 |
|
---|
[783c041] | 49 | <caution><para>It is imperative at this point to stop and ensure that the basic
|
---|
| 50 | functions (compiling and linking) of the new toolchain are working as expected.
|
---|
| 51 | For this we are going to perform a simple sanity check:</para>
|
---|
[1f53626] | 52 |
|
---|
[21ba4e3] | 53 | <screen><userinput>echo 'main(){}' > dummy.c
|
---|
[1f53626] | 54 | gcc dummy.c
|
---|
[21ba4e3] | 55 | readelf -l a.out | grep ': /tools'</userinput></screen>
|
---|
[1f53626] | 56 |
|
---|
[783c041] | 57 | <para>If everything is working correctly, there should be no errors, and the
|
---|
| 58 | output of the last command will be:</para>
|
---|
[1f53626] | 59 |
|
---|
[7e602eab] | 60 | <blockquote><screen>[Requesting program interpreter: /tools/lib/ld-linux.so.2]</screen></blockquote>
|
---|
[1f53626] | 61 |
|
---|
[6267e8e] | 62 | <para>If you did not receive the output as shown above, or received no output at
|
---|
| 63 | all, then something is seriously wrong. You will need to investigate and retrace
|
---|
| 64 | your steps to find out where the problem is and correct it. There is no point in
|
---|
| 65 | continuing until this is done. Most likely something went wrong with the specs
|
---|
| 66 | file amendment above. Note especially that <filename>/tools/lib</filename>
|
---|
| 67 | appears as the prefix of our dynamic linker. Of course, if you are working on a
|
---|
[1f53626] | 68 | platform where the name of the dynamic linker is something other than
|
---|
[6267e8e] | 69 | <filename>ld-linux.so.2</filename>, then the output will be slightly
|
---|
| 70 | different.</para>
|
---|
[1f53626] | 71 |
|
---|
| 72 | <para>Once you are satisfied that all is well, clean up the test files:</para>
|
---|
| 73 |
|
---|
[21ba4e3] | 74 | <screen><userinput>rm dummy.c a.out</userinput></screen>
|
---|
[1f53626] | 75 | </caution>
|
---|
| 76 |
|
---|
[783c041] | 77 | <para>This completes the installation of the self-contained toolchain, and it
|
---|
[66e4325] | 78 | can now be used to build the rest of the temporary tools.</para>
|
---|
| 79 |
|
---|
[bc82645e] | 80 | </sect1>
|
---|
| 81 |
|
---|