Skip to content

Commit 7e808f1

Browse files
authored
Skip final JS compiler step when only building wasm. NFC (#20970)
The early return was originally delayed in #12729 since we wanted to be able to report undefined symbols based on JS library contents, but since we now pass JS library information into wasm-ld all the undefined symbol reporting is done there. See #21026
1 parent 3d4cf73 commit 7e808f1

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

test/test_other.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,25 +2371,43 @@ def test_link_memcpy(self):
23712371
''', output)
23722372
self.assertNotContained('warning: library.js memcpy should not be running, it is only for testing!', output)
23732373

2374-
def test_undefined_exported_function(self):
2375-
cmd = [EMCC, test_file('hello_world.c')]
2374+
@parameterized({
2375+
'': ('out.js',),
2376+
'standalone': ('out.wasm',)
2377+
})
2378+
def test_undefined_exported_function(self, outfile):
2379+
cmd = [EMCC, test_file('hello_world.c'), '-o', outfile]
23762380
self.run_process(cmd)
23772381

2378-
# adding a missing symbol to EXPORTED_FUNCTIONS should cause failure
2382+
# Adding a missing symbol to EXPORTED_FUNCTIONS should cause a link failure
23792383
cmd += ['-sEXPORTED_FUNCTIONS=_foobar']
23802384
err = self.expect_fail(cmd)
23812385
self.assertContained('wasm-ld: error: symbol exported via --export not found: foobar', err)
23822386

2383-
def test_undefined_exported_js_function(self):
2384-
cmd = [EMXX, test_file('hello_world.cpp')]
2387+
# Adding -sERROR_ON_UNDEFINED_SYMBOLS=0 means the error gets reported later
2388+
# by emscripten.py.
2389+
cmd += ['-sERROR_ON_UNDEFINED_SYMBOLS=0']
2390+
err = self.expect_fail(cmd)
2391+
self.assertContained('undefined exported symbol: "_foobar"', err)
2392+
2393+
# setting `-Wno-undefined` should suppress the error
2394+
cmd += ['-Wno-undefined']
2395+
self.run_process(cmd)
2396+
2397+
@parameterized({
2398+
'': ('out.js',),
2399+
'standalone': ('out.wasm',)
2400+
})
2401+
def test_undefined_exported_js_function(self, outfile):
2402+
cmd = [EMXX, test_file('hello_world.cpp'), '-o', outfile]
23852403
self.run_process(cmd)
23862404

23872405
# adding a missing symbol to EXPORTED_FUNCTIONS should cause failure
23882406
cmd += ['-sEXPORTED_FUNCTIONS=foobar']
23892407
err = self.expect_fail(cmd)
23902408
self.assertContained('undefined exported symbol: "foobar"', err)
23912409

2392-
# setting `-Wno-undefined` should suppress error
2410+
# setting `-Wno-undefined` should suppress the error
23932411
cmd += ['-Wno-undefined']
23942412
self.run_process(cmd)
23952413

tools/diagnostics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def disable_warning(name):
242242
manager.warnings[name]['enabled'] = False
243243

244244

245+
def is_enabled(name):
246+
return manager.warnings[name]['enabled']
247+
248+
245249
def warning(warning_type, message, *args):
246250
manager.warning(warning_type, message, *args)
247251

tools/emscripten.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,22 @@ def set_memory(static_bump):
210210
settings.HEAP_BASE = align_memory(stack_high)
211211

212212

213-
def report_missing_symbols(js_symbols):
214-
# Report any symbol that was explicitly exported but is present neither
215-
# as a native function nor as a JS library function.
216-
defined_symbols = set(asmjs_mangle(e) for e in settings.WASM_EXPORTS).union(js_symbols)
217-
missing = set(settings.USER_EXPORTED_FUNCTIONS) - defined_symbols
218-
for symbol in sorted(missing):
219-
diagnostics.warning('undefined', f'undefined exported symbol: "{symbol}"')
213+
def report_missing_exports_wasm_only(metadata):
214+
if diagnostics.is_enabled('undefined'):
215+
defined_symbols = set(asmjs_mangle(e) for e in metadata.all_exports)
216+
missing = set(settings.USER_EXPORTED_FUNCTIONS) - defined_symbols
217+
for symbol in sorted(missing):
218+
diagnostics.warning('undefined', f'undefined exported symbol: "{symbol}"')
219+
220+
221+
def report_missing_exports(js_symbols):
222+
if diagnostics.is_enabled('undefined'):
223+
# Report any symbol that was explicitly exported but is present neither
224+
# as a native function nor as a JS library function.
225+
defined_symbols = set(asmjs_mangle(e) for e in settings.WASM_EXPORTS).union(js_symbols)
226+
missing = set(settings.USER_EXPORTED_FUNCTIONS) - defined_symbols
227+
for symbol in sorted(missing):
228+
diagnostics.warning('undefined', f'undefined exported symbol: "{symbol}"')
220229

221230
# Special hanlding for the `_main` symbol
222231

@@ -359,7 +368,9 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True):
359368
if proc.returncode:
360369
exit_with_error(f'EM_JS function validation failed (node returned {proc.returncode})')
361370

362-
logger.debug('emscript: skipping remaining js glue generation')
371+
if not outfile_js:
372+
report_missing_exports_wasm_only(metadata)
373+
logger.debug('emscript: skipping js glue generation')
363374
return
364375

365376
# memory and global initializers
@@ -398,11 +409,7 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True):
398409
pre += f" ignoredModuleProp('{sym}');\n"
399410
pre += "}\n"
400411

401-
report_missing_symbols(forwarded_json['librarySymbols'])
402-
403-
if not outfile_js:
404-
logger.debug('emscript: skipping remaining js glue generation')
405-
return
412+
report_missing_exports(forwarded_json['librarySymbols'])
406413

407414
if settings.MINIMAL_RUNTIME:
408415
# In MINIMAL_RUNTIME, atinit exists in the postamble part

0 commit comments

Comments
 (0)