Ch5: "Locking in" glibc, Ch6: Adjusting toolchain

Jouko Orava joorava at pcu.helsinki.fi
Thu Jun 5 01:03:19 PDT 2003


On Wed, 4 Jun 2003, Zack Winkles wrote:
> Edwin van Vliet (cheatah at tweakers.net) wrote:
> > But this does not solve the problem of the specs-4 patch containing more
> > patterns than just the /lib directory. Nonetheless, those commands can be
> > shorter than they are now.
>
> IMHO the patch is gonna be pretty hard to replicate outside of grep'ing
> all occurances of ld*.so.1 and ld-linux*.so.[12] into a var, then somehow
> cleansing that list of stuff we don't want to modify. Take a look at some
> of the extreme strangeness in linker names. It's nasty. It wouldn't be
> such a big deal covering all of them is two of the weird ones were going
> to end up being so common-place.
>
> ld.so.1, ld-linux.so.2, ld-linux.so.1, ld-linux-x86-64.so.2,
> ld-linux-ia64.so.2.... ugh.

I'm guessing we can ignore the *bsd dynamic linkers? Or not?
There are three of these beasts, and they live in /usr/libexec:
  /usr/libexec/ld-elf.so.1
  /usr/libexec/ld.elf_so
  /usr/libexec/ld.so

As for the rest, this sed seems to do the trick:

sed -e '/LINKER/ s@\([ \t]\)"/lib\([/6e]\)@\1"/stage1/lib\2 at g' \
    -e '/-dynamic-linker/ s@\([ \t]\)/lib\([/6e]\)@\1/stage1/lib\2 at g' \
    -e '/-rpath/ s@\([ \t]\)/lib\([/6e]\)@\1/stage1/lib\2 at g' \
    saved-file > file

This can be applied to spec (as in /stage1/lib/gcc-lib/*/*/specs)
or gcc config header file.
Applied to all of gcc-3.2.3/gcc/config/*/*.h this provides the same
changes as the gcc-3.2.3-specs-4.patch, plus the following:

  gcc-3.2.3/gcc/config/i386/gnu.h:
  -  %{!dynamic-linker:-dynamic-linker /lib/ld.so}}
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/ld.so}}
  -  %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}}
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/ld-linux.so.1}}

  gcc-3.2.3/gcc/config/i386/linux.h
  -  %{!dynamic-linker:-dynamic-linker /lib/elf/ld-linux.so.1} \
     %{!rpath:-rpath /lib/elf/} %{static:-static}}}"
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/elf/ld-linux.so.1} \
     %{!rpath:-rpath /stage1/lib/elf/} %{static:-static}}}"
  -  %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/ld-linux.so.1}} \

  gcc-3.2.3/gcc/config/sparc/linux.h
  -  %{!rpath:-rpath /lib/elf/}} %{static:-static}}}"
  +  %{!rpath:-rpath /stage1/lib/elf/}} %{static:-static}}}"

I wonder why generic i386 GNU was omitted from the
gcc-3.2.3-specs-4.patch?

I'm not sure, but to me it seems a good idea to edit the
runpath (-rpath) also (the above changes).
The gcc-3.2.3-specs-4.patch does the exact same thing,
but only for m68k/linux.h .

To apply the sed there is no need to fool around with
lists. You can do this safely with quite a small bash
script; feed it all possible file names. I use something like

-->8--
#!/bin/bash
while [ $# -gt 0 ]; do
  if [ -f "$1" ]; then
    if echo "$1" | grep -q '\.lfs-orig$' ; then
      echo "$1: Skipped"
    else
      if [ -f "$1.lfs-orig" ]; then
        rm -f "$1"
      else
        mv -f "$1" "$1.lfs-orig"
      fi
      sed -e '/LINKER/ s@\([ \t]\)"/lib\([/6e]\)@\1"/stage1/lib\2 at g' \
        -e 's@\(dynamic-linker[ \t][ \t]*\)\(/lib[/6e}]\)@\1/stage1\2 at g' \
        -e 's@\(rpath[ \t][ \t]*\)\(/lib[/6e}]\)@\1/stage1\2 at g' \
          "$1.lfs-orig" > "$1"
      if cmp -s "$1" "$1.lfs-orig" ; then
        echo "$1: Unchanged"
        mv -f "$1.lfs-orig" "$1"
      else
        echo "$1: Modified; original is $1.lfs-orig"
      fi
    fi
  fi
  shift 1
done
-->8--

Example:
  above.sh gcc-3.2.3/gcc/config/*/*.h

The script skips all files ending with .lfs-orig
as I, for one, often do   config/*  config/*/*
On the first run, the file is moved to "file.lfs-orig".
The "file" is removed prior to sed to avoid sym/hardlinks.
Sed reads "file.lfs-orig" and pipes output to "file".
If files are identical, "file.lfs-orig" is moved
back over "file". Since they are on the same fs,
move works with hard links only; timestamp and
original contents are kept unchanged. (Except atime?)

It's still dog slow, but quite safe.

To remove /stage1 from the spec file, I suggest using
  sed -e 's@\(dynamic-linker[ \t][ \t]*\)/stage1/lib@\1/lib at g' \
      -e 's@\(rpath[ \t][ \t]*\)/stage1/lib@\1/lib at g' ...

Oh, and if you try above, remember to remove
the *.lfs-orig files from the tree first.

I'd better get some sleep now,
  Jouko

-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-dev' in the subject header of the message



More information about the lfs-dev mailing list