* Re: ldd command for Digital Unix
1998-10-09 4:00 ldd command for Digital Unix Pierre RUINET
@ 1998-10-09 4:00 ` Dirk Grunwald
1998-10-09 4:00 ` Mike Iglesias
1 sibling, 0 replies; 3+ messages in thread
From: Dirk Grunwald @ 1998-10-09 4:00 UTC (permalink / raw)
Here's a version of 'ldd' for DigitalUnix I picked up somewhere.
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1998-10-09 09:40 MDT by <grunwald@foobar.cs.colorado.edu>.
# Source directory was `/tmp_mnt/home/foobar/grunwald/Src'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 642 -rw-r--r-- ldd/README
# 366 -rw-r--r-- ldd/Makefile
# 3735 -rw-r--r-- ldd/ldd.c
# 1710 -rw-r--r-- ldd/ldd.1
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh23912; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= ldd/README ==============
if test ! -d 'ldd'; then
$echo 'x -' 'creating directory' 'ldd'
mkdir 'ldd'
fi
if test -f 'ldd/README' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'ldd/README' '(file already exists)'
else
$echo 'x -' extracting 'ldd/README' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'ldd/README' &&
README for ldd.
X
This is a version of ldd for Alpha's running DEC OSF/1. Its based on
the SUNOS one in functionality, although the sunos one is probably the
more polished of the two. ldd requies no special priviledges to run.
Installing is a case of 'make', followed by 'make install'.
X
Currently (2/2/94) ldd does not support all the environment variables
that loader(1) uses - these will be added as time permits, and if people
want them. See the man page for more details.
X
As with the rest of OSF/1 1.x, ldd knows about library versions, where
they exist, but doesnt know what to do with them
X
Anthony Baxter, <anthony.baxter@aaii.oz.au>
SHAR_EOF
$shar_touch -am 0202085994 'ldd/README' &&
chmod 0644 'ldd/README' ||
$echo 'restore of' 'ldd/README' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'ldd/README:' 'MD5 check failed'
d7f2450660babe609ca9907346689d77 ldd/README
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'ldd/README'`"
test 642 -eq "$shar_count" ||
$echo 'ldd/README:' 'original size' '642,' 'current size' "$shar_count!"
fi
fi
# ============= ldd/Makefile ==============
if test -f 'ldd/Makefile' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'ldd/Makefile' '(file already exists)'
else
$echo 'x -' extracting 'ldd/Makefile' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'ldd/Makefile' &&
BINDIR=/usr/local/bin
MANDIR=/usr/local/man
X
#CFLAGS=-g -DDEBUG
CFLAGS=-O2
X
X
all: ldd
X
ldd: ldd.o
X $(CC) $(CFLAGS) ldd.o -o ldd -lmld
X
ldd.o: ldd.c
X
install: ldd
X installbsd -m 511 -c ldd $(BINDIR)/ldd
X installbsd -m 444 -c ldd.1 $(MANDIR)/man1/ldd.1
X
clean:
X -rm -f core ldd.o ldd.tar
X
clobber: clean
X -rm -f ldd
X
tar:
X tar cf ldd.tar README Makefile ldd.c ldd.1
SHAR_EOF
$shar_touch -am 0202090094 'ldd/Makefile' &&
chmod 0644 'ldd/Makefile' ||
$echo 'restore of' 'ldd/Makefile' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'ldd/Makefile:' 'MD5 check failed'
64f7ded5a9e4f2934bddd6cda7b05c35 ldd/Makefile
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'ldd/Makefile'`"
test 366 -eq "$shar_count" ||
$echo 'ldd/Makefile:' 'original size' '366,' 'current size' "$shar_count!"
fi
fi
# ============= ldd/ldd.c ==============
if test -f 'ldd/ldd.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'ldd/ldd.c' '(file already exists)'
else
$echo 'x -' extracting 'ldd/ldd.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'ldd/ldd.c' &&
/*
X * ldd - list dynamic dependencies.
X *
X * Modelled after the SUNOS program of the same name.
X *
X * Anthony Baxter, <anthony@aaii.oz.au>
X *
X * Todo: Handle _RLD_ROOT, and _RLD_LIST arguments.
X * If program is setuid or setgid, then environment variables
X * should be ignored.
X * Handle some of the _RLD_ARGS options - only those that it
X * makes sense to handle.
X *
X * $Id: ldd.c,v 1.6 1994/02/02 14:28:31 root Exp root $
X */
X
#include <stdlib.h>
#include <a.out.h>
#include <stdio.h>
#include <filehdr.h>
#include <syms.h>
#include <ldfcn.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
X
#define DEFAULT_LD_PATH "/usr/shlib:/usr/ccs/lib:/usr/lib/cmplrs/cc:/usr/lib:/usr/local/lib"
X
char *env_rld_root, *env_rld_list, *env_ld_lib_path;
X
char *find_solib_from_name(char *);
void getenvvars(void);
X
main(int argc, char **argv) {
X LDFILE *tl;
X SCNHDR dysec,libsec;
X int i,j;
X Elf32_Lib *ed;
X char *dump;
X struct stat stbuf;
X
X if(argc<2) {
X fprintf(stderr,"Usage: %s file ...\n",argv[0]);
X }
X
X getenvvars();
X
X for(j=1; j<argc; j++) {
X i=stat(argv[j],&stbuf);
X if((i== -1) || !(S_ISREG(stbuf.st_mode))) {
X fprintf(stderr,"%s is not a regular, readable file, ignored\n",argv[j]);
X continue;
X }
X
X tl=ldopen(argv[j],(LDFILE *)NULL);
X
X if(!tl) {
X fprintf(stderr,"%s not an executable\n",argv[j]);
X continue;
X }
X
X i=ldnshread(tl,".dynstr",&dysec);
X if(i==FAILURE) {
X fprintf(stderr,"%s not dynamically linked\n",argv[j]);
X continue;
X }
#ifdef DEBUG
X printf(".dynstr is %d long\n",dysec.s_size);
#endif
X
X /* more than one file specified, print the name of each */
X if(argc>2)
X printf("%s:\n",argv[j]);
X
X dump = (char *)malloc(dysec.s_size);
X
X i=ldnshread(tl,".liblist",&libsec);
X if(i==FAILURE) {
X fprintf(stderr,"couldnt find liblist in %s, no dependencies?\n",argv[j]);
X continue;
X }
X
X
#ifdef DEBUG
X printf(".liblist has %d entries\n",libsec.s_size);
#endif
X ed = (Elf32_Lib *)malloc((sizeof(Elf32_Lib) * libsec.s_size));
X
X i=ldnsseek(tl,".liblist");
X if(i==FAILURE)
X fatal("ldnrseek failed\n");
X
X
X i=ldfread(ed,sizeof(Elf32_Lib),libsec.s_size,tl);
X if(i==FAILURE)
X fatal("ldfread failed\n");
X
X i=ldnsseek(tl,".dynstr");
X if(i==FAILURE)
X fatal("ldnrseek failed\n");
X
X i=ldfread(dump,1,dysec.s_size,tl);
X
X for(i=0;i<libsec.s_size;i++)
X {
X /* kludgey, but this seems to indicate no more shlibs */
X if(!ed[i].l_name || (ed[i].l_name>100000) || (ed[i].l_flags>3))
X break;
X printf("\t%s (%s) %s%s => %s\n",(dump + ed[i].l_name),
X (ed[i].l_version)?(dump + ed[i].l_version):"",
X (ed[i].l_flags&&LL_EXACT_MATCH)?"exact ":"",
X (ed[i].l_flags&&LL_IGNORE_INT_VER)?"ignore":"",
X find_solib_from_name(dump + ed[i].l_name) );
X }
X ldclose(tl);
X }
}
X
char *
find_solib_from_name(char *soname)
{
X char *ld_path;
X char *pt1,*pt2;
X char testpath[MAXPATHLEN];
X struct stat stbuf;
X int i;
X
X if(env_ld_lib_path)
X ld_path = strdup(env_ld_lib_path);
X else
X ld_path = strdup(DEFAULT_LD_PATH);
X
X pt1=ld_path;
X do {
X pt2=strchr(pt1,':');
X if(pt2)
X *pt2=0;
X sprintf(testpath,"%s/%s",pt1,soname);
#ifdef DEBUG
X printf("looking for %s...",testpath);
#endif
X i=stat(testpath,&stbuf);
X if(!i) {
X free(ld_path);
X return(testpath);
X }
X if(pt2)
X pt1=pt2+1;
X } while (pt2);
X free(ld_path);
X return "not found";
}
X
void
getenvvars()
{
X
X env_rld_root=getenv("_RLD_ROOT");
X env_rld_list=getenv("_RLD_LIST");
X env_ld_lib_path=getenv("LD_LIBRARY_PATH");
X
X /* My reading of the man page for loader says that if
X * LD_LIBRARY_PATH is set, _RLD_ROOT is ignored
X */
X if (env_ld_lib_path)
X env_rld_root=NULL;
}
SHAR_EOF
$shar_touch -am 0202072894 'ldd/ldd.c' &&
chmod 0644 'ldd/ldd.c' ||
$echo 'restore of' 'ldd/ldd.c' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'ldd/ldd.c:' 'MD5 check failed'
960640111aa6ffb4844bedf352dffdc8 ldd/ldd.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'ldd/ldd.c'`"
test 3735 -eq "$shar_count" ||
$echo 'ldd/ldd.c:' 'original size' '3735,' 'current size' "$shar_count!"
fi
fi
# ============= ldd/ldd.1 ==============
if test -f 'ldd/ldd.1' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'ldd/ldd.1' '(file already exists)'
else
$echo 'x -' extracting 'ldd/ldd.1' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'ldd/ldd.1' &&
X.\" This manpage source uses rsml coding.
X.so /usr/share/lib/tmac/sml
X.so /usr/share/lib/tmac/rsml
X.TH ldd 1 "" "" "" "local" ""
X.SH NAME
X.PP
\*Lldd\*O \- List dynamic dependencies.
X.SH SYNOPSIS
X.PP
X.sS
\*Lldd\*O
\*Vfile\*O
\&.\&.\&.
X.sE
X.PP
ldd attempts to list the dynamically loaded objects on which \*Vfile\*O depends.
X.PP
X.SH FLAGS
X.PP
None
X.SH DESCRIPTION
X.PP
X.iX "ldd command"
X.iX "list dynamic" "dependencies"
X.iX "shared" "libraries"
For each of the files given as arguments, ldd tries to expand the
dynamically loaded files that it needs to run, and resolve them to file names of
shared objects on the system. It searches for the shared objects using the
same algorithm as documented in the manual page for \*Lloader\*O(1) (but see
BUGS, below.)
X.RE
X.SH DIAGNOSTICS
X.PP
\*Lldd\*O can output the following error messages:
X.VL 4m
X.LI "\*Vfile\*O is not a regular, readable file, ignored"
\*Lldd\*O was unable to open the file.
X.LI "\*Ocouldnt ldopen \*Vfile\*O, not an executable?"
\*Lldd\*O does not think the file is an OSF/1 executable.
X.LI "\*Vfile\*O not dynamically linked"
\*Lldd\*O does not think the file is dynamically linked. Perhaps it is statically
linked?
X.LE
X.SH RELATED INFORMATION
X.PP
\*Lloader\*O(1), \*Lld\*O(1), \*Lldfcn\*O(4) (yeah, right, \*Lldfcn\*O(4) - how about
updating it, DEC?)
X.SH BUGS
X.PP
Probably. Its not been extensively leaned on. If you find a bug, let
me know, and I'll look at fixing it. Most of the assumptions were from
DEC's man pages, so there are probably erroneous ones in there.
X.PP
It could do with better error messages. It doesnt (yet) handle _RLD_ROOT
or _RLD_LIST environment variables.
X.SH AUTHOR
X.PP
Anthony Baxter, <anthony@aaii.oz.au>
X.PP
X
SHAR_EOF
$shar_touch -am 0202072694 'ldd/ldd.1' &&
chmod 0644 'ldd/ldd.1' ||
$echo 'restore of' 'ldd/ldd.1' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'ldd/ldd.1:' 'MD5 check failed'
594a13e1a40248c6a8a77bc9fc69ac66 ldd/ldd.1
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'ldd/ldd.1'`"
test 1710 -eq "$shar_count" ||
$echo 'ldd/ldd.1:' 'original size' '1710,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh23912
exit 0
--
Dirk Grunwald Assoc. Prof, Univ. of Colorado at Boulder
^ permalink raw reply [flat|nested] 3+ messages in thread