-
Notifications
You must be signed in to change notification settings - Fork 0
/
findlibs
executable file
·61 lines (52 loc) · 1.08 KB
/
findlibs
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
#!/bin/bash
find_lib_providing() {
symbol="$1"
shift
scanelf -s "$symbol" "$@" |
grep "$symbol" |
while read -r _ _ file; do
nm -Cu "$file" |
grep -q "$symbol" ||
echo "$file";
done
}
get_missing_symbols() {
file="$1"
nm -Cu "$file" | sed -e 's/.* \([^ ]\+\)$/\1/' -e '/GLIBC/d'
}
print_help() {
echo "Usage: $0 <file> <libs_directories...>"
echo "This is a tool to help to determine dependencies of a library"
}
set -e
which nm >/dev/null
which scanelf >/dev/null
if [ "$1" = "-h" ]; then
print_help
exit 0
fi
if [ $# -lt 2 ]; then
echo "Please provide file and a lib directory"
print_help
exit 1
fi
if [ ! -f "$1" ]; then
echo "$1 is not a file"
print_help
exit 1
fi
file="$1"
shift
libs=( )
while [ -n "$1" ]; do
if [ ! -d "$1" ]; then
echo "$1 is not a directory"
print_help
exit 1
fi
libs+=("$1")
shift
done
for symbol in $(get_missing_symbols "$file"); do
echo "$(find_lib_providing "$symbol" "${libs[@]}")" "$symbol"
done | sort