source: chapter06/readjusting.xml@ 0e5c784

Last change on this file since 0e5c784 was 2914987b, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

Adjust chapter 5 binutils to build a static ld-new for use in the chapter 6 readjusting section.
Also add some extended sanity checks. These fixes are adapted from DIY-Linux and Greg Schafer.
Thanks to Dan Nicholson for the report, as well.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@7308 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 5.1 KB
Line 
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
10<para>Now that the final C libraries have been installed, it is time to adjust
11the toolchain again. The toolchain will be adjusted so that it will link any
12newly compiled program against these new libraries. This is a similar process
13used in the <quote>Adjusting</quote> phase in the beginning of <xref
14linkend="chapter-temporary-tools"/>, but with the adjustments reversed. In <xref
15linkend="chapter-temporary-tools"/>, the chain was guided from the host's
16<filename class="directory">/{,usr/}lib</filename> directories to the new
17<filename class="directory">/tools/lib</filename> directory. Now, the chain will
18be guided from that same <filename class="directory">/tools/lib</filename>
19directory to the LFS <filename class="directory">/{,usr/}lib</filename>
20directories.</para>
21
22<para>First, create a symlink to the adjusted linker we created in chapter 5.</para>
23
24<screen><userinput>ln -sv /tools/bin/ld-new /usr/bin/ld</userinput></screen>
25
26<para>Next, amend the GCC specs file so that it points to the new
27dynamic linker. A <command>sed</command> command accomplishes this:</para>
28
29<screen><userinput>SPECFILE=`dirname $(gcc -print-libgcc-file-name)`/specs &amp;&amp;
30gcc -dumpspecs > $SPECFILE &amp;&amp;
31sed -i -e '/^\*link:$/{n;s,$, -L/usr/lib,}' \
32 -e 's@^/tools/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' $SPECFILE &amp;&amp;
33unset SPECFILE</userinput></screen>
34
35<para>It is a good idea to visually inspect the specs file to verify the intended
36change was actually made.</para>
37
38<important><para>If working on a platform where the name of the
39dynamic linker is something other than
40<filename class="libraryfile">ld-linux.so.2</filename>, substitute
41<quote>ld-linux.so.2</quote> with the name of the platform's
42dynamic linker in the above commands. Refer back to <xref
43linkend="ch-tools-toolchaintechnotes" role=","/> if
44necessary.</para></important>
45
46<para>Now create a temporary wrapper script for <filename>gcc</filename>.
47This script will point to the real <filename>gcc</filename>
48in <filename class="directory">/tools</filename> but with adjusted parameters
49to ensure that GCC in the next section links to our newly installed Glibc.</para>
50
51<screen><userinput>cat &gt; /usr/bin/gcc &lt;&lt; "EOF"
52#!/bin/bash
53/tools/bin/gcc -B/usr/lib/ -B/usr/bin/ $@
54EOF
55chmod 755 /usr/bin/gcc
56ln -s gcc /usr/bin/cc</userinput></screen>
57
58<caution><para>It is imperative at this point to stop and ensure that
59the basic functions (compiling and linking) of the adjusted toolchain
60are working as expected. To do this, perform a sanity
61check:</para>
62
63<screen><userinput>echo 'main(){}' &gt; dummy.c
64cc dummy.c -Wl,--verbose &amp;&gt; dummy.log
65readelf -l a.out | grep ': /lib'</userinput></screen>
66
67<para>If everything is working correctly, there should be no errors,
68and the output of the last command will be (allowing for
69platform-specific differences in dynamic linker name):</para>
70
71<screen><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>
72
73<para>Note that <filename class="directory">/lib</filename> is now
74the prefix of our dynamic linker.</para>
75
76<para>Now make sure that we're setup to use the correct start files:</para>
77
78<screen><userinput>grep "/usr/lib/crt.* " dummy.log</userinput></screen>
79
80<para>If everything is working correctly, there should be no errors,
81and the output of the last command will be:</para>
82
83<screen><computeroutput>attempt to open /usr/lib/crt1.o succeeded
84attempt to open /usr/lib/crti.o succeeded
85attempt to open /usr/lib/crtn.o succeeded</computeroutput></screen>
86
87<para>Next make sure that we're using the correct libc:</para>
88
89<screen><userinput>grep "/lib/libc.so.6 " dummy.log</userinput></screen>
90
91<para>If everything is working correctly, there should be no errors,
92and the output of the last command will be:</para>
93
94<screen><computeroutput>attempt to open /lib/libc.so.6 succeeded</computeroutput></screen>
95
96<para>Lastly, make sure GCC is using the correct dynamic linker:</para>
97
98<screen><userinput>grep found dummy.log</userinput></screen>
99
100<para>If everything is working correctly, there should be no errors,
101and the output of the last command will be (allowing for
102platform-specific differences in dynamic linker name):</para>
103
104<screen><computeroutput>found ld-linux.so.2 at /lib/ld-linux.so.2</computeroutput></screen>
105
106<para>If the output does not appear as shown above or is not received
107at all, then something is seriously wrong. Investigate and retrace the
108steps to find out where the problem is and correct it. The most likely
109reason is that something went wrong with the specs file amendment
110above. Any issues will need to be resolved before continuing on with
111the process.</para>
112
113<para>Once everything is working correctly, clean up the test
114files:</para>
115
116<screen><userinput>rm -v dummy.c a.out dummy.log</userinput></screen></caution>
117
118</sect1>
119
Note: See TracBrowser for help on using the repository browser.