<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../../general.ent">
  %general-entities;
]>

<sect1 id="ch-system-adjusting">
  <?dbhtml filename="adjusting.html"?>

  <title>Adjusting the Toolchain</title>

  <para os="a">Now we adjust GCC's specs so that they point to the new
  dynamic linker. A <command>perl</command> command accomplishes this:</para>

<screen os="c"><userinput>gcc -dumpspecs | \
perl -p -e 's@/tools/lib/ld@/lib/ld@g;' \
     -e 's@\*startfile_prefix_spec:\n@$_/usr/lib/ @g;' &gt; \
     $(dirname $(gcc --print-libgcc-file-name))/specs</userinput></screen>

  <para os="d">The <command>perl</command> command above makes 2
  modifications to GCC's specs: it removes <quote>/tools</quote> from the
  pathname to the dynamic linker, and adds <quote>/usr/lib/</quote> to the
  startfile_prefix_spec. It is a good idea to visually inspect the
  <filename>specs</filename> file, and compare with the output of
  <command>gcc -dumpspecs</command>, to verify that
  the intended changes were actually made.</para>

  <caution>

    <para os="f">It is imperative at this point to stop and ensure that
    the basic functions (compiling and linking) of the adjusted toolchain
    are working as expected. To do this, perform a sanity
    check:</para>

<screen os="g"><userinput>echo 'main(){}' &gt; dummy.c
gcc dummy.c
readelf -l a.out | grep ': /lib'</userinput></screen>

    <para os="h">If everything is working correctly, there should be no errors,
    and the output of the last command will be:</para>

<screen os="i"><computeroutput>[Requesting program interpreter: /lib/ld-linux.so.2]</computeroutput></screen>

    <para os="j">Note that <filename class="directory">/lib</filename> is now
    the prefix of our dynamic linker.</para>

    <para os="k">If the output does not appear as shown above or is not received
    at all, then something is seriously wrong. Investigate and retrace the
    steps to find out where the problem is and correct it. The most likely
    reason is that something went wrong with the specs file amendment
    above. Any issues will need to be resolved before continuing on with
    the process.</para>

    <para os="l">Once everything is working correctly, clean up the test
    files:</para>

<screen os="m"><userinput>rm -v dummy.c a.out</userinput></screen>

  </caution>

</sect1>
