-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolveSharedLibSymbols.sh
72 lines (58 loc) · 1.71 KB
/
resolveSharedLibSymbols.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
if [ "$#" -ne 1 ]
then
echo "1 argument needed in the script"
echo "e.g. $0 [binary name(complete path)]"
exit
fi
if [ -f $1 ]
then
echo "Going to find the unresolved symbols found in \"$1\""
else
echo "Binary file \"$1\" not found. Check name/path."
fi
binaryFile=$1
lddOutput=`ldd $binaryFile | awk '{print $3}' | grep -v "0x" | awk 'NF >0'`
#echo "$lddOutput"
sharedDependencies=()
for lib in `readelf -d $binaryFile | grep -i "Shared library" | awk '{print $5}' | sed -e 's/\[//g' | sed -e 's/\]//g'`;
do
sharedDependencies+=(`grep $lib lddOutput`)
done
rm -f allSymbols.temp
rm -f result.txt
# Iterate the loop to read and print each array element
echo -e "\nGiven below are the dependencies found for $binaryFile\n"
for lib in "${sharedDependencies[@]}"
do
echo $lib
#Create list of all text symbols from all the libraries
#for symbol in `nm -gD $lib | awk '{$1=""}1' | grep " T \| W \| V \| w \| v \| t " | awk '{print $2}'`;
#for symbol in `nm -gD $lib | grep -i " T \| W \| V "`;
nm -gD $lib | grep -i " T \| W \| V \| I " | while read symbol;
do
string=
sym=
#echo -e "\nsymbol->$symbol" >> debug.txt
n=`echo $symbol | awk "{print NF}"`
#echo -e "n->$n\n" >> debug.txt
if [ $n -eq 2 ]
then
sym=`echo $symbol | awk '{print $2}'`
else
sym=`echo $symbol | awk '{print $3}'`
fi
string="$lib contains $sym"
echo $string >> allSymbols.temp
#echo $string >> debug.txt
done
done
undefinedDynamicSymbols=`nm -uD $binaryFile | awk '{print $2}'`
#echo -e "\n\nUndefinedDynamicSymbols\n$undefinedDynamicSymbols\n"
for undefinedSymbol in $undefinedDynamicSymbols;
do
echo $undefinedSymbol >> result.txt
grep -w $undefinedSymbol allSymbols.temp >> result.txt
echo -e "\n" >> result.txt
done
rm -f allSymbols.temp