@@ -1580,12 +1580,11 @@ def test_dot_a_all_contents_invalid(self):
15801580 self.assertContained(['unknown file type', "libfoo.a: archive member 'native.o' is neither Wasm object file nor LLVM bitcode"], stderr)
15811581
15821582 def test_export_all(self):
1583- lib = r'''
1583+ create_file('main.c', r'''
15841584 #include <stdio.h>
15851585 void libf1() { printf("libf1\n"); }
15861586 void libf2() { printf("libf2\n"); }
1587- '''
1588- create_file('lib.c', lib)
1587+ ''')
15891588
15901589 create_file('pre.js', '''
15911590 Module.onRuntimeInitialized = () => {
@@ -1596,8 +1595,10 @@ def test_export_all(self):
15961595
15971596 # Explicitly test with -Oz to ensure libc_optz is included alongside
15981597 # libc when `--whole-archive` is used.
1599- self.emcc('lib.c', ['-Oz', '-sEXPORT_ALL', '-sLINKABLE', '-Wno-deprecated', '--pre-js', 'pre.js'], output_filename='a.out.js')
1600- self.assertContained('libf1\nlibf2\n', self.run_js('a.out.js'))
1598+ self.do_runf('main.c', 'libf1\nlibf2\n', cflags=['-Oz', '-sEXPORT_ALL', '-sMAIN_MODULE', '--pre-js', 'pre.js'])
1599+
1600+ # Without the `-sEXPORT_ALL` these symbols will not be visible from JS
1601+ self.do_runf('main.c', '_libf1 is not defined', assert_returncode=NON_ZERO, cflags=['-Oz', '-sMAIN_MODULE', '--pre-js', 'pre.js'])
16011602
16021603 def test_export_keepalive(self):
16031604 create_file('main.c', r'''
@@ -2532,23 +2533,23 @@ def test_sdl2_mixer_wav(self):
25322533 self.emcc('browser/test_sdl2_mixer_wav.c', ['--use-port=sdl2_mixer:formats=ogg'], output_filename='a.out.js')
25332534
25342535 def test_sdl2_linkable(self):
2535- # Ensure that SDL2 can be built with LINKABLE . This implies there are no undefined
2536- # symbols in the library (because LINKABLE includes the entire library).
2537- self.emcc('browser/test_sdl2_misc.c', ['-sLINKABLE', '-Wno-deprecated ', '-sUSE_SDL=2'], output_filename='a.out.js')
2538- self.emcc('browser/test_sdl2_misc.c', ['-sLINKABLE', '-Wno-deprecated ', '--use-port=sdl2'], output_filename='a.out.js')
2536+ # Ensure that SDL2 can be built with MAIN_MODULE . This implies there are no undefined
2537+ # symbols in the library (because MAIN_MODULE=1 includes the entire library).
2538+ self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE ', '-sUSE_SDL=2'], output_filename='a.out.js')
2539+ self.emcc('browser/test_sdl2_misc.c', ['-sMAIN_MODULE ', '--use-port=sdl2'], output_filename='a.out.js')
25392540
25402541 def test_sdl3_linkable(self):
2541- # Ensure that SDL3 can be built with LINKABLE . This implies there are no undefined
2542- # symbols in the library (because LINKABLE includes the entire library).
2542+ # Ensure that SDL3 can be built with MAIN_MODULE . This implies there are no undefined
2543+ # symbols in the library (because MAIN_MODULE=1 includes the entire library).
25432544 self.cflags.append('-Wno-experimental')
2544- self.emcc('browser/test_sdl3_misc.c', ['-sLINKABLE', '-Wno-deprecated ', '-sUSE_SDL=3'], output_filename='a.out.js')
2545- self.emcc('browser/test_sdl3_misc.c', ['-sLINKABLE', '-Wno-deprecated ', '--use-port=sdl3'], output_filename='a.out.js')
2545+ self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE ', '-sUSE_SDL=3'], output_filename='a.out.js')
2546+ self.emcc('browser/test_sdl3_misc.c', ['-sMAIN_MODULE ', '--use-port=sdl3'], output_filename='a.out.js')
25462547
25472548 @requires_network
25482549 def test_sdl2_gfx_linkable(self):
25492550 # Same as above but for sdl2_gfx library
2550- self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sLINKABLE', '-Wno-deprecated ', '-sUSE_SDL_GFX=2'], output_filename='a.out.js')
2551- self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sLINKABLE', '-Wno-deprecated ', '--use-port=sdl2_gfx'], output_filename='a.out.js')
2551+ self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE ', '-sUSE_SDL_GFX=2'], output_filename='a.out.js')
2552+ self.emcc('browser/test_sdl2_misc.c', ['-Wl,-fatal-warnings', '-sMAIN_MODULE ', '--use-port=sdl2_gfx'], output_filename='a.out.js')
25522553
25532554 @requires_network
25542555 def test_libpng(self):
@@ -5733,9 +5734,9 @@ def test_bad_function_pointer_cast(self, opts, wasm, safe):
57335734''')
57345735
57355736 for emulate_casts in (0, 1):
5736- for relocatable in (0, 1):
5737- # wasm2js is not compatible with relocatable mode
5738- if not wasm and relocatable :
5737+ for dylink in (0, 1):
5738+ # wasm2js is not compatible with dynamic linking
5739+ if dylink and not wasm :
57395740 continue
57405741 cmd = [EMXX, 'src.cpp'] + opts
57415742 if not wasm:
@@ -5744,8 +5745,8 @@ def test_bad_function_pointer_cast(self, opts, wasm, safe):
57445745 cmd += ['-sSAFE_HEAP']
57455746 if emulate_casts:
57465747 cmd += ['-sEMULATE_FUNCTION_POINTER_CASTS']
5747- if relocatable :
5748- cmd += ['-sRELOCATABLE '] # disables asm-optimized safe heap
5748+ if dylink :
5749+ cmd += ['-sMAIN_MODULE=2 '] # disables asm-optimized safe heap
57495750 print(cmd)
57505751 self.run_process(cmd)
57515752 returncode = 0 if emulate_casts or not wasm else NON_ZERO
@@ -12776,10 +12777,10 @@ def test_pthread_export_es6(self, args):
1277612777 self.assertContained('hello, world!', output)
1277712778
1277812779 def test_wasm2js_no_dylink(self):
12779- for arg in ('-sMAIN_MODULE', '-sSIDE_MODULE', '-sRELOCATABLE' ):
12780+ for arg in ('-sMAIN_MODULE', '-sSIDE_MODULE'):
1278012781 print(arg)
1278112782 err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM=0', arg])
12782- self.assertContained('emcc: error: WASM2JS is not compatible with RELOCATABLE ', err)
12783+ self.assertContained(r 'emcc: error: WASM2JS is not compatible with .*_MODULE \(wasm2js does not support dynamic linking\) ', err, regex=True )
1278312784
1278412785 def test_wasm2js_standalone(self):
1278512786 self.do_run_in_out_file_test('hello_world.c', cflags=['-sSTANDALONE_WASM', '-sWASM=0'])
@@ -13015,12 +13016,12 @@ def test_gen_struct_info_env(self):
1301513016 with env_modify({'EMCC_CFLAGS': '-O2 BAD_ARG', 'EMCC_FORCE_STDLIBS': '1', 'EMCC_ONLY_FORCED_STDLIBS': '1'}):
1301613017 self.run_process([PYTHON, path_from_root('tools/gen_struct_info.py'), '-o', 'out.json'])
1301713018
13018- def test_relocatable_limited_exports (self):
13019- # Building with RELOCATABLE should *not* automatically export all sybmols.
13020- self.run_process([EMCC, test_file('hello_world.c'), '-sRELOCATABLE ', '-o', 'out.wasm'])
13019+ def test_dylink_limited_exports (self):
13020+ # Building with MAIN_MODULE=2 should *not* automatically export all sybmols.
13021+ self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE=2 ', '-o', 'out.wasm'])
1302113022
13022- # Building with RELOCATABLE + LINKABLE should include and export all of the standard library
13023- self.run_process([EMCC, test_file('hello_world.c'), '-sRELOCATABLE', '-sLINKABLE ', '-o', 'out_linkable.wasm'])
13023+ # Building with MAIN_MODULE=1 should include and export all of the standard library
13024+ self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE ', '-o', 'out_linkable.wasm'])
1302413025
1302513026 exports = self.parse_wasm('out.wasm')[1]
1302613027 exports_linkable = self.parse_wasm('out_linkable.wasm')[1]
@@ -13211,18 +13212,13 @@ def test_reverse_deps_allow_undefined(self):
1321113212 ''')
1321213213 self.do_runf('test.c', cflags=['-sERROR_ON_UNDEFINED_SYMBOLS=0'])
1321313214
13214- @parameterized({
13215- 'relocatable': ('-sRELOCATABLE',),
13216- 'linkable': ('-sLINKABLE',),
13217- 'main_module': ('-sMAIN_MODULE',),
13218- })
13219- def test_check_undefined(self, flag):
13215+ def test_dylink_undefined(self):
1322013216 # positive case: no undefined symbols
13221- self.run_process([EMCC, flag, '-sERROR_ON_UNDEFINED_SYMBOLS ', test_file('hello_world.c')])
13217+ self.run_process([EMCC, '-sMAIN_MODULE ', test_file('hello_world.c')])
1322213218 self.run_js('a.out.js')
1322313219
1322413220 # negative case: foo is undefined in test_check_undefined.c
13225- err = self.expect_fail([EMCC, flag, '-sERROR_ON_UNDEFINED_SYMBOLS ', test_file('other/test_check_undefined.c')])
13221+ err = self.expect_fail([EMCC, '-sMAIN_MODULE ', test_file('other/test_check_undefined.c')])
1322613222 self.assertContained('undefined symbol: foo', err)
1322713223
1322813224 @also_with_wasm64
@@ -14125,7 +14121,7 @@ def test_wasm_worker_errors(self):
1412514121 self.assertContained('-sSINGLE_FILE is not supported with -sWASM_WORKERS', err)
1412614122 err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM_WORKERS', '-sPROXY_TO_WORKER'])
1412714123 self.assertContained('-sPROXY_TO_WORKER is not supported with -sWASM_WORKERS', err)
14128- err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM_WORKERS', '-sRELOCATABLE '])
14124+ err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sWASM_WORKERS', '-sMAIN_MODULE '])
1412914125 self.assertContained('dynamic linking is not supported with -sWASM_WORKERS', err)
1413014126
1413114127 def test_clock_nanosleep(self):
0 commit comments