Subject: Re: how to get ld working...
To: Theo Deraadt <deraadt@fsa.ca>
From: Alan Barrett <barrett@daisy.ee.und.ac.za>
List: current-users
Date: 04/03/1994 11:50:31
> If you have a problem with a library, deleting the __.SYMDEF file should
> solve the problem. 

Not quite.  Without the __.SYMDEF index, the linker does a single linear
search through the library, but libraries often contain circular
references, and the single linear search often does not pick up everything
that is needed.  You can work around this by searching each library
multiple times (add extra "-l<whatever>" flags to the link command line),
or by storing multiple copies of the objects in each library.  I append
the latest version of my fake ranlib script, which tries to be sensible
about deciding which objects need to appear multiple times in the library. 

--apb (Alan Barrett)

#!/bin/sh
# Fake ranlib script, intended to emulate enough of ranlib's
# functionality to allow NetBSD-current-940330 to be built.
# Written by A. P. Barrett and placed in the public domain, April 1994. 

# do nothing if "-t" option is given
case "$1" in
-*) exit 0 ;;
esac

# otherwise, copy archive to a temp directory and work there
ARFILE="$1"
ARFILEBASE=`basename $ARFILE`
RANLIBTMPDIR=/tmp/ranlib.$$
mkdir $RANLIBTMPDIR
cp $ARFILE $RANLIBTMPDIR

(
    cd $RANLIBTMPDIR
    # delete the __.SYMDEF component
    ar r $ARFILEBASE __.SYMDEF
    # extract copies of all the other components
    ar x $ARFILEBASE
    # instead of indexing the archive, we append extra copies of some
    # of the components.  if tsort reports no cycles, then no extra
    # copies are needed.  if there are cycles, the number of
    # necessary extra copies is difficult to determine, but we just
    # blindly add as many copies as tsort reports.  if that is too many,
    # the only harm done is in wasted disk space.  if it is too few,
    # then run this fake ranlib again to append even more copies.
    TSORTOUT=tsortout.$$
    TSORTERR=tsorterr.$$
    lorder *.*o | tsort >$TSORTOUT 2>$TSORTERR
    CYCLEMEMBERS=`sed -ne '/^tsort: .*\..*o$/s/^tsort: //p' <$TSORTERR`
    ar q $ARFILEBASE $CYCLEMEMBERS
)

# copy the munged archive back to where it belongs
cp $RANLIBTMPDIR/$ARFILEBASE $ARFILE

# delete the temp dir
rm -rf $RANLIBTMPDIR

------------------------------------------------------------------------------