Skip to content

Commit a595919

Browse files
authored
Remove references to RELOCATABLE/LINKABLE from test code. NFC (emscripten-core#25607)
These settings are due for deprecation/removal, plus none of these tests were really depending on them specifically (as opposed to dynamic linking in general). Replace this usage with three specific simple tests that we can remove when we remove these settings. See emscripten-core#25262
1 parent 00ad5e2 commit a595919

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed

embuilder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
'libwasmfs-debug',
128128
'libwasmfs_no_fs',
129129
'giflib',
130+
'sdl2',
131+
'sdl2_gfx',
132+
'sdl3',
130133
]
131134

132135
PORTS = sorted(list(ports.ports_by_name.keys()) + list(ports.port_variants.keys()))

test/test_core.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,15 +1856,14 @@ def test_set_align(self):
18561856
self.do_core_test('test_set_align.c')
18571857

18581858
@no_modularize_instance('uses Module object directly')
1859-
@no_js_math('JS_MATH is not compatible with LINKABLE')
18601859
@parameterized({
18611860
'': (['-sEXPORTED_FUNCTIONS=_main,_save_me_aimee'],),
18621861
# test EXPORT_ALL too
1863-
'export_all': (['-Wno-deprecated', '-sEXPORT_ALL', '-sLINKABLE'],),
1862+
'export_all': (['-sEXPORT_ALL', '-sMAIN_MODULE'],),
18641863
})
18651864
def test_emscripten_api(self, args):
1866-
if '-sLINKABLE' in args and '-lllvmlibc' in self.cflags:
1867-
self.skipTest('LLVM-libc overlay mode is not compatible with whole-archive (LINKABLE)')
1865+
if '-sMAIN_MODULE' in args:
1866+
self.check_dylink()
18681867
self.do_core_test('test_emscripten_api.c', cflags=args)
18691868

18701869
def test_emscripten_run_script_string_int(self):
@@ -6648,8 +6647,7 @@ def test_cubescript(self):
66486647

66496648
@needs_dylink
66506649
def test_relocatable_void_function(self):
6651-
self.set_setting('RELOCATABLE')
6652-
self.do_core_test('test_relocatable_void_function.c', cflags=['-Wno-deprecated'])
6650+
self.do_core_test('test_relocatable_void_function.c', cflags=['-sMAIN_MODULE=2'])
66536651

66546652
@wasm_simd
66556653
@parameterized({

test/test_other.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,12 +1582,11 @@ def test_dot_a_all_contents_invalid(self):
15821582
self.assertContained(['unknown file type', "libfoo.a: archive member 'native.o' is neither Wasm object file nor LLVM bitcode"], stderr)
15831583

15841584
def test_export_all(self):
1585-
lib = r'''
1585+
create_file('main.c', r'''
15861586
#include <stdio.h>
15871587
void libf1() { printf("libf1\n"); }
15881588
void libf2() { printf("libf2\n"); }
1589-
'''
1590-
create_file('lib.c', lib)
1589+
''')
15911590

15921591
create_file('pre.js', '''
15931592
Module.onRuntimeInitialized = () => {
@@ -1598,8 +1597,10 @@ def test_export_all(self):
15981597

15991598
# Explicitly test with -Oz to ensure libc_optz is included alongside
16001599
# libc when `--whole-archive` is used.
1601-
self.emcc('lib.c', ['-Oz', '-sEXPORT_ALL', '-sLINKABLE', '-Wno-deprecated', '--pre-js', 'pre.js'], output_filename='a.out.js')
1602-
self.assertContained('libf1\nlibf2\n', self.run_js('a.out.js'))
1600+
self.do_runf('main.c', 'libf1\nlibf2\n', cflags=['-Oz', '-sEXPORT_ALL', '-sMAIN_MODULE', '--pre-js', 'pre.js'])
1601+
1602+
# Without the `-sEXPORT_ALL` these symbols will not be visible from JS
1603+
self.do_runf('main.c', '_libf1 is not defined', assert_returncode=NON_ZERO, cflags=['-Oz', '-sMAIN_MODULE', '--pre-js', 'pre.js'])
16031604

16041605
def test_export_keepalive(self):
16051606
create_file('main.c', r'''
@@ -2534,23 +2535,23 @@ def test_sdl2_mixer_wav(self):
25342535
self.emcc('browser/test_sdl2_mixer_wav.c', ['--use-port=sdl2_mixer:formats=ogg'], output_filename='a.out.js')
25352536

25362537
def test_sdl2_linkable(self):
2537-
# Ensure that SDL2 can be built with LINKABLE. This implies there are no undefined
2538-
# symbols in the library (because LINKABLE includes the entire library).
2539-
self.emcc('browser/test_sdl2_misc.c', ['-sLINKABLE', '-Wno-deprecated', '-sUSE_SDL=2'], output_filename='a.out.js')
2540-
self.emcc('browser/test_sdl2_misc.c', ['-sLINKABLE', '-Wno-deprecated', '--use-port=sdl2'], output_filename='a.out.js')
2538+
# Ensure that SDL2 can be built with MAIN_MODULE. This implies there are no undefined
2539+
# symbols in the library (because MAIN_MODULE=1 includes the entire library).
2540+
self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE', '-sUSE_SDL=2'], output_filename='a.out.js')
2541+
self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE', '--use-port=sdl2'], output_filename='a.out.js')
25412542

25422543
def test_sdl3_linkable(self):
2543-
# Ensure that SDL3 can be built with LINKABLE. This implies there are no undefined
2544-
# symbols in the library (because LINKABLE includes the entire library).
2544+
# Ensure that SDL3 can be built with MAIN_MODULE. This implies there are no undefined
2545+
# symbols in the library (because MAIN_MODULE=1 includes the entire library).
25452546
self.cflags.append('-Wno-experimental')
2546-
self.emcc('browser/test_sdl3_misc.c', ['-sLINKABLE', '-Wno-deprecated', '-sUSE_SDL=3'], output_filename='a.out.js')
2547-
self.emcc('browser/test_sdl3_misc.c', ['-sLINKABLE', '-Wno-deprecated', '--use-port=sdl3'], output_filename='a.out.js')
2547+
self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE', '-sUSE_SDL=3'], output_filename='a.out.js')
2548+
self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE', '--use-port=sdl3'], output_filename='a.out.js')
25482549

25492550
@requires_network
25502551
def test_sdl2_gfx_linkable(self):
25512552
# Same as above but for sdl2_gfx library
2552-
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sLINKABLE', '-Wno-deprecated', '-sUSE_SDL_GFX=2'], output_filename='a.out.js')
2553-
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sLINKABLE', '-Wno-deprecated', '--use-port=sdl2_gfx'], output_filename='a.out.js')
2553+
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE', '-sUSE_SDL_GFX=2'], output_filename='a.out.js')
2554+
self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE', '--use-port=sdl2_gfx'], output_filename='a.out.js')
25542555

25552556
@requires_network
25562557
def test_libpng(self):
@@ -5120,9 +5121,9 @@ def test_bad_function_pointer_cast(self, opts, wasm, safe):
51205121
''')
51215122

51225123
for emulate_casts in (0, 1):
5123-
for relocatable in (0, 1):
5124-
# wasm2js is not compatible with relocatable mode
5125-
if not wasm and relocatable:
5124+
for dylink in (0, 1):
5125+
# wasm2js is not compatible with dynamic linking
5126+
if dylink and not wasm:
51265127
continue
51275128
cmd = [EMXX, 'src.cpp'] + opts
51285129
if not wasm:
@@ -5131,8 +5132,8 @@ def test_bad_function_pointer_cast(self, opts, wasm, safe):
51315132
cmd += ['-sSAFE_HEAP']
51325133
if emulate_casts:
51335134
cmd += ['-sEMULATE_FUNCTION_POINTER_CASTS']
5134-
if relocatable:
5135-
cmd += ['-sRELOCATABLE'] # disables asm-optimized safe heap
5135+
if dylink:
5136+
cmd += ['-sMAIN_MODULE=2'] # disables asm-optimized safe heap
51365137
print(cmd)
51375138
self.run_process(cmd)
51385139
returncode = 0 if emulate_casts or not wasm else NON_ZERO
@@ -12136,10 +12137,10 @@ def test_pthread_export_es6(self, args):
1213612137
self.assertContained('hello, world!', output)
1213712138

1213812139
def test_wasm2js_no_dylink(self):
12139-
for arg in ('-sMAIN_MODULE', '-sSIDE_MODULE', '-sRELOCATABLE'):
12140+
for arg in ('-sMAIN_MODULE', '-sSIDE_MODULE'):
1214012141
print(arg)
1214112142
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM=0', arg])
12142-
self.assertContained('emcc: error: WASM2JS is not compatible with RELOCATABLE', err)
12143+
self.assertContained(r'emcc: error: WASM2JS is not compatible with .*_MODULE \(wasm2js does not support dynamic linking\)', err, regex=True)
1214312144

1214412145
def test_wasm2js_standalone(self):
1214512146
self.do_run_in_out_file_test('hello_world.c', cflags=['-sSTANDALONE_WASM', '-sWASM=0'])
@@ -12375,12 +12376,12 @@ def test_gen_struct_info_env(self):
1237512376
with env_modify({'EMCC_CFLAGS': '-O2 BAD_ARG', 'EMCC_FORCE_STDLIBS': '1', 'EMCC_ONLY_FORCED_STDLIBS': '1'}):
1237612377
self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '-o', 'out.json'])
1237712378

12378-
def test_relocatable_limited_exports(self):
12379-
# Building with RELOCATABLE should *not* automatically export all sybmols.
12380-
self.run_process([EMCC, test_file('hello_world.c'), '-sRELOCATABLE', '-o', 'out.wasm'])
12379+
def test_dylink_limited_exports(self):
12380+
# Building with MAIN_MODULE=2 should *not* automatically export all sybmols.
12381+
self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE=2', '-o', 'out.wasm'])
1238112382

12382-
# Building with RELOCATABLE + LINKABLE should include and export all of the standard library
12383-
self.run_process([EMCC, test_file('hello_world.c'), '-sRELOCATABLE', '-sLINKABLE', '-o', 'out_linkable.wasm'])
12383+
# Building with MAIN_MODULE=1 should include and export all of the standard library
12384+
self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE', '-o', 'out_linkable.wasm'])
1238412385

1238512386
exports = self.parse_wasm('out.wasm')[1]
1238612387
exports_linkable = self.parse_wasm('out_linkable.wasm')[1]
@@ -12571,18 +12572,13 @@ def test_reverse_deps_allow_undefined(self):
1257112572
''')
1257212573
self.do_runf('test.c', cflags=['-sERROR_ON_UNDEFINED_SYMBOLS=0'])
1257312574

12574-
@parameterized({
12575-
'relocatable': ('-sRELOCATABLE',),
12576-
'linkable': ('-sLINKABLE',),
12577-
'main_module': ('-sMAIN_MODULE',),
12578-
})
12579-
def test_check_undefined(self, flag):
12575+
def test_dylink_undefined(self):
1258012576
# positive case: no undefined symbols
12581-
self.run_process([EMCC, flag, '-sERROR_ON_UNDEFINED_SYMBOLS', test_file('hello_world.c')])
12577+
self.run_process([EMCC, '-sMAIN_MODULE', test_file('hello_world.c')])
1258212578
self.run_js('a.out.js')
1258312579

1258412580
# negative case: foo is undefined in test_check_undefined.c
12585-
err = self.expect_fail([EMCC, flag, '-sERROR_ON_UNDEFINED_SYMBOLS', test_file('other/test_check_undefined.c')])
12581+
err = self.expect_fail([EMCC, '-sMAIN_MODULE', test_file('other/test_check_undefined.c')])
1258612582
self.assertContained('undefined symbol: foo', err)
1258712583

1258812584
@also_with_wasm64
@@ -13473,7 +13469,7 @@ def test_wasm_worker_errors(self):
1347313469
self.assertContained('-sSINGLE_FILE is not supported with -sWASM_WORKERS', err)
1347413470
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM_WORKERS', '-sPROXY_TO_WORKER'])
1347513471
self.assertContained('-sPROXY_TO_WORKER is not supported with -sWASM_WORKERS', err)
13476-
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM_WORKERS', '-sRELOCATABLE'])
13472+
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM_WORKERS', '-sMAIN_MODULE'])
1347713473
self.assertContained('dynamic linking is not supported with -sWASM_WORKERS', err)
1347813474

1347913475
def test_clock_nanosleep(self):
@@ -15197,3 +15193,18 @@ def has_defined_function(file, func):
1519715193
self.assertIn('main.cpp', out)
1519815194
self.assertIn('foo.cpp', out)
1519915195
self.assertIn('/emsdk/emscripten/system/lib/libc/musl/src/string/strcmp.c', out)
15196+
15197+
def test_relocatable(self):
15198+
# This setting is due for removal:
15199+
# https://github.com/emscripten-core/emscripten/issues/25262
15200+
self.do_run_in_out_file_test('hello_world.c', cflags=['-Wno-deprecated', '-sRELOCATABLE'])
15201+
15202+
def test_linkable(self):
15203+
# This setting is due for removal:
15204+
# https://github.com/emscripten-core/emscripten/issues/25262
15205+
self.do_run_in_out_file_test('hello_world.c', cflags=['-Wno-deprecated', '-sLINKABLE'])
15206+
15207+
def test_linkable_relocatable(self):
15208+
# These setting is due for removal:
15209+
# https://github.com/emscripten-core/emscripten/issues/25262
15210+
self.do_run_in_out_file_test('hello_world.c', cflags=['-Wno-deprecated', '-sLINKABLE', '-sRELOCATABLE'])

tools/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
# List of incompatible settings, of the form (SETTINGS_A, SETTING_B, OPTIONAL_REASON_FOR_INCOMPAT)
138138
INCOMPATIBLE_SETTINGS = [
139139
('MINIMAL_RUNTIME', 'RELOCATABLE', None),
140-
('WASM2JS', 'RELOCATABLE', None),
140+
('WASM2JS', 'MAIN_MODULE', 'wasm2js does not support dynamic linking'),
141+
('WASM2JS', 'SIDE_MODULE', 'wasm2js does not support dynamic linking'),
141142
('MODULARIZE', 'PROXY_TO_WORKER', 'if you want to run in a worker with -sMODULARIZE, you likely want to do the worker side setup manually'),
142143
('MODULARIZE', 'NO_DECLARE_ASM_MODULE_EXPORTS', None),
143144
('EVAL_CTORS', 'WASM2JS', None),

0 commit comments

Comments
 (0)