Skip to content

Commit 48ed386

Browse files
committed
Merge #13724: [contrib] Support ARM and RISC-V symbol check
c516c3a [contrib] Support ARM and RISC-V symbol check (Chun Kuan Lee) Pull request description: Solve the TODO in the gitian-descripter Tree-SHA512: 8115e2958af3dde43d9d9d05f0b1b1b93b1c2aa513e771a3e4e1342a5d78af2b0e40c0bbb7e9a0d15954897317e6f5a0d80996239af3b376d5ddd527f73428ae
2 parents 07033a8 + c516c3a commit 48ed386

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

contrib/devtools/symbol-check.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@
3636
# (glibc) GLIBC_2_11
3737
#
3838
MAX_VERSIONS = {
39-
'GCC': (4,4,0),
40-
'CXXABI': (1,3,3),
41-
'GLIBCXX': (3,4,13),
42-
'GLIBC': (2,11)
39+
'GCC': (4,4,0),
40+
'CXXABI': (1,3,3),
41+
'GLIBCXX': (3,4,13),
42+
'GLIBC': (2,11),
43+
'LIBATOMIC': (1,0)
4344
}
4445
# See here for a description of _IO_stdin_used:
4546
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=634261#109
4647

4748
# Ignore symbols that are exported as part of every executable
4849
IGNORE_EXPORTS = {
49-
'_edata', '_end', '_init', '__bss_start', '_fini', '_IO_stdin_used', 'stdin', 'stdout', 'stderr'
50+
'_edata', '_end', '__end__', '_init', '__bss_start', '__bss_start__', '_bss_end__', '__bss_end__', '_fini', '_IO_stdin_used', 'stdin', 'stdout', 'stderr'
5051
}
5152
READELF_CMD = os.getenv('READELF', '/usr/bin/readelf')
5253
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
@@ -59,8 +60,12 @@
5960
'libanl.so.1', # DNS resolve
6061
'libm.so.6', # math library
6162
'librt.so.1', # real-time (clock)
63+
'libatomic.so.1',
6264
'ld-linux-x86-64.so.2', # 64-bit dynamic linker
6365
'ld-linux.so.2', # 32-bit dynamic linker
66+
'ld-linux-aarch64.so.1', # 64-bit ARM dynamic linker
67+
'ld-linux-armhf.so.3', # 32-bit ARM dynamic linker
68+
'ld-linux-riscv64-lp64d.so.1', # 64-bit RISC-V dynamic linker
6469
# bitcoin-qt only
6570
'libX11-xcb.so.1', # part of X11
6671
'libX11.so.6', # part of X11
@@ -69,7 +74,13 @@
6974
'libfreetype.so.6', # font parsing
7075
'libdl.so.2' # programming interface to dynamic linker
7176
}
72-
77+
ARCH_MIN_GLIBC_VER = {
78+
'80386': (2,1),
79+
'X86-64': (2,2,5),
80+
'ARM': (2,4),
81+
'AArch64':(2,17),
82+
'RISC-V': (2,27)
83+
}
7384
class CPPFilt(object):
7485
'''
7586
Demangle C++ symbol names.
@@ -94,23 +105,25 @@ def read_symbols(executable, imports=True):
94105
Parse an ELF executable and return a list of (symbol,version) tuples
95106
for dynamic, imported symbols.
96107
'''
97-
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
108+
p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', '-h', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
98109
(stdout, stderr) = p.communicate()
99110
if p.returncode:
100111
raise IOError('Could not read symbols for %s: %s' % (executable, stderr.strip()))
101112
syms = []
102113
for line in stdout.splitlines():
103114
line = line.split()
115+
if 'Machine:' in line:
116+
arch = line[-1]
104117
if len(line)>7 and re.match('[0-9]+:$', line[0]):
105118
(sym, _, version) = line[7].partition('@')
106119
is_import = line[6] == 'UND'
107120
if version.startswith('@'):
108121
version = version[1:]
109122
if is_import == imports:
110-
syms.append((sym, version))
123+
syms.append((sym, version, arch))
111124
return syms
112125

113-
def check_version(max_versions, version):
126+
def check_version(max_versions, version, arch):
114127
if '_' in version:
115128
(lib, _, ver) = version.rpartition('_')
116129
else:
@@ -119,7 +132,7 @@ def check_version(max_versions, version):
119132
ver = tuple([int(x) for x in ver.split('.')])
120133
if not lib in max_versions:
121134
return False
122-
return ver <= max_versions[lib]
135+
return ver <= max_versions[lib] or lib == 'GLIBC' and ver <= ARCH_MIN_GLIBC_VER[arch]
123136

124137
def read_libraries(filename):
125138
p = subprocess.Popen([READELF_CMD, '-d', '-W', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
@@ -142,16 +155,17 @@ def read_libraries(filename):
142155
retval = 0
143156
for filename in sys.argv[1:]:
144157
# Check imported symbols
145-
for sym,version in read_symbols(filename, True):
146-
if version and not check_version(MAX_VERSIONS, version):
158+
for sym,version,arch in read_symbols(filename, True):
159+
if version and not check_version(MAX_VERSIONS, version, arch):
147160
print('%s: symbol %s from unsupported version %s' % (filename, cppfilt(sym), version))
148161
retval = 1
149162
# Check exported symbols
150-
for sym,version in read_symbols(filename, False):
151-
if sym in IGNORE_EXPORTS:
152-
continue
153-
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
154-
retval = 1
163+
if arch != 'RISC-V':
164+
for sym,version,arch in read_symbols(filename, False):
165+
if sym in IGNORE_EXPORTS:
166+
continue
167+
print('%s: export of symbol %s not allowed' % (filename, cppfilt(sym)))
168+
retval = 1
155169
# Check dependency libraries
156170
for library_name in read_libraries(filename):
157171
if library_name not in ALLOWED_LIBRARIES:

contrib/gitian-descriptors/gitian-linux.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,7 @@ script: |
173173
CONFIG_SITE=${BASEPREFIX}/${i}/share/config.site ./configure --prefix=/ --disable-ccache --disable-maintainer-mode --disable-dependency-tracking ${CONFIGFLAGS} CFLAGS="${HOST_CFLAGS}" CXXFLAGS="${HOST_CXXFLAGS}" LDFLAGS="${HOST_LDFLAGS}"
174174
make ${MAKEOPTS}
175175
make ${MAKEOPTS} -C src check-security
176-
177-
#TODO: This is a quick hack that disables symbol checking for arm.
178-
# Instead, we should investigate why these are popping up.
179-
# For aarch64, we'll need to bump up the min GLIBC version, as the abi
180-
# support wasn't introduced until 2.17.
181-
case $i in
182-
aarch64-*) : ;;
183-
arm-*) : ;;
184-
riscv64-*) : ;;
185-
*) make ${MAKEOPTS} -C src check-symbols ;;
186-
esac
187-
176+
make ${MAKEOPTS} -C src check-symbols
188177
make install DESTDIR=${INSTALLPATH}
189178
cd installed
190179
find . -name "lib*.la" -delete

0 commit comments

Comments
 (0)