Skip to content

Commit c972345

Browse files
committed
scripts: check minimum required Windows version is set
We use linker flags (-Wl,--major/minor-subsystem-version) to set the minimum required version of Windows needed to run our binaries. This adds a sanity check that the version is being set as expected.
1 parent 29615ae commit c972345

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

contrib/devtools/symbol-check.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ def check_PE_libraries(filename) -> bool:
227227
ok = False
228228
return ok
229229

230+
def check_PE_subsystem_version(filename) -> bool:
231+
binary = lief.parse(filename)
232+
major: int = binary.optional_header.major_subsystem_version
233+
minor: int = binary.optional_header.minor_subsystem_version
234+
if major == 6 and minor == 1:
235+
return True
236+
return False
237+
230238
CHECKS = {
231239
'ELF': [
232240
('IMPORTED_SYMBOLS', check_imported_symbols),
@@ -238,7 +246,8 @@ def check_PE_libraries(filename) -> bool:
238246
('MIN_OS', check_MACHO_min_os),
239247
],
240248
'PE' : [
241-
('DYNAMIC_LIBRARIES', check_PE_libraries)
249+
('DYNAMIC_LIBRARIES', check_PE_libraries),
250+
('SUBSYSTEM_VERSION', check_PE_subsystem_version),
242251
]
243252
}
244253

contrib/devtools/test-symbol-check.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,26 @@ def test_PE(self):
145145
}
146146
''')
147147

148-
self.assertEqual(call_symbol_check(cc, source, executable, ['-lpdh']),
148+
self.assertEqual(call_symbol_check(cc, source, executable, ['-lpdh', '-Wl,--major-subsystem-version', '-Wl,6', '-Wl,--minor-subsystem-version', '-Wl,1']),
149149
(1, 'pdh.dll is not in ALLOWED_LIBRARIES!\n' +
150150
executable + ': failed DYNAMIC_LIBRARIES'))
151151

152152
source = 'test2.c'
153153
executable = 'test2.exe'
154+
155+
with open(source, 'w', encoding="utf8") as f:
156+
f.write('''
157+
int main()
158+
{
159+
return 0;
160+
}
161+
''')
162+
163+
self.assertEqual(call_symbol_check(cc, source, executable, ['-Wl,--major-subsystem-version', '-Wl,9', '-Wl,--minor-subsystem-version', '-Wl,9']),
164+
(1, executable + ': failed SUBSYSTEM_VERSION'))
165+
166+
source = 'test3.c'
167+
executable = 'test3.exe'
154168
with open(source, 'w', encoding="utf8") as f:
155169
f.write('''
156170
#include <windows.h>
@@ -162,7 +176,7 @@ def test_PE(self):
162176
}
163177
''')
164178

165-
self.assertEqual(call_symbol_check(cc, source, executable, ['-lole32']),
179+
self.assertEqual(call_symbol_check(cc, source, executable, ['-lole32', '-Wl,--major-subsystem-version', '-Wl,6', '-Wl,--minor-subsystem-version', '-Wl,1']),
166180
(0, ''))
167181

168182

0 commit comments

Comments
 (0)