-
Notifications
You must be signed in to change notification settings - Fork 5
/
norm-ldd
executable file
·142 lines (131 loc) · 6.22 KB
/
norm-ldd
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
set -eE
set -o pipefail
# set -x
usage() {
echo "Usage: $0 [-v] [-q] <full-prefix-path>"
exit 64
}
## parse parameters
unset verbose
unset quiet
while getopts ":qv" opt; do
case $opt in
v) verbose=true ;;
q) quiet=true ;;
\?) echo "Invalid option: -$OPTARG" >&2
usage
exit 64
;;
:)
usage
exit 64
;;
esac
done
shift $((OPTIND-1))
OPTIND=1
[[ -z "$1" ]] && usage
prefix="$1"
## get files
IFS=$'\n' ## split on newline only
set -f ## disable globbing
files=($(find "$1" -type f))
## filter out files
newfiles=()
for file in "${files[@]}"; do
## filter out some files by path
[[ $file =~ (README|INSTALL|COPYING)$ ]] && continue
[[ $file == */include/* ]] && continue
[[ $file == */share/cmake* ]] && continue
[[ $file == */share/doc/* ]] && continue
[[ $file == */share/docbook-xsl/* ]] && continue
[[ $file == */share/docbook-xsl-ns/* ]] && continue
[[ $file == */share/gtk-doc/* ]] && continue
[[ $file == */share/info/* ]] && continue
[[ $file == */share/man* ]] && continue
[[ $file == */share/terminfo/* ]] && continue
[[ $file == */share/X11/locale/* ]] && continue
[[ $file == */share/bash-completion/* ]] && continue
[[ $file == */bash_completion.d/* ]] && continue
[[ $file == */var/cache/* ]] && continue
[[ $file == */mysql-test/* ]] && continue
[[ $file == */tmp/compile/* ]] && continue
[[ $file == */go/pkg/obj/go-build/* ]] && continue
[[ $file == */testdata/* ]] && continue
## filter out some files by extension
[[ $file =~ \.(py|pyo|pyc|ri|rb|js|rhtml)$ ]] && continue
[[ $file =~ \.(def|decTest|m4|txt|pc|la|syntax|installed)$ ]] && continue
[[ $file =~ \.(c|h|fon|am|pm|tcl|sl|xml|sh|msg|map|info|pem|ini|hlp|mo|po)$ ]] && continue
[[ $file =~ \.(sample|ttf|css|htm|html|pub|ac|in|inc|sub|conf|site|cnf|pod|el)$ ]] && continue
[[ $file =~ \.(gir|cmake|rules|pickle|tmpl|typelib|packlist)$ ]] && continue
[[ $file =~ \.(gif|png|jpg|jpeg|bmp|pbm|pgm|ppm|ras|sgi|tiff?|xbm|svg)$ ]] && continue
[[ $file =~ \.(aiff|au|wav|aifc|aif)$ ]] && continue
[[ $file =~ \.(x|xbn|xc|xd|xdc|xdw|xn|xr|xs|xsc|xsw|xu|xw)$ ]] && continue
[[ $file =~ \.(a|gox|go|nse|lua|gv|s)$ ]] && continue
[[ $file =~ \.(xsl|xsd|rng|docbook|ent|mod|cat)$ ]] && continue
[[ $file =~ \.(o|cc|test|result|sql|class|java|pl|cfg|opt)$ ]] && continue
[[ $file =~ \.(enc|exp|aug|rlib|json)$ ]] && continue
[[ $file =~ \.(pri|prf|qm|i|swg|qml|prl|qdocconf|qdoc|qdocinc|qmltypes)$ ]] && continue
[[ $file =~ \.(gz|xz|y|e2x|sv|tablet|bat|htaccess|icns|lisp|tmp|dtd|rnc|tex)$ ]] && continue
[[ $file =~ \.(cl)$ ]] && continue
newfiles+=("$file")
done
files=("${newfiles[@]}")
[[ -n "$verbose" ]] && printf "%s\n" "${files[@]}" | sort
[[ -z "$quiet" ]] && echo "Found "${#files[@]}" files, checking if they have dependencies outside norm's prefix..."
unset LD_LIBRARY_PATH
retstatus=0
for file in "${files[@]}"; do
## get ldd of the file
ldd=($(ldd "$file" 2>&1 || true))
lines=()
## filter out the ldd output
for line in "${ldd[@]}"; do
[[ $line == *"$prefix"* ]] && continue
[[ $line == *"not a dynamic executable"* ]] && continue
[[ $line == *"statically linked"* ]] && continue
[[ $line =~ 'fatal error:'.*'otool: internal objdump command failed' ]] && continue
[[ $line =~ ^$'\t'linux-(gate|vdso)\.so\.1\ (=>\ \ )?\( ]] && continue
[[ $line =~ ^$'\t'lib(c|m|dl|rt|pthread|resolv|crypt|util|nsl|mvec)\.so ]] && continue
[[ $line =~ ^$'\t'libc.musl-x86_64\.so ]] && continue
[[ $line =~ ^$'\t'lib(gcc_s|stdc\+\+|ssp|gomp)\.so ]] && continue
[[ $line =~ ^$'\t'libfreebl3.so' => '/lib64/libfreebl3.so' '\(0x[0-9a-f]+\)$ ]] && continue
[[ $line =~ ^$'\t'/lib/ld-linux\.so\.2 ]] && continue
[[ $line =~ ^$'\t'/lib/ld-linux-aarch64\.so\.1 ]] && continue
[[ $line =~ ^$'\t'/lib/ld-musl-x86_64\.so\.1 ]] && continue
[[ $line =~ ^$'\t'(/usr)?/lib64/ld-linux-x86-64\.so\.2 ]] && continue
[[ $line =~ ^$'\t'/lib/ld-linux-armhf\.so\.3 ]] && continue
[[ $line =~ ^$'\t'ldd\b ]] && continue
[[ $line =~ ^$'\t'/usr/lib/arm-linux-gnueabihf/libarmmem\.so ]] && continue
[[ $line =~ ^$'\t'/usr/lib/arm-linux-gnueabihf/libarmmem- ]] && continue
## osx first-party frameworks (core)
[[ $line =~ ^$'\t'/System/Library/Frameworks/Core(Foundation|Services|Graphics|Audio|Video|Media|Image|Haptics).framework/ ]] && continue
## osx first-party frameworks (kits)
[[ $line =~ ^$'\t'/System/Library/Frameworks/(IOKit|AppKit).framework/ ]] && continue
## osx first-party frameworks (toolbox)
[[ $line =~ ^$'\t'/System/Library/Frameworks/(Audio|Video)Toolbox.framework/ ]] && continue
## osx first-party frameworks (base)
[[ $line =~ ^$'\t'/System/Library/Frameworks/(Cocoa|Carbon|Security|Foundation).framework/ ]] && continue
## osx first-party frameworks (multimedia)
[[ $line =~ ^$'\t'/System/Library/Frameworks/(Metal|OpenGL|OpenCL|AVFoundation|ForceFeedback|GameController).framework/ ]] && continue
## osx first-party frameworks
[[ $line =~ ^$'\t'/System/Library/Frameworks/(LDAP|ApplicationServices|SystemConfiguration).framework/ ]] && continue
## osx third-party frameworks
[[ $line =~ ^$'\t'/System/Library/Frameworks/(Tk|Tcl|GLUT|Hypervisor).framework/ ]] && continue
## osx first-party libraries
[[ $line =~ ^$'\t'/usr/lib/lib(System\.B|objc.A|resolv\.9|charset\.1|c\+\+\.1)\.dylib ]] && continue
## osx third-party system libraries
[[ $line =~ ^$'\t'/usr/lib/lib(iconv\.2|xml2\.2|z\.1|curl\.4|expat\.1|lzma\.5|bz2\.1\.0|ffi|edit\.3|ncurses\.5\.4|sasl2\.2|sqlite3)\.dylib ]] && continue
## osx norm anomalies that don't support rpath
[[ $line =~ ^$'\t'lib(lmdb|boost_[a-z_2]+|capstone|icu(data|uc|tu|test|i18n|io)|gif)(\.[0-9]+)?\.dylib ]] && continue
## osx norm anomalies with rpath
[[ $line =~ ^$'\t'\@rpath/libmpdec(\+\+)?(\.[0-9]+)?\.dylib ]] && continue
lines+=("$line")
done
if [[ -n "$lines" ]]; then
echo "$file:"
printf "%s\n" "${lines[@]}"
retstatus=1
fi
done