source: chapter05/adjusting.xml@ 9109cd4

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 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
Last change on this file since 9109cd4 was 9109cd4, checked in by Zack Winkles <winkie@…>, 20 years ago

Use "gcc --print-file specs" to determine the location of the specs file

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

  • Property mode set to 100644
File size: 5.3 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
3 <!ENTITY % general-entities SYSTEM "../general.ent">
4 %general-entities;
5]>
6<sect1 id="ch-tools-adjusting">
7<title>Adjusting the toolchain</title>
8<?dbhtml filename="adjusting.html"?>
9
10<para>Now that the temporary C libraries have been installed, all
11the tools compiled in the rest of this chapter should be linked against these
12libraries. In order to accomplish this the linker, and the compiler's
13specs file, need to be adjsted.</para>
14
15<para> Some people would say that there is <emphasis><quote>black magic juju
16below this line</quote></emphasis>, but it is really very simple.</para>
17
18<para>First the adjusted linker is installed (adjusted at the end of the first pass
19of Binutils), by running the following command from within
20the <filename class="directory">binutils-build</filename> directory:</para>
21
22<screen><userinput>make -C ld install</userinput></screen>
23
24<para>From this point onwards everything will link <emphasis>only</emphasis>
25against the libraries in <filename class="directory">/tools/lib</filename>.</para>
26
27<note><para>If you missed the earlier warning to retain the Binutils
28source and build directories from the first pass, dont worry - all is not lost.
29Just ignore the above command. This results in a small chance of the subsequent
30testing programs linking against libraries on the host. This is not ideal, but
31it's not a major problem. The situation is corrected when the second pass of
32Binutils is installed later on.</para></note>
33
34<para>Now that the adjusted linker is installed, the Binutils build and source
35direcotries should be <emphasis>removed</emphasis>.</para>
36
37<para>The next task is to amend our GCC specs file so that it points
38to the new dynamic linker. A simple sed script will accomplish this:</para>
39
40<!-- Ampersands are needed to allow cut and paste -->
41
42<screen><userinput>SPECFILE=`gcc --print-file specs` &amp;&amp;
43sed -e 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \
44 $SPECFILE &gt; tempspecfile &amp;&amp;
45mv -f tempspecfile $SPECFILE &amp;&amp;
46unset SPECFILE</userinput></screen>
47
48<para>It is recommended that the above command be cut-and-pasted in order to ensure correctness - Alternatively the specs file can be edited by hand. This is done simply by replacing every occurrence of <quote>/lib/ld-linux.so.2</quote> with <quote>/tools/lib/ld-linux.so.2</quote>.</para>
49
50<para> Be sure to visually inspect the specs file in order to verify the intended changes have been mande.</para>
51
52<important><para>If you are working on a platform where the name of the dynamic
53linker is something other than <filename>ld-linux.so.2</filename>, you
54<emphasis>must</emphasis> replace <filename>ld-linux.so.2</filename> with the
55name of your platform's dynamic linker in the above commands. Refer back to
56<xref linkend="ch-tools-toolchaintechnotes"/> if necessary.</para></important>
57
58<para>Lastly, there is a possibility that some include files from the host
59system have found their way into GCC's private include dir. This can happen
60as a result of of GCC's <quote>fixincludes</quote> process which runs as part
61of the GCC build. We'll explain more about this further on in this chapter.
62Run the following commands to eliminate this possibility:</para>
63
64<screen><userinput>rm -f /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h}</userinput></screen>
65
66
67<caution><para>It is imperative at this point to stop and ensure that the basic
68functions (compiling and linking) of the new toolchain are working as expected.
69To perform a simple sanity check run the following commands:</para>
70
71<screen><userinput>echo 'main(){}' &gt; dummy.c
72cc dummy.c
73readelf -l a.out | grep ': /tools'</userinput></screen>
74
75<para>If everything is working correctly, there should be no errors, and the
76output of the last command will be of the form:</para>
77
78<blockquote><screen><computeroutput>[Requesting program interpreter: /tools/lib/ld-linux.so.2]</computeroutput></screen></blockquote>
79
80<para>Note especially that <filename class="directory">/tools/lib</filename>
81appears as the prefix of our dynamic linker.</para>
82
83<para>If the output is not
84as shown above, or there was no output at all, then something is seriously
85wrong. You will need to investigate and retrace your steps to find out where the
86problem is and correct it. There is no point in continuing until this is done.
87First, perform the sanity check again, using <command>gcc</command> instead of
88<command>cc</command>. If this works then the
89<filename class="symlink">/tools/bin/cc</filename> symlink is missing. Revisit
90<xref linkend="ch-tools-gcc-pass1"/> and install the symlink. Second, ensure your PATH
91is correct. You can check this by running <userinput>echo $PATH</userinput> and
92verifying that <filename class="directory">/tools/bin</filename> is at the head
93of the list. If the PATH is wrong it could mean you're not logged in as user
94<emphasis>lfs</emphasis> or something went wrong back in
95<xref linkend="ch-tools-settingenviron"/>. Third, something may have gone wrong with
96the specs file amendment above. In this case redo the specs file amendment
97being careful to cut-and-paste the commands.</para>
98
99<para>Once you are satisfied that all is well, clean up the test files:</para>
100
101<screen><userinput>rm dummy.c a.out</userinput></screen>
102</caution>
103
104
105</sect1>
Note: See TracBrowser for help on using the repository browser.