Monday, 12 July 2010

LAP - Toolchain, Part 3 - The Switch

The next stage in the procedure is to use the programs and libraries that we just installed to rebuild themselves to 100% guarantee that nothing from the host system has contaminated the installation.  We need to tell the software we have just installed to use itself now, and not anything on the host machine.  To achieve this we run the following commands:
SPECS=`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/specs
$LFS_TGT-gcc -dumpspecs | sed -e 's@/lib\(64\)\?/ld@/tools&@g' -e "/^\*cpp:$/{n;s,$, -isystem /tools/include,}" > $SPECS 
echo "New specs file is: $SPECS"
unset SPECS

I have literally no idea what a SPECS is, but I suspect it has nothing to do with lenses.  You can see in there some mention of 'tools' which is I guess what we are trying to achieve.  The 'echo' command produces this result:

New specs file is: /media/lfs/tools/bin/../lib/gcc/i686-lfs-linux-gnu/4.4.3/specs

Which sounds promising.  As suggested by the book I visually inspected that file.  It made my head hurt, and I could briefly only see in the colour magenta.  So I stopped looking at it.

It is strongly recommended that we try some tests before proceeding.  Well, OK if you insist.

echo 'main(){}' > dummy.c

This command just [echo]s the text in single quotes to the file dummy.c.  The .c extension indicates that the file contains 'C' source code.  Next we compile that code:

$LFS_TGT-gcc -B/tools/lib dummy.c

We know that the $LFS_TGT part of that resolves into i686-lfs-linux-gnu, and if you look in the /tools/bin directory you will find a file called i686-lfs-linux-gnu-gcc, so this command just executes that program.  The [-B] bit adds the following directory to the search path, which means that the gcc gets to use the Glibc libraries we installed.  I think.  So this command means compile the dummy.c program using the Glibc libraries.  The command produces a file called a.out.  We then search that command for references to the /tools directory to make sure it was used:

readelf -l a.out | grep ': /tools'

We should be told that:

[Requesting program interpreter: /tools/lib/]

Which is exactly what we want to see.  Lets get rid of the test files:

rm -v dummy.c a.out

And we now move on to rebuild the tools we just made, this time by using themselves.  It's a bit like the snake eating its tail, but in reverse.

No comments:

Post a Comment