This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deps
68 lines (61 loc) · 1.53 KB
/
deps
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
#!/usr/bin/env python
import os
import re
import popen2
import sys
import tempfile
libc = '/usr/lib/libc.a'
tmp = tempfile.mktemp()
# create dictionary s2o: symbol name -> (.o name (in libc.a), type (e.g., 'T'))
def gets2o():
s2o = {}
r = re.compile(r'.*\[([.\-\w]+)\]: (\w+) ([WwtTCBRD])')
nm = ['nm','-A','-fposix',libc]
(ignore_in,f,ignore_err) = os.popen3(' '.join(nm))
for line in f:
m = r.findall(line)
if 0 == len(m):
continue;
m = m[0]
if s2o.has_key(m[1]):
t = s2o[m[1]][1]
if t != 'w' and t != 'W':
continue;
s2o[m[1]] = (m[0],m[2])
f.close()
del f
return s2o
objs = sys.argv[1:]
if 0 == len(objs):
print 'no objects specified'
sys.exit(1)
cc = ['gcc','-o',tmp,'-shared','-nostartfiles','-Xlinker','-Bsymbolic']
nm = ['nm','-fposix','-u',tmp]
ar = ['ar','-x',libc]
xx = gets2o()
extract = []
while 1:
p = popen2.Popen3(' '.join(cc+objs+extract), 1)
p.wait()
del p
f = os.popen(' '.join(nm),'r')
l = len(extract)
for line in f:
sym = line.split()[0];
sym = sym.split('@')[0]
sym = sym.strip()
if not xx.has_key(sym):
print 'error: unknown undefined symbol', sym
sys.exit(1)
o = xx[sym][0]
if not o in extract:
p = popen2.Popen3(' '.join(ar+[o]))
p.wait()
del p
extract.append(o)
f.close()
del f
if len(extract) == l:
break
os.remove(tmp)
print ' '.join(extract)