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

Jouko Orava joorava at
Thu Jun 5 01:03:19 PDT 2003

On Wed, 4 Jun 2003, Zack Winkles wrote:
> Edwin van Vliet (cheatah at 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.
> 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:

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:

  -  %{!dynamic-linker:-dynamic-linker /lib/}}
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/}}
  -  %{!dynamic-linker:-dynamic-linker /lib/}}
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/}}

  -  %{!dynamic-linker:-dynamic-linker /lib/elf/} \
     %{!rpath:-rpath /lib/elf/} %{static:-static}}}"
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/elf/} \
     %{!rpath:-rpath /stage1/lib/elf/} %{static:-static}}}"
  -  %{!dynamic-linker:-dynamic-linker /lib/}} \
  +  %{!dynamic-linker:-dynamic-linker /stage1/lib/}} \

  -  %{!rpath:-rpath /lib/elf/}} %{static:-static}}}"
  +  %{!rpath:-rpath /stage1/lib/elf/}} %{static:-static}}}"

I wonder why generic i386 GNU was omitted from the

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

while [ $# -gt 0 ]; do
  if [ -f "$1" ]; then
    if echo "$1" | grep -q '\.lfs-orig$' ; then
      echo "$1: Skipped"
      if [ -f "$1.lfs-orig" ]; then
        rm -f "$1"
        mv -f "$1" "$1.lfs-orig"
      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"
        echo "$1: Modified; original is $1.lfs-orig"
  shift 1

Example: 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,

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

More information about the lfs-dev mailing list