@@ -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'])
0 commit comments