Subject: Re: DynLink'd gzip(1) for CF Bootstrap
To: matthew sporleder <msporleder@gmail.com>
From: Brian A. Seklecki <lavalamp@spiritual-machines.org>
List: netbsd-users
Date: 06/18/2006 11:46:08
The solution to the problem:

Progress bar and optional gzip compression could be added with specially
compiling versions of pax(1)/tar(1)/gzip(1) that do are:
        
      * Not statically linked
        
      * Are dynamically linked against /lib instead of /usr/lib
        
      * Do not depend additional superfluous libraries such as libbz2
        
      * A work-around to compile progress(1) correctly:
        
        By default, progress is linked against the libc.so.12 in
        /usr/lib, which is actually a symlink to the real libc.so file
        in /lib:
        
        # ldd /usr/bin/progress
        
        /usr/bin/progress:
        
        -lc.12 => /usr/lib/libc.so.12
        
        # ls -al /usr/lib/libc.so.12
        
        lrwxr-xr-x 1 root wheel 21 Dec 18 19:15 /usr/lib/libc.so.12@ ->
        /lib/libc.so.12.128.2
        
        

To trick it into compiling against /lib, two variables must be set in
src/usr.bin/progress/Makefile and src/usr.bin/gzip/Makefile which push
knobs in src/share/mk/bsd.prog.mk and src/share/mk/bsd.own.mk:

SHLINKDIR= /libexec

SHLIBDIR= /lib


As well in src/lib/libbz2/Makefile:

USE_SHLIBDIR= yes

SHLINKDIR= /libexec

SHLIBDIR= /lib


Thanks to Bill Moran with for the help teething through the Makefiles to
track

down where the extra ld(1) â~@~\-Râ~@~] flags were coming from.

root@thunderwing:/home/nbsd/src/lib/libbz2# make install
#   install  /usr/lib/libbz2.a
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -c  -r -o root -g
wheel -m 444  -a "/home/nbsd/tools//bin/i386--netbsdelf-ranlib -t" 
libbz2.a /usr/lib/libbz2.a
#   install  /usr/lib/libbz2_p.a
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -c  -r -o root -g
wheel -m 444  -a "/home/nbsd/tools//bin/i386--netbsdelf-ranlib -t" 
libbz2_p.a /usr/lib/libbz2_p.a
#   install  /usr/lib/libbz2_pic.a
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -c  -r -o root -g
wheel -m 444  -a "/home/nbsd/tools//bin/i386--netbsdelf-ranlib -t" 
libbz2_pic.a /usr/lib/libbz2_pic.a
#   install  /lib/libbz2.so.1.0
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -c  -r -o root -g
wheel -m 444   libbz2.so.1.0 /lib/libbz2.so.1.0
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -l s -r  
/lib/libbz2.so.1.0  /usr/lib/libbz2.so.1.0
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -l s -r  
libbz2.so.1.0  /lib/libbz2.so.1
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -l s -r  
/lib/libbz2.so.1.0  /usr/lib/libbz2.so.1
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -l s -r  
libbz2.so.1.0  /lib/libbz2.so
STRIP=/home/nbsd/tools//bin/i386--netbsdelf-strip
/home/nbsd/tools//bin/nbinstall  -N /home/nbsd/src/etc -l s -r  
/lib/libbz2.so.1.0  /usr/lib/libbz2.so


# ldd /usr/bin/gzip
/usr/bin/gzip:
        -lz.0 => /usr/lib/libz.so.0
        -lbz2.1 => /usr/lib/libbz2.so.1
        -lc.12 => /usr/lib/libc.so.12


# ldd /usr/bin/gzip
/usr/bin/gzip:
        -lz.0 => /lib/libz.so.0
        -lbz2.1 => /lib/libbz2.so.1
        -lc.12 => /lib/libc.so.12

The binary install location stays the same, manual cp(1) is needed, but
the linking to the resolved symlinks solves the /usr unavailability
issue.

~~BAS



On Wed, 2006-05-10 at 12:50, matthew sporleder wrote:
> >
> > I'm looking to make a 'rescue' gzip(1) binary for a CF Bootstrap, however
> > /rescue/gzip is staticly linked and thus 2+MB.
> >
> > Space is limited for binaries in /bin and /lib because of size limitations
> > of the in-kernel RD/MD image.
> >
> > Space is limited on the CF device for usr.tar.gz (which gets extracted
> > into an MFS /usr), so /rescue/gzip is out of the question.
> >
> > Thus my RD/MD root file system lacks a /usr until after the start of
> > /etc/rc.
> >
> > With our in-tree gzip(1) substitute, could the Makefile be modified to
> > link against the libc/libz in /lib instead of /usr/lib (which are actually
> > symlinks any way?).
> >
> > It seems pretty simple:
> >
> > # link gzip/gzip
> > /nbsd/tools/bin/i386--netbsdelf-gcc -Wl,-nostdlib -o gzip
> > -Wl,-rpath-link,/lib:/usr/lib -L/lib -B/usr/lib/ -B/usr/lib/ gzip.o -lz
> > -lbz2 -L/usr/lib -L/usr/lib
> >
> > But it would nice if there was some conditional environmental that could
> > be set for this non-standard build behavior.
> >
> > Also, could a the bzip2 support be killed off easily?  That might not be
> > prodent since it doesn't really add that much space (60K?).
> >
> 
> I'm pretty sure everything in /rescue is exactly the same size,
> because it's all the same binary + hard links.