[kwlug-disc] how to identify superfluous shared library references?

Chris Frey cdfrey at foursquare.net
Tue Mar 10 18:53:03 EDT 2009


On Tue, Mar 10, 2009 at 05:10:38PM -0400, Robert P. J. Day wrote:
>   it would be, except things are a bit trickier than that.  this is on
> an embedded system that has no "ldd" command, but i've managed to
> kludge that via the following:
> 
>   $ LD_TRACE_LOADED_OBJECTS=1 /bin/ls
> 
> that env var is recognized by the linker which prints out the shared
> lib references for any command, just as "ldd" does.  problem is,
> there's no way i can see to add the "-u" behaviour of ldd to that.

If you have objdump on the embedded system, or if you can use objdump
on your development system, you might try something like this:

for f in $(ldd /bin/ls | grep "=> /lib" |awk '{print $3}') ; do
	if ! objdump -T $f | grep text | egrep $(objdump -T /bin/ls | grep UND | awk 'BEGIN {printf "("; start = 1} { if( start ) { start = 0; } else { printf "|" } printf "%s", $(NF) } END {printf ")"}') >/dev/null ; then
		echo "Useless: $f"
	fi
done


You'll have to replace the ldd output in the for loop with your LD_TRACE
output.

This was a quick hack, so it might not be completely accurate. Or useful. :-)

- Chris





More information about the kwlug-disc mailing list