1#!/bin/sh 2# $FreeBSD$ 3 4mime=$(file --mime-type $1) 5case $mime in 6*application/x-executable);; 7*application/x-sharedlib);; 8*) echo "Not an elf file" >&2 ; exit 1;; 9esac 10 11# Check for useful libs 12list_libs="" 13for lib in $(readelf -d $1 | awk '$2 == "(NEEDED)" { sub(/\[/,"",$NF); sub(/\]/,"",$NF); print $NF }'); do 14 echo -n "checking if $lib is needed: " 15 libpath=$(ldd $1 | awk -v lib=$lib '$1 == lib { print $3 }') 16 list_libs="$list_libs $libpath" 17 foundone=0 18 for fct in $(nm -D $libpath | awk '$2 == "T" || $2 == "W" || $2 == "B" { print $3 }'); do 19 nm -D $1 | awk -v s=$fct '$1 == "U" && $2 == s { found=1 ; exit } END { if (found != 1) { exit 1 } }' && foundone=1 && break 20 done 21 if [ $foundone -eq 1 ]; then 22 echo "yes" 23 else 24 echo "no" 25 fi 26done 27 28for sym in $(nm -D $1 | awk '$1 == "U" { print $2 }'); do 29 found=0 30 for l in ${list_libs} ; do 31 nm -D $l | awk -v s=$sym '($2 == "T" || $2 == "W" || $2 == "B") && $3 == s { found=1 ; exit } END { if (found != 1) { exit 1 } }' && found=1 && break 32 done 33 if [ $found -eq 0 ]; then 34 echo "Unresolved symbol $sym" 35 fi 36done 37 38