[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

10029.0. "dynamic libraries & v4.0b" by NNTPD::"[email protected]" (Kim Roy) Tue Jun 03 1997 11:52

Hi there,

This is hopefully a quick question.  Does anyone know if dunix v4.0b has an
equivalent command to 'ldd' in solaris which allows you to see which dynamic
libraries will be loaded by an executable??

Thanks in advance.

/kim
[Posted by WWW Notes gateway]
T.RTitleUserPersonal
Name
DateLines
10029.1odump?MSKRAT::ANKANIdle words waste timeTue Jun 03 1997 11:571
odump -Dl <image-to-check>
10029.2ldd scriptDECC::SULLIVANJeff SullivanTue Jun 03 1997 12:38201
Here's a script I've been using for several years on several different versions
of UNIX. I'm not the author, but I don't think there is a copyright problem in
posting it here. Feel free to use it yourself.

(Note that you might need to fix some line wrapping before use)

-Jeff

#!/bin/sh
#-------------------------------------------------------------------------------
#
# Script to produce consistent dynamic dependency information across platforms.
#
# Syntax: ldd <exe> ...
#
#-------------------------------------------------------------------------------
#
# To use the general code at the bottom of this script, you must define the
# following three functions:-
#
#    need <file>	- Returns the dynamic dependencies for the supplied
#			  file, one per line. If the dependency contains a "/"
#			  character then it will not be subject to a path
#			  search. A second word can be added to any line which
#			  supplies a default name to use if the search should
#			  fail.
#
#    conlib <file>	- Converts the supplied file name into a loader library
#			  reference (eg /lib/libc.a -> -lc) if it is of the
#			  correct form. Otherwise the original name will be
#			  returned.
#
#    search <file>	- Returns a colon separated search path for locating
#			  the dependencies of the supplied file.
# 
#-------------------------------------------------------------------------------
#
# Switch on machine type
#
case `uname` in
#
# Use ldd for SunOS4
#  - Loop over args as pipe suppresses output of filename
#
SunOS)	for file do
		   if [ $# -gt 1 ]; then echo "$file:"; fi
		   /bin/ldd "$file" |
		      sed -e 's/^	/     /' -e 's/ => /	=> /'
		done
		exit 0;;
#
# Define functions for HPUX 9
#
HP-UX)	need() {
		   chatr $1 2>/dev/null | awk ' \
		      BEGIN { exe = 0; got = 0; } \
		      $0 ~ /^[ 	]*shared executable[ 	]*/ { exe = 1; } \
		      $0 ~ /^[ 	]*demand load executable[ 	]*/ { exe = 1; }
\
		      /^[ 	]*shared library list:[ 	]*$/ { \
			 got = 1; \
			 next; \
		      } \
		      got != 0 { \
			 if (NF == 2 && ($1 == "static" || $1 == "dynamic")) { \
			    if (!exe || got != 1) { \
			       if ($1 == "static") print $2; \
			       else { \
				  for (i=length($2)-1;i>0;i--) \
				     if (substr($2,i,1) == "/") break; \
				  print substr($2,i+1),$2; \
			       } \
			    } \
			    got++; \
			 } \
			 else got = 0; \
		      }'
		}
		conlib() {
		   echo "$1" | sed -e 's/^lib\(.*\)\.sl$/-l\1/'
		}
		search() {
		   temp=`chatr $1 2>/dev/null | awk ' \
		      BEGIN { got = 0; first=0; shlib=""; embed=""; } \
		      /^[ 	]*shared library dynamic path search:[ 	]*$/ { \
			 got = 1; \
			 next; \
		      } \
		      got != 0 { \
			 if ($1 == "SHLIB_PATH" && $2 == "enabled") { \
			    shlib = "$SHLIB_PATH"; \
			    first = ($3 == "first"); \
			 } \
			 if ($1 == "embedded" && $2 == "path" && $3 == "enabled"
&& (NF != 6 || $5 != "Not" || $6 != "Defined")) { \
			    first = ($4 != "first"); \
			    embed = $5; \
			    for (i=6; i<=NF; i++) embed = embed " " $i; \
			 } \
			 if (got++ > 2) exit; \
		      } \
		      END { \
			 if (first) print shlib ":" embed; \
			 else print embed ":" shlib; \
		      }'`
		   eval echo "$temp"
		};;
#
# Define functions for Mips Irix 5
#
IRIX)	need() {
		   odump -D $1 2>/dev/null |
		      sed -n 's/^[ 	]*NEEDED:[ 	]*//p'
		}
		rpath() {
		   odump -D $1 2>/dev/null |
		      sed -n 's/^[ 	]*RPATH:[ 	]*//p'
		}
		conlib() {
		   echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \
				   -e 's/^lib\(.*\)\.so$/-l\1/'
		}
		search() {
		   echo "`rpath
$1`:$LD_LIBRARY_PATH:/lib:/usr/lib:/lib/cmplrs/cc:/usr/lib/cmplrs/cc"
		};;
#
# Define functions for Alpha OSF 1
#
OSF1)	need() {
		   odump -D $1 2>/dev/null |
		      sed -n 's/^[ 	]*NEEDED:[ 	]*//p'
		}
		rpath() {
		   odump -D $1 2>/dev/null |
		      sed -n 's/^[ 	]*RPATH:[ 	]*//p'
		}
		conlib() {
		   echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \
				   -e 's/^lib\(.*\)\.so$/-l\1/'
		}
		search() {
		   echo "`rpath
$1`:$LD_LIBRARY_PATH:/usr/shlib:/usr/ccs/lib:/usr/lib/cmplrs/cc:/usr/lib:/usr/lo
cal/lib"
		};;
#
# Define functions for Solaris 2
#
sparc_5)	need() {
		   dump -Lv $1 2>/dev/null |
		      sed -n 's/^\[[0-9]*\][ 	]*NEEDED[ 	]*//p'
		}
		rpath() {
		   dump -Lv $1 2>/dev/null |
		      sed -n 's/^\[[0-9]*\][ 	]*RPATH[ 	]*//p'
		}
		conlib() {
		   echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \
				   -e 's/^lib\(.*\)\.so$/-l\1/'
		}
		search() {
		   echo "$LD_LIBRARY_PATH:`rpath $1`:/usr/ccs/lib:/usr/lib"
		};;
#
# Unknown platforms
#
*)		echo "$0 Not supported on this platform"
		exit 1;;
esac
#
# Process files in turn
#
for file do
   deps="`need $file`"
   if [ -z "$deps" ]; then
      if [ ! -f $file ]; then echo "$file: No such file or directory"
      else echo "$file: Statically linked"; fi
      continue
   fi

   if [ $# -gt 1 ]; then echo "$file:"; fi
   scan=`search $file`

   echo "$deps" | while read name def; do
      case $name in
      */*)	echo "     $name";;
      *)	( IFS=":"
		  soname=""
		  for path in $scan; do
		     if [ -f "$path/$name" ]; then
		        soname="$path/$name"
		        break;
		     fi
		  done
		  if [ -z "$soname" -a -f "$def" ]; then soname=$def; fi
		  echo "     `conlib $name`	=> ${soname:-(not found)}"
		);;
      esac
   done
done
10029.3ldd is comingQUARRY::nethCraig NethTue Jun 03 1997 13:564
.1 is the right answer for V4.0b, although .2's script looks interesting.

FWIW, the 'steel' release of DIGITAL UNIX will include the ldd utility.