forked from 21cnbao/libdep
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsymbol-dep.py
More file actions
executable file
·43 lines (36 loc) · 1.1 KB
/
symbol-dep.py
File metadata and controls
executable file
·43 lines (36 loc) · 1.1 KB
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
#!/usr/bin/python3
import sys, getopt, os
def main(argv):
srcfile = ''
dstfile = ''
neededsymbols=[]
exportedsymbols=[]
try:
opts, args = getopt.getopt(argv,"hs:d:",["sfile=","dfile="])
except getopt.GetoptError:
print ('symbol-dep.py -s <srcfile> -d <dstfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ('symbol-dep.py -s <srcfile> -d <dsrfile>')
sys.exit()
elif opt in ("-s", "--sfile"):
srcfile = arg
elif opt in ("-d", "--dfile"):
dstfile = arg
# get the symbols srcfile depends on
src=os.popen("nm -D --undefined-only "+srcfile)
srclist=src.read().splitlines()
for sline in srclist:
neededsymbols.append(sline.split()[-1])
# get the symbols dstfile exports
dst=os.popen("nm -D --defined-only "+dstfile)
dstlist=dst.read().splitlines()
for dline in dstlist:
exportedsymbols.append(dline.split()[-1])
# intersection of src and dest
for symbol in neededsymbols:
if symbol in exportedsymbols:
print(symbol)
if __name__ == "__main__":
main(sys.argv[1:])