finding needed shared libraries for an application

Hi,
How to find the shared libraries for application …
should i use objdump -x | grep …
But i am not getting needed info by the above
Any hints
regards
Mani

The following output of objdump -p shows what libraries are “NEEDED” for the
binary “twodep-ecpp_g”.


D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>ls
CVS Makefile main.o twodep-ecpp_g

D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>objdump -p twodep-ecpp_g

twodep-ecpp_g: file format elf32-powerpc

Program Header:
PHDR off 0x00000034 vaddr 0x48040034 paddr 0x00000000 align 22
filesz 0x000000e0 memsz 0x000000e0 flags r-x
INTERP off 0x00000114 vaddr 0x48040114 paddr 0x00000000 align 2
0
filesz 0x00000014 memsz 0x00000014 flags r–
LOAD off 0x00000000 vaddr 0x48040000 paddr 0x48040000 align 212
filesz 0x000021fc memsz 0x000021fc flags r-x
LOAD off 0x00002200 vaddr 0x48043200 paddr 0x48043200 align 2
12
filesz 0x000000f9 memsz 0x00000284 flags rwx
DYNAMIC off 0x00002218 vaddr 0x48043218 paddr 0x00000000 align 22
filesz 0x000000a8 memsz 0x000000a8 flags rw-
NOTE off 0x000022fc vaddr 0x00000000 paddr 0x00000000 align 2
2
filesz 0x00000054 memsz 0x00000000 flags —

Dynamic Section:
NEEDED libtdep1-ecpp_g.so.1
NEEDED libtdep2-ecpp_g.so.1
NEEDED libecpp.so.2
NEEDED libm.so.2
NEEDED libc.so.2
INIT 0x4804216c
FINI 0x4804218c
HASH 0x48040130
STRTAB 0x48040690
SYMTAB 0x480402c0
STRSZ 0x564
SYMENT 0x10
DEBUG 0x0
PLTGOT 0x48043300
PLTRELSZ 0xf0
PLTREL 0x7
JMPREL 0x48040c00
RELA 0x48040bf4
RELASZ 0x108
RELAENT 0xc


D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>
“Manigandan.V” <scemani@yahoo.com> wrote in message
news:a3p8cf$3m1$1@inn.qnx.com

Hi,
How to find the shared libraries for application …
should i use objdump -x | grep …
But i am not getting needed info by the above
Any hints
regards
Mani

Hello,
use objdump --private-headers “executable”

Janusz.


“Allan” <apkleywegt@qnx.com> wrote in message
news:a3pdee$la9$1@nntp.qnx.com
The following output of objdump -p shows what libraries are “NEEDED” for the
binary “twodep-ecpp_g”.


D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>ls
CVS Makefile main.o twodep-ecpp_g

D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>objdump -p twodep-ecpp_g

twodep-ecpp_g: file format elf32-powerpc

Program Header:
PHDR off 0x00000034 vaddr 0x48040034 paddr 0x00000000 align 22
filesz 0x000000e0 memsz 0x000000e0 flags r-x
INTERP off 0x00000114 vaddr 0x48040114 paddr 0x00000000 align 2
0
filesz 0x00000014 memsz 0x00000014 flags r–
LOAD off 0x00000000 vaddr 0x48040000 paddr 0x48040000 align 212
filesz 0x000021fc memsz 0x000021fc flags r-x
LOAD off 0x00002200 vaddr 0x48043200 paddr 0x48043200 align 2
12
filesz 0x000000f9 memsz 0x00000284 flags rwx
DYNAMIC off 0x00002218 vaddr 0x48043218 paddr 0x00000000 align 22
filesz 0x000000a8 memsz 0x000000a8 flags rw-
NOTE off 0x000022fc vaddr 0x00000000 paddr 0x00000000 align 2
2
filesz 0x00000054 memsz 0x00000000 flags —

Dynamic Section:
NEEDED libtdep1-ecpp_g.so.1
NEEDED libtdep2-ecpp_g.so.1
NEEDED libecpp.so.2
NEEDED libm.so.2
NEEDED libc.so.2
INIT 0x4804216c
FINI 0x4804218c
HASH 0x48040130
STRTAB 0x48040690
SYMTAB 0x480402c0
STRSZ 0x564
SYMENT 0x10
DEBUG 0x0
PLTGOT 0x48043300
PLTRELSZ 0xf0
PLTREL 0x7
JMPREL 0x48040c00
RELA 0x48040bf4
RELASZ 0x108
RELAENT 0xc


D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>
“Manigandan.V” <scemani@yahoo.com> wrote in message
news:a3p8cf$3m1$1@inn.qnx.com

Hi,
How to find the shared libraries for application …
should i use objdump -x | grep …
But i am not getting needed info by the above
Any hints
regards
Mani

Heloo,
use objdump --private-headers “executable”


Janusz.


“Allan” <apkleywegt@qnx.com> wrote in message
news:a3pdee$la9$1@nntp.qnx.com
The following output of objdump -p shows what libraries are “NEEDED” for the
binary “twodep-ecpp_g”.


D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>ls
CVS Makefile main.o twodep-ecpp_g

D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>objdump -p twodep-ecpp_g

twodep-ecpp_g: file format elf32-powerpc

Program Header:
PHDR off 0x00000034 vaddr 0x48040034 paddr 0x00000000 align 22
filesz 0x000000e0 memsz 0x000000e0 flags r-x
INTERP off 0x00000114 vaddr 0x48040114 paddr 0x00000000 align 2
0
filesz 0x00000014 memsz 0x00000014 flags r–
LOAD off 0x00000000 vaddr 0x48040000 paddr 0x48040000 align 212
filesz 0x000021fc memsz 0x000021fc flags r-x
LOAD off 0x00002200 vaddr 0x48043200 paddr 0x48043200 align 2
12
filesz 0x000000f9 memsz 0x00000284 flags rwx
DYNAMIC off 0x00002218 vaddr 0x48043218 paddr 0x00000000 align 22
filesz 0x000000a8 memsz 0x000000a8 flags rw-
NOTE off 0x000022fc vaddr 0x00000000 paddr 0x00000000 align 2
2
filesz 0x00000054 memsz 0x00000000 flags —

Dynamic Section:
NEEDED libtdep1-ecpp_g.so.1
NEEDED libtdep2-ecpp_g.so.1
NEEDED libecpp.so.2
NEEDED libm.so.2
NEEDED libc.so.2
INIT 0x4804216c
FINI 0x4804218c
HASH 0x48040130
STRTAB 0x48040690
SYMTAB 0x480402c0
STRSZ 0x564
SYMENT 0x10
DEBUG 0x0
PLTGOT 0x48043300
PLTRELSZ 0xf0
PLTREL 0x7
JMPREL 0x48040c00
RELA 0x48040bf4
RELASZ 0x108
RELAENT 0xc


D:\cvs\tools\regress3\src\cpp\twodep\ppc\be.ecpp.g>
“Manigandan.V” <scemani@yahoo.com> wrote in message
news:a3p8cf$3m1$1@inn.qnx.com

Hi,
How to find the shared libraries for application …
should i use objdump -x | grep …
But i am not getting needed info by the above
Any hints
regards
Mani

How to find the shared libraries for application …

I guess this will be FAQ, so I made up the ldd command just now.
Similar thing used to be on staff.qnx.com/~cburgess/
but it’s now gone right?

Note that this ldd assumes the RPATH bug is fixed, so
it may get incorrect results on 6.1.0A.
(The script itself likely works on other ELF platforms too)

kabe

#!/bin/sh

shellscripted ldd

(requires objdump,awk)

for bin do
OBJDUMP=objdump -p $bin
LDLIBS=echo "$OBJDUMP" | awk '$1 == "NEEDED"{print $2 }'
LDPATH=echo "$OBJDUMP" | awk '$1 == "RPATH"{ print $2 }'
LDPATH="${LDPATH} /lib /usr/lib"

if [ -n “$LD_LIBRARY_PATH” ]; then
LDPATH=echo $LD_LIBRARY_PATH | tr : ' '"$LDPATH"
fi

if [ $# -gt 1 ]; then
echo ${bin}:
fi
for i in $LDLIBS; do
case $i in
/*)
if [ -x $i ]; then
echo “\011$i”
i=“found”
fi
;;
*)
for p in $LDPATH; do
if [ -x $p/$i ]; then
echo “\011$i =>\011$p/$i”
i=“found”
break
fi
done
;;
esac
if [ $i != “found” ]; then
echo “\011$i =>\011(file not found)”
fi
done
done

exit 0

output format of SunOS ldd:

#/bin/filename:

libx.so => (file not found)

libc.so.1 => /usr/lib/libc.so.1

/usr/platform/SUNW,Ultra-1/lib/libc_psr.so.1

Current homebrew “ldd” command by shellscript.

It doesn’t recurse into libraries for further dependencies,
so the output may be different from other OS’s ldd.

(this ldd may work on other GNU binutils environment too)

kabe

#!/bin/sh

shellscripted ldd

(requires objdump,awk)

#ifdef __USAGE
#%C - display dynamic library dependency of the binary

#%C [-v] a.out [a.out…]

-v Verbose

#endif

verbose=

get default lib search path

CS_LIBPATH=getconf CS_LIBPATH 2>/dev/null
if [ $? != 0 ]; then CS_LIBPATH="/lib:/usr/lib"; fi
CS_LIBPATH=echo $CS_LIBPATH | tr ':' ' '

for bin do
if [ x$bin = x-v ]; then verbose=$bin; continue; fi

if [ $# -gt 1 ]; then
echo ${bin}:
fi

LDLIBS=“libc.so.2”;RPATH="/embedded/rpath"

eval `objdump -p $bin | awk ’
$1 == “NEEDED” { needs=needs $2 " "}
$1 == “RPATH” { rpath=rpath $2 " "}
END {

strip things after malicious chars

#sub("`.*","",rpath)
if (p=match(needs,"[`<>();&$]")) needs=substr(needs,1,p-1);
if (p=match(rpath,"[`<>();&$]")) rpath=substr(rpath,1,p-1);
#gsub(":"," “,rpath)
while (p=match(needs,”:")) {
needs=substr(needs,1,p-1) " " substr(needs,p+1)
}
while (p=match(rpath,":")) {
rpath=substr(rpath,1,p-1) " " substr(rpath,p+1)
}
print “LDLIBS=”" needs “”;RPATH="" rpath “”"
}’`
LDPATH="${RPATH} ${CS_LIBPATH}"

if [ x$verbose = x-v ]; then echo RPATH: $RPATH; fi

if [ -n “$LD_LIBRARY_PATH” ]; then
LDPATH=echo ${LD_LIBRARY_PATH}: | tr : ' '"$LDPATH"
fi

if [ x$verbose = x-v ]; then echo Search Path: $LDPATH; fi

for i in $LDLIBS; do
case $i in
/*)
if [ -r $i ]; then
m="\011$i"
test ! -x $i && m=${m}"\011(not executable)"
echo “$m”
i=“found”
fi
;;
*)
for p in $LDPATH; do
if [ -r $p/$i ]; then
m="\011$i =>\011$p/$i"
test ! -x $p/$i && m=${m}"\011(not executable)"
echo “$m”
i=“found”
break
fi
done
;;
esac
if [ $i != “found” ]; then
echo “\011$i =>\011(file not found)”
fi
done
done

exit 0

output format of SunOS ldd:

#/bin/filename:

libx.so => (file not found)

libc.so.1 => /usr/lib/libc.so.1

/usr/platform/SUNW,Ultra-1/lib/libc_psr.so.1

current ldd.

Changes:
Emulate the bug which searches “.” when
no RPATH/LD_LIBRARY_PATH is defined


kabe

#!/bin/sh

shellscripted ldd

(requires objdump,awk)

does NOT recurse into dependencies

#ifdef __USAGE
#%C - display dynamic library dependency of the binary

#%C [-v] a.out [a.out…]

-v Verbose

#endif

verbose=

get default lib search path

CS_LIBPATH=getconf CS_LIBPATH 2>/dev/null
if [ $? != 0 ]; then CS_LIBPATH="/lib:/usr/lib"; fi
CS_LIBPATH=echo $CS_LIBPATH | tr ':' ' '

for bin do
if [ x$bin = x-v ]; then verbose=$bin; continue; fi

if [ $# -gt 1 ]; then
echo ${bin}:
fi

LDLIBS=“libc.so.2”;RPATH="/embedded/rpath"

eval `objdump -p – $bin | awk ’
$1 == “NEEDED” { needs=needs $2 " "}
$1 == “RPATH” { rpath=rpath $2 " "}
END {

strip things after malicious chars

#sub("`.*","",rpath)
if (p=match(needs,"[`<>();&$]")) needs=substr(needs,1,p-1);
if (p=match(rpath,"[`<>();&$]")) rpath=substr(rpath,1,p-1);
#gsub(":"," “,rpath)
while (p=match(needs,”:")) {
needs=substr(needs,1,p-1) " " substr(needs,p+1)
}
while (p=match(rpath,":")) {
rpath=substr(rpath,1,p-1) " " substr(rpath,p+1)
}
print “LDLIBS=”" needs “”;RPATH="" rpath “”"
}’`

if [ x$verbose = x-v ]; then echo RPATH: $RPATH; fi

if [ -n “$LD_LIBRARY_PATH” ]; then
LOCALPATH=echo $LD_LIBRARY_PATH | tr : ' '
fi

there is an OS bug which no RPATH && no L_L_P

causes “.” to be searched;

doing “RPATH:L_L_P :CS_LIBPATH” using colon?

if [ -z “$RPATH” -a -z “$LD_LIBRARY_PATH” ]; then
LOCALPATH="."
fi

LDPATH="${RPATH} ${LOCALPATH} ${CS_LIBPATH}"

if [ x$verbose = x-v ]; then echo Search Path: $LDPATH; fi

for i in $LDLIBS; do
case $i in
/*)
if [ -r $i ]; then
m="\011$i"
test ! -x $i && m=${m}"\011(not executable)"
echo “$m”
i=“found”
fi
;;
*)
for p in $LDPATH; do
if [ -r $p/$i ]; then
m="\011$i =>\011$p/$i"
test ! -x $p/$i && m=${m}"\011(not executable)"
echo “$m”
i=“found”
break
fi
done
;;
esac
if [ $i != “found” ]; then
echo “\011$i =>\011(file not found)”
fi
done
done

exit 0

output format of SunOS ldd:

#/bin/filename:

libx.so => (file not found)

libc.so.1 => /usr/lib/libc.so.1

/usr/platform/SUNW,Ultra-1/lib/libc_psr.so.1

Current ldd command by shellscript.

Changes:
Switch between 6.1.* and 6.2.* behavior.


kabe

#!/bin/sh

shellscripted ldd

(requires objdump,awk)

does NOT recurse into dependencies

#ifdef __USAGE
#%C - display dynamic library dependency of the ELF executable

#%C [-v] a.out [a.out…]

-v Verbose

#endif

verbose=

unset IFS

get default lib search path

CS_LIBPATH=getconf CS_LIBPATH 2>/dev/null
if [ $? != 0 ]; then CS_LIBPATH="/lib:/usr/lib"; fi

for bin do
if [ x$bin = x-v ]; then verbose=$bin; continue; fi

if [ $# -gt 1 ]; then
echo ${bin}:
fi

LDLIBS=“libc.so.2 libsocket.so”;RPATH="/embedded/rpath:/path2"

eval `objdump -p – $bin | awk ’
$1 == “NEEDED” { needs=needs $2 " "}
$1 == “RPATH” { rpath=rpath “:” $2}
END {

strip things after malicious chars

#sub("`.*","",rpath)
if (p=match(needs,"[`<>();&|$]")) needs=substr(needs,1,p-1);
if (p=match(rpath,"[`<>();&|$]")) rpath=substr(rpath,1,p-1);

strip first “:”

rpath=substr(rpath,2)

result

print “LDLIBS=”" needs “”;RPATH="" rpath “”"
}’`

if [ x$verbose = x-v ]; then echo RPATH: $RPATH; fi


IFS=:
set – $RPATH $LD_LIBRARY_PATH $CS_LIBPATH
case uname -r in
6.1.|6.0.)

6.1.0 won’t honor RPATH in the binary

will search “” (current dir) if LD_LIBRARY_PATH undefined

set – “$LD_LIBRARY_PATH” $CS_LIBPATH;;
6.2.*)

will search “” (current dir) if LD_LIBRARY_PATH undefined

set – $RPATH “$LD_LIBRARY_PATH” $CS_LIBPATH;;
esac
if [ x$verbose = x-v ]; then echo Search Path: “$*”; fi
unset IFS

for i in $LDLIBS; do
case $i in
/*)
if [ -r $i ]; then
m="\011$i"
test ! -x $i && m=${m}"\011(not executable)"
i=“found”
fi
;;
*)
for p do
test “$p” = “” && p="."
if [ -r $p/$i ]; then
m="\011$i =>\011$p/$i"
test ! -x $p/$i && m=${m}"\011(not executable)"
i=“found”
break
fi
done
;;
esac
test “$i” != “found” && m="\011$i =>\011(file not found)"
echo “$m”
done
done

exit 0

output format of SunOS ldd:

#/bin/filename:

libx.so => (file not found)

libc.so.1 => /usr/lib/libc.so.1

/usr/platform/SUNW,Ultra-1/lib/libc_psr.so.1

Changelog:

2002/09/02 use “:” for LDPATH separator, use IFS=: to split LDPATH

properly search for “.” when RPATH=:…

2003/10/16 Switch between 6.1.0 and 6.2.0.

Switch search “.” when LD_LIBRARY_PATH undefined.