Skip to content

Commit 152c205

Browse files
committed
fix more tests, use explicit need_name_section in finalize
1 parent 5d13302 commit 152c205

File tree

5 files changed

+62
-59
lines changed

5 files changed

+62
-59
lines changed

src/shell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var Module = typeof {{{ EXPORT_NAME }}} != 'undefined' ? {{{ EXPORT_NAME }}} : {
5050
#endif
5151

5252
#if WASM_BIGINT && MIN_SAFARI_VERSION < 140100
53-
// TODO: Fix this back to 150000
53+
// TODO(features): Fix this back to 150000
5454
// See https://caniuse.com/mdn-javascript_builtins_bigint64array
5555
#include "polyfill/bigint64array.js"
5656
#endif

test/test_other.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,7 +2960,7 @@ def test_emcc_debug_files(self):
29602960
self.assertFalse(os.path.exists(self.canonical_temp_dir))
29612961
else:
29622962
print(sorted(os.listdir(self.canonical_temp_dir)))
2963-
self.assertExists(os.path.join(self.canonical_temp_dir, 'emcc-03-original.js'))
2963+
self.assertExists(os.path.join(self.canonical_temp_dir, 'emcc-02-original.js'))
29642964

29652965
def test_debuginfo_line_tables_only(self):
29662966
def test(do_compile):
@@ -3504,10 +3504,10 @@ def test_embind_tsgen_val(self):
35043504
def test_embind_tsgen_bigint(self):
35053505
args = [EMXX, test_file('other/embind_tsgen_bigint.cpp'), '-lembind', '--emit-tsd', 'embind_tsgen_bigint.d.ts']
35063506
# Check that TypeScript generation fails when code contains bigints but their support is not enabled
3507-
stderr = self.expect_fail(args)
3507+
stderr = self.expect_fail(args + ['-sWASM_BIGINT=0'])
35083508
self.assertContained("Missing primitive type to TS type for 'int64_t", stderr)
35093509
# Check that TypeScript generation works when bigint support is enabled
3510-
self.run_process(args + ['-sWASM_BIGINT'])
3510+
self.run_process(args)
35113511
self.assertFileContents(test_file('other/embind_tsgen_bigint.d.ts'), read_file('embind_tsgen_bigint.d.ts'))
35123512

35133513
@requires_wasm64
@@ -8013,8 +8013,8 @@ def test_malloc_multithreading(self, allocator, args):
80138013
self.do_other_test('test_malloc_multithreading.cpp', emcc_args=args)
80148014

80158015
@parameterized({
8016-
'': ([], 'testbind.js'),
8017-
'bigint': (['-sWASM_BIGINT'], 'testbind_bigint.js'),
8016+
'': ([], 'testbind_bigint.js'),
8017+
'nobigint': (['-sWASM_BIGINT=0'], 'testbind.js'),
80188018
})
80198019
@requires_node
80208020
def test_i64_return_value(self, args, bind_js):
@@ -8510,7 +8510,7 @@ def test_binaryen_warn_mem(self):
85108510
self.run_process([EMCC, test_file('hello_world.c'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY'])
85118511
out = self.run_js('a.out.js', assert_returncode=NON_ZERO)
85128512
self.assertContained('LinkError', out)
8513-
self.assertContained("memory import 2 has a larger maximum size 800 than the module's declared maximum", out)
8513+
self.assertContained("memory import 1 has a larger maximum size 800 than the module's declared maximum", out)
85148514
self.assertNotContained('hello, world!', out)
85158515
# and with memory growth, all should be good
85168516
self.run_process([EMCC, test_file('hello_world.c'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sALLOW_MEMORY_GROWTH', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY'])
@@ -8934,39 +8934,39 @@ def test_exported_runtime_methods_metadce(self, use_legacy_name):
89348934
for export in exports:
89358935
self.assertContained(f'Module["{export}"]', js)
89368936

8937-
def test_legalize_js_ffi(self):
8938-
# test disabling of JS FFI legalization
8939-
for (args, js_ffi) in [
8940-
(['-sLEGALIZE_JS_FFI=1', '-sSIDE_MODULE', '-O1'], True),
8941-
(['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O1'], False),
8942-
(['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O0'], False),
8943-
(['-sLEGALIZE_JS_FFI=1', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], True),
8944-
(['-sLEGALIZE_JS_FFI=0', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], False),
8945-
]:
8946-
print(args)
8947-
delete_file('a.out.wasm')
8948-
cmd = [EMCC, test_file('other/ffi.c'), '-g', '-o', 'a.out.wasm'] + args
8949-
print(' '.join(cmd))
8950-
self.run_process(cmd)
8951-
text = self.get_wasm_text('a.out.wasm')
8952-
# remove internal comments and extra whitespace
8953-
text = re.sub(r'\(;[^;]+;\)', '', text)
8954-
text = re.sub(r'\$var\$*.', '', text)
8955-
text = re.sub(r'param \$\d+', 'param ', text)
8956-
text = re.sub(r' +', ' ', text)
8957-
e_add_f32 = re.search(r'func \$add_f \(param f32\) \(param f32\) \(result f32\)', text)
8958-
assert e_add_f32, 'add_f export missing'
8959-
i_i64_i32 = re.search(r'import "env" "import_ll" .*\(param i32 i32\) \(result i32\)', text)
8960-
i_i64_i64 = re.search(r'import "env" "import_ll" .*\(param i64\) \(result i64\)', text)
8961-
e_i64_i32 = re.search(r'func \$legalstub\$add_ll \(param i32\) \(param i32\) \(param i32\) \(param i32\) \(result i32\)', text)
8962-
if js_ffi:
8963-
assert i_i64_i32, 'i64 not converted to i32 in imports'
8964-
assert not i_i64_i64, 'i64 not converted to i32 in imports'
8965-
assert e_i64_i32, 'i64 not converted to i32 in exports'
8966-
else:
8967-
assert not i_i64_i32, 'i64 converted to i32 in imports'
8968-
assert i_i64_i64, 'i64 converted to i32 in imports'
8969-
assert not e_i64_i32, 'i64 converted to i32 in exports'
8937+
@parameterized({
8938+
'legal_side_O1': (['-sLEGALIZE_JS_FFI=1', '-sSIDE_MODULE', '-O1'], True),
8939+
'nolegal_side_O1': (['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O1'], False),
8940+
'nolegal_side_O0': (['-sLEGALIZE_JS_FFI=0', '-sSIDE_MODULE', '-O0'], False),
8941+
'legal_O0': (['-sLEGALIZE_JS_FFI=1', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], True),
8942+
'nolegal_O0': (['-sLEGALIZE_JS_FFI=0', '-sWARN_ON_UNDEFINED_SYMBOLS=0', '-O0'], False),
8943+
})
8944+
def test_legalize_js_ffi(self, args, js_ffi):
8945+
# test disabling of JS FFI legalization when not using bigint
8946+
print(args)
8947+
delete_file('a.out.wasm')
8948+
cmd = [EMCC, test_file('other/ffi.c'), '-g', '-o', 'a.out.wasm', '-sWASM_BIGINT=0'] + args
8949+
print(' '.join(cmd))
8950+
self.run_process(cmd)
8951+
text = self.get_wasm_text('a.out.wasm')
8952+
# remove internal comments and extra whitespace
8953+
text = re.sub(r'\(;[^;]+;\)', '', text)
8954+
text = re.sub(r'\$var\$*.', '', text)
8955+
text = re.sub(r'param \$\d+', 'param ', text)
8956+
text = re.sub(r' +', ' ', text)
8957+
e_add_f32 = re.search(r'func \$add_f \(param f32\) \(param f32\) \(result f32\)', text)
8958+
assert e_add_f32, 'add_f export missing'
8959+
i_i64_i32 = re.search(r'import "env" "import_ll" .*\(param i32 i32\) \(result i32\)', text)
8960+
i_i64_i64 = re.search(r'import "env" "import_ll" .*\(param i64\) \(result i64\)', text)
8961+
e_i64_i32 = re.search(r'func \$legalstub\$add_ll \(param i32\) \(param i32\) \(param i32\) \(param i32\) \(result i32\)', text)
8962+
if js_ffi:
8963+
assert i_i64_i32, 'i64 not converted to i32 in imports'
8964+
assert not i_i64_i64, 'i64 not converted to i32 in imports'
8965+
assert e_i64_i32, 'i64 not converted to i32 in exports'
8966+
else:
8967+
assert not i_i64_i32, 'i64 converted to i32 in imports'
8968+
assert i_i64_i64, 'i64 converted to i32 in imports'
8969+
assert not e_i64_i32, 'i64 converted to i32 in exports'
89708970

89718971
@disabled('https://github.com/WebAssembly/binaryen/pull/6428')
89728972
def test_no_legalize_js_ffi(self):
@@ -11478,13 +11478,13 @@ def test(code):
1147811478
print(f'int:{i} float:{f} double:{lf}: both{both}')
1147911479

1148011480
# iprintf is much smaller than printf with float support
11481-
self.assertGreater(i, f - 3500)
11481+
self.assertGreater(i, f - 3800)
1148211482
self.assertLess(i, f - 3000)
1148311483
# __small_printf is somewhat smaller than printf with long double support
1148411484
self.assertGreater(f, lf - 900)
1148511485
self.assertLess(f, lf - 500)
1148611486
# both is a little bigger still
11487-
self.assertGreater(lf, both - 110)
11487+
self.assertGreater(lf, both - 150)
1148811488
self.assertLess(lf, both - 50)
1148911489

1149011490
@parameterized({
@@ -12347,19 +12347,18 @@ def ok(args, filename='hello_world.cpp', expected='hello, world!'):
1234712347
args += ['-sERROR_ON_WASM_CHANGES_AFTER_LINK']
1234812348
self.do_runf(filename, expected, emcc_args=args)
1234912349

12350-
# -O0 with BigInt support (to avoid the need for legalization)
12351-
required_flags = ['-sWASM_BIGINT']
12352-
ok(required_flags)
12350+
# -O0 with BigInt support (now on by default)
12351+
ok([])
1235312352
# Same with DWARF
12354-
ok(required_flags + ['-g'])
12353+
ok(['-g'])
1235512354
# Function pointer calls from JS work too
12356-
ok(required_flags, filename='hello_world_main_loop.cpp')
12355+
ok([], filename='hello_world_main_loop.cpp')
1235712356
# -O1 is ok as we don't run wasm-opt there (but no higher, see below)
12358-
ok(required_flags + ['-O1'])
12357+
ok(['-O1'])
1235912358
# Exception support shouldn't require changes after linking
12360-
ok(required_flags + ['-fexceptions'])
12359+
ok(['-fexceptions'])
1236112360
# Standalone mode should not do anything special to the wasm.
12362-
ok(required_flags + ['-sSTANDALONE_WASM'])
12361+
ok(['-sSTANDALONE_WASM'])
1236312362

1236412363
# other builds fail with a standard message + extra details
1236512364
def fail(args, details):
@@ -12371,12 +12370,12 @@ def fail(args, details):
1237112370

1237212371
# plain -O0
1237312372
legalization_message = 'to disable int64 legalization (which requires changes after link) use -sWASM_BIGINT'
12374-
fail([], legalization_message)
12375-
fail(['-sMIN_SAFARI_VERSION=140100'], legalization_message)
12373+
fail(['-sWASM_BIGINT=0'], legalization_message)
12374+
fail(['-sMIN_SAFARI_VERSION=140000'], legalization_message) # TODO(features): change this back to 140100 after 15 is default
1237612375
# optimized builds even without legalization
1237712376
optimization_message = '-O2+ optimizations always require changes, build with -O0 or -O1 instead'
12378-
fail(required_flags + ['-O2'], optimization_message)
12379-
fail(required_flags + ['-O3'], optimization_message)
12377+
fail(['-O2'], optimization_message)
12378+
fail(['-O3'], optimization_message)
1238012379

1238112380
@crossplatform
1238212381
def test_output_to_nowhere(self):
@@ -14471,7 +14470,8 @@ def test_reproduce(self):
1447114470

1447214471
def test_min_browser_version(self):
1447314472
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-Wno-transpile', '-Werror', '-sWASM_BIGINT', '-sMIN_SAFARI_VERSION=120000'])
14474-
self.assertContained('emcc: error: MIN_SAFARI_VERSION=120000 is not compatible with WASM_BIGINT (150000 or above required)', err)
14473+
# TODO(features): fix back to 15000 once Safari 15 is default
14474+
self.assertContained('emcc: error: MIN_SAFARI_VERSION=120000 is not compatible with WASM_BIGINT (140100 or above required)', err)
1447514475

1447614476
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-Wno-transpile', '-Werror', '-pthread', '-sMIN_CHROME_VERSION=73'])
1447714477
self.assertContained('emcc: error: MIN_CHROME_VERSION=73 is not compatible with pthreads (74 or above required)', err)

tools/emscripten.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,14 @@ def finalize_wasm(infile, outfile, js_syms):
499499

500500
# if we don't need to modify the wasm, don't tell finalize to emit a wasm file
501501
modify_wasm = False
502+
need_name_section = False
502503

503504
if settings.WASM2JS:
504505
# wasm2js requires full legalization (and will do extra wasm binary
505506
# later processing later anyhow)
506507
modify_wasm = True
507508
if settings.DEBUG_LEVEL >= 2 or settings.ASYNCIFY_ADD or settings.ASYNCIFY_ADVISE or settings.ASYNCIFY_ONLY or settings.ASYNCIFY_REMOVE or settings.EMIT_SYMBOL_MAP or settings.EMIT_NAME_SECTION:
509+
need_name_section = True
508510
args.append('-g')
509511
if settings.WASM_BIGINT:
510512
args.append('--bigint')
@@ -566,11 +568,12 @@ def finalize_wasm(infile, outfile, js_syms):
566568
infile]
567569
shared.check_call(cmd)
568570

569-
# For sections we no longer need, strip now to speed subsequent passes
571+
# For sections we no longer need, strip now to speed subsequent passes.
572+
# If Binaryen is not needed, this is also our last chance to strip.
570573
strip_sections = []
571574
if not settings.EMIT_PRODUCERS_SECTION:
572575
strip_sections += ['producers']
573-
if not settings.EMIT_NAME_SECTION:
576+
if not need_name_section:
574577
strip_sections += ['name']
575578

576579
if strip_sections or not settings.GENERATE_DWARF:

tools/feature_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Feature(IntEnum):
6666
Feature.JS_BIGINT_INTEGRATION: {
6767
'chrome': 67,
6868
'firefox': 68,
69-
'safari': 140100, # TODO: set this back to 15 after we update the default targets.
69+
'safari': 140100, # TODO(features): set this back to 15 after we update the default targets.
7070
},
7171
Feature.THREADS: {
7272
'chrome': 74,

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ def get_full_import_name(name):
17571757
exit_with_error('wasm2js does not support source maps yet (debug in wasm for now)')
17581758
if settings.MEMORY64:
17591759
exit_with_error('wasm2js does not support MEMORY64')
1760-
if settings.WASM_BIGINT:
1760+
if settings.WASM_BIGINT and 'WASM_BIGINT' in user_settings:
17611761
exit_with_error('wasm2js does not support WASM_BIGINT')
17621762
if settings.CAN_ADDRESS_2GB:
17631763
exit_with_error('wasm2js does not support >2gb address space')

0 commit comments

Comments
 (0)