Skip to content

Commit b4285d0

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#18395: scripts: add PE dylib checking to symbol-check.py
1a0993a scripts: add PE dylib checking to symbol-check.py (fanquake) Pull request description: Uses `objdump -x` and looks for `DLL Name:` lines. i.e: ```bash objdump -x src/qt/bitcoin-qt.exe | grep "DLL Name:" DLL Name: ADVAPI32.dll DLL Name: dwmapi.dll DLL Name: GDI32.dll DLL Name: IMM32.dll DLL Name: IPHLPAPI.DLL DLL Name: KERNEL32.dll DLL Name: msvcrt.dll DLL Name: ole32.dll DLL Name: OLEAUT32.dll DLL Name: SHELL32.dll DLL Name: SHLWAPI.dll DLL Name: USER32.dll DLL Name: UxTheme.dll DLL Name: VERSION.dll DLL Name: WINMM.dll DLL Name: WS2_32.dll ``` ACKs for top commit: dongcarl: Concept ACK 1a0993a hebasto: ACK 1a0993a, tested on Linux Mint 19.3: Tree-SHA512: 0099a50e2c616d5239a15cafa9a7c483e9c40244af41549e4738be0f5360f27a2afb956eb50b47cf446b242f4cfc6dc9d111306a056fb83789eefbd71eddabd2
1 parent caeab86 commit b4285d0

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

contrib/devtools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ certain symbols and are only linked against allowed libraries.
170170
For Linux this means checking for allowed gcc, glibc and libstdc++ version symbols.
171171
This makes sure they are still compatible with the minimum supported distribution versions.
172172

173-
For macOS we check that the executables are only linked against libraries we allow.
173+
For macOS and Windows we check that the executables are only linked against libraries we allow.
174174

175175
Example usage after a Gitian build:
176176

contrib/devtools/symbol-check.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
'''
66
A script to check that the (Linux) release executables only contain
7-
allowed gcc and glibc version symbols. This makes sure they are still compatible
8-
with the minimum supported Linux distribution versions.
7+
certain symbols and are only linked against allowed libraries.
98
109
Example usage:
1110
@@ -57,6 +56,7 @@
5756
'environ', '_environ', '__environ',
5857
}
5958
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
59+
OBJDUMP_CMD = os.getenv('OBJDUMP', '/usr/bin/objdump')
6060
OTOOL_CMD = os.getenv('OTOOL', '/usr/bin/otool')
6161

6262
# Allowed NEEDED libraries
@@ -107,6 +107,30 @@
107107
'QuartzCore', # animation
108108
}
109109

110+
PE_ALLOWED_LIBRARIES = {
111+
'ADVAPI32.dll', # security & registry
112+
'IPHLPAPI.DLL', # IP helper API
113+
'KERNEL32.dll', # win32 base APIs
114+
'msvcrt.dll', # C standard library for MSVC
115+
'SHELL32.dll', # shell API
116+
'USER32.dll', # user interface
117+
'WS2_32.dll', # sockets
118+
'bcrypt.dll',
119+
# bitcoin-qt only
120+
'dwmapi.dll', # desktop window manager
121+
'GDI32.dll', # graphics device interface
122+
'IMM32.dll', # input method editor
123+
'NETAPI32.dll',
124+
'ole32.dll', # component object model
125+
'OLEAUT32.dll', # OLE Automation API
126+
'SHLWAPI.dll', # light weight shell API
127+
'USERENV.dll',
128+
'UxTheme.dll',
129+
'VERSION.dll', # version checking
130+
'WINMM.dll', # WinMM audio API
131+
'WTSAPI32.dll',
132+
}
133+
110134
class CPPFilt(object):
111135
'''
112136
Demangle C++ symbol names.
@@ -200,6 +224,26 @@ def check_MACHO_libraries(filename) -> bool:
200224
ok = False
201225
return ok
202226

227+
def pe_read_libraries(filename) -> List[str]:
228+
p = subprocess.Popen([OBJDUMP_CMD, '-x', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True)
229+
(stdout, stderr) = p.communicate()
230+
if p.returncode:
231+
raise IOError('Error opening file')
232+
libraries = []
233+
for line in stdout.splitlines():
234+
if 'DLL Name:' in line:
235+
tokens = line.split(': ')
236+
libraries.append(tokens[1])
237+
return libraries
238+
239+
def check_PE_libraries(filename) -> bool:
240+
ok = True
241+
for dylib in pe_read_libraries(filename):
242+
if dylib not in PE_ALLOWED_LIBRARIES:
243+
print('{} is not in ALLOWED_LIBRARIES!'.format(dylib))
244+
ok = False
245+
return ok
246+
203247
CHECKS = {
204248
'ELF': [
205249
('IMPORTED_SYMBOLS', check_imported_symbols),
@@ -208,6 +252,9 @@ def check_MACHO_libraries(filename) -> bool:
208252
],
209253
'MACHO': [
210254
('DYNAMIC_LIBRARIES', check_MACHO_libraries)
255+
],
256+
'PE' : [
257+
('DYNAMIC_LIBRARIES', check_PE_libraries)
211258
]
212259
}
213260

contrib/gitian-descriptors/gitian-win.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ script: |
159159
CONFIG_SITE=${BASEPREFIX}/${i}/share/config.site ./configure --prefix=/ --disable-maintainer-mode --disable-dependency-tracking ${CONFIGFLAGS} CFLAGS="${HOST_CFLAGS}" CXXFLAGS="${HOST_CXXFLAGS}"
160160
make ${MAKEOPTS}
161161
make ${MAKEOPTS} -C src check-security
162+
make ${MAKEOPTS} -C src check-symbols
162163
make deploy BITCOIN_WIN_INSTALLER="${OUTDIR}/${DISTNAME}-win64-setup-unsigned.exe"
163164
make install DESTDIR=${INSTALLPATH}
164165
cd installed

src/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,11 @@ if TARGET_DARWIN
938938
$(AM_V_at) OTOOL=$(OTOOL) $(PYTHON) $(top_srcdir)/contrib/devtools/symbol-check.py $(bin_PROGRAMS)
939939
endif
940940

941+
if TARGET_WINDOWS
942+
@echo "Checking Windows dynamic libraries..."
943+
$(AM_V_at) OBJDUMP=$(OBJDUMP) $(PYTHON) $(top_srcdir)/contrib/devtools/symbol-check.py $(bin_PROGRAMS)
944+
endif
945+
941946
if GLIBC_BACK_COMPAT
942947
@echo "Checking glibc back compat..."
943948
$(AM_V_at) CPPFILT=$(CPPFILT) $(PYTHON) $(top_srcdir)/contrib/devtools/symbol-check.py $(bin_PROGRAMS)

0 commit comments

Comments
 (0)