-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindsym
executable file
·116 lines (98 loc) · 2.2 KB
/
findsym
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh -efu
PROG=findsym
info()
{
printf %s\\n "$PROG: $*" >&2
}
fatal()
{
printf %s\\n "$PROG: $*" >&2
exit 1
}
show_usage()
{
[ -z "$*" ] || info "$*"
echo "Try \`$PROG --help' for more information." >&2
exit 1
}
print_version()
{
cat <<EOF
$PROG version 1.2
EOF
exit
}
show_help()
{
cat <<EOF
$PROG - search through all system shared libraries for a specific symbol.
This program will attempt to search through all system shared libraries
for a specific symbol. This is useful when trying to compile something
and the compiler complains about an undefined reference similar to this:
/tmp/ccabcdef.o(.text+0x7): undefined reference to \`printf'
Running \`findsym' would try to locate the provided symbol and indicate
what library you should be linking with:
$ findsym printf
/lib32/libc.so.6: 000509a0 T printf
/lib/i386-linux-gnu/libc.so.6: 000509e0 T printf
/libx32/libc.so.6: 0004bb50 T printf
/lib/x86_64-linux-gnu/libc.so.6: 0000000000054b40 T printf
/usr/lib32/libasan.so.4: 000770a0 W printf
Usage: $PROG [options] <symbol>...
Options:
-C, --demangle[=style] demangle symbol names;
-V, --version print program version and exit;
-h, --help show this text and exit.
EOF
exit
}
TEMP=`getopt -n $PROG -o C,h,V -l demangle::,help,version -- "$@"` ||
show_usage
eval set -- "$TEMP"
demangle=
while :; do
case "$1" in
--) shift; break
;;
-C)
demangle='-C'
;;
--demangle)
shift; demangle="--demangle=$1"
;;
-h|--help) show_help
;;
-V|--version) print_version
;;
*) fatal "Unrecognized option: $1"
;;
esac
shift
done
# At least one argument, please.
[ "$#" -ge 1 ] ||
show_usage 'Not enough arguments.'
IFS='
'
/sbin/ldconfig -p |
sed -ne 's/^.\+=>[[:space:]]\+\([^[:space:]]\+\)[[:space:]]*$/\1/p' |
sort -u |
xargs -r nm -gD ${demangle} -- 2>/dev/null |
LC_ALL=C sed -e 's/^\([0-9a-f]\+\)\?[[:space:]]\+\([A-Za-z]\)[[:space:]]\+\([^[:space:]]\)/\1\t\2\t\3/' |
LC_ALL=C awk "-vr=$IFS" "-vs=$*" '
BEGIN {
FS="\t"
OFS=" "
f=""
split(s,a,r)
}
(NF==0) {f=""}
(NF==1) {f=$1}
((NF==3) && (f!="") && ($2~/^[A-Za-z]$/) && ($1~/^[0-9a-f]+$/)) {
for(e in a)
if($3==a[e]) {
$1=$1
printf("%s %s\n",f,$0)
}
}
'