Skip to content

Commit f50975b

Browse files
committed
[contrib] fixup symbol-check.py Python3 support
1 parent 5de2b18 commit f50975b

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

contrib/devtools/symbol-check.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,28 @@
4646

4747
# Ignore symbols that are exported as part of every executable
4848
IGNORE_EXPORTS = {
49-
b'_edata', b'_end', b'_init', b'__bss_start', b'_fini', b'_IO_stdin_used'
49+
'_edata', '_end', '_init', '__bss_start', '_fini', '_IO_stdin_used'
5050
}
5151
READELF_CMD = os.getenv('READELF', '/usr/bin/readelf')
5252
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
5353
# Allowed NEEDED libraries
5454
ALLOWED_LIBRARIES = {
5555
# bitcoind and bitcoin-qt
56-
b'libgcc_s.so.1', # GCC base support
57-
b'libc.so.6', # C library
58-
b'libpthread.so.0', # threading
59-
b'libanl.so.1', # DNS resolve
60-
b'libm.so.6', # math library
61-
b'librt.so.1', # real-time (clock)
62-
b'ld-linux-x86-64.so.2', # 64-bit dynamic linker
63-
b'ld-linux.so.2', # 32-bit dynamic linker
56+
'libgcc_s.so.1', # GCC base support
57+
'libc.so.6', # C library
58+
'libpthread.so.0', # threading
59+
'libanl.so.1', # DNS resolve
60+
'libm.so.6', # math library
61+
'librt.so.1', # real-time (clock)
62+
'ld-linux-x86-64.so.2', # 64-bit dynamic linker
63+
'ld-linux.so.2', # 32-bit dynamic linker
6464
# bitcoin-qt only
65-
b'libX11-xcb.so.1', # part of X11
66-
b'libX11.so.6', # part of X11
67-
b'libxcb.so.1', # part of X11
68-
b'libfontconfig.so.1', # font support
69-
b'libfreetype.so.6', # font parsing
70-
b'libdl.so.2' # programming interface to dynamic linker
65+
'libX11-xcb.so.1', # part of X11
66+
'libX11.so.6', # part of X11
67+
'libxcb.so.1', # part of X11
68+
'libfontconfig.so.1', # font support
69+
'libfreetype.so.6', # font parsing
70+
'libdl.so.2' # programming interface to dynamic linker
7171
}
7272

7373
class CPPFilt(object):
@@ -77,10 +77,10 @@ class CPPFilt(object):
7777
Use a pipe to the 'c++filt' command.
7878
'''
7979
def __init__(self):
80-
self.proc = subprocess.Popen(CPPFILT_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
80+
self.proc = subprocess.Popen(CPPFILT_CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
8181

8282
def __call__(self, mangled):
83-
self.proc.stdin.write(mangled + b'\n')
83+
self.proc.stdin.write(mangled + '\n')
8484
self.proc.stdin.flush()
8585
return self.proc.stdout.readline().rstrip()
8686

@@ -94,43 +94,43 @@ def read_symbols(executable, imports=True):
9494
Parse an ELF executable and return a list of (symbol,version) tuples
9595
for dynamic, imported symbols.
9696
'''
97-
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
97+
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
9898
(stdout, stderr) = p.communicate()
9999
if p.returncode:
100100
raise IOError('Could not read symbols for %s: %s' % (executable, stderr.strip()))
101101
syms = []
102-
for line in stdout.split(b'\n'):
102+
for line in stdout.splitlines():
103103
line = line.split()
104-
if len(line)>7 and re.match(b'[0-9]+:$', line[0]):
105-
(sym, _, version) = line[7].partition(b'@')
106-
is_import = line[6] == b'UND'
107-
if version.startswith(b'@'):
104+
if len(line)>7 and re.match('[0-9]+:$', line[0]):
105+
(sym, _, version) = line[7].partition('@')
106+
is_import = line[6] == 'UND'
107+
if version.startswith('@'):
108108
version = version[1:]
109109
if is_import == imports:
110110
syms.append((sym, version))
111111
return syms
112112

113113
def check_version(max_versions, version):
114-
if b'_' in version:
115-
(lib, _, ver) = version.rpartition(b'_')
114+
if '_' in version:
115+
(lib, _, ver) = version.rpartition('_')
116116
else:
117117
lib = version
118118
ver = '0'
119-
ver = tuple([int(x) for x in ver.split(b'.')])
119+
ver = tuple([int(x) for x in ver.split('.')])
120120
if not lib in max_versions:
121121
return False
122122
return ver <= max_versions[lib]
123123

124124
def read_libraries(filename):
125-
p = subprocess.Popen([READELF_CMD, '-d', '-W', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
125+
p = subprocess.Popen([READELF_CMD, '-d', '-W', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
126126
(stdout, stderr) = p.communicate()
127127
if p.returncode:
128128
raise IOError('Error opening file')
129129
libraries = []
130-
for line in stdout.split(b'\n'):
130+
for line in stdout.splitlines():
131131
tokens = line.split()
132-
if len(tokens)>2 and tokens[1] == b'(NEEDED)':
133-
match = re.match(b'^Shared library: \[(.*)\]$', b' '.join(tokens[2:]))
132+
if len(tokens)>2 and tokens[1] == '(NEEDED)':
133+
match = re.match('^Shared library: \[(.*)\]$', ' '.join(tokens[2:]))
134134
if match:
135135
libraries.append(match.group(1))
136136
else:
@@ -144,18 +144,18 @@ def read_libraries(filename):
144144
# Check imported symbols
145145
for sym,version in read_symbols(filename, True):
146146
if version and not check_version(MAX_VERSIONS, version):
147-
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym).decode('utf-8'), version.decode('utf-8')))
147+
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym), version))
148148
retval = 1
149149
# Check exported symbols
150150
for sym,version in read_symbols(filename, False):
151151
if sym in IGNORE_EXPORTS:
152152
continue
153-
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym).decode('utf-8')))
153+
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
154154
retval = 1
155155
# Check dependency libraries
156156
for library_name in read_libraries(filename):
157157
if library_name not in ALLOWED_LIBRARIES:
158-
print('%s: NEEDED library %s is not allowed' % (filename, library_name.decode('utf-8')))
158+
print('%s: NEEDED library %s is not allowed' % (filename, library_name))
159159
retval = 1
160160

161161
sys.exit(retval)

0 commit comments

Comments
 (0)