Skip to content

Commit 1627d30

Browse files
committed
Allow arbitrary export names when not generating JS output
Fixes: #24413
1 parent f531731 commit 1627d30

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

test/test_other.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15983,7 +15983,11 @@ def test_cxx20_modules_std_headers(self):
1598315983
def test_invalid_export_name(self):
1598415984
create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}')
1598515985
err = self.expect_fail([EMCC, 'test.c'])
15986-
self.assertContained('emcc: error: invalid export name: my.func', err)
15986+
self.assertContained('emcc: error: invalid export name: _my.func', err)
15987+
15988+
# When we are generating only wasm and not JS we don't need exports to
15989+
# be valid JS symbols.
15990+
self.run_process([EMCC, 'test.c', '--no-entry', '-o', 'out.wasm'])
1598715991

1598815992
# GCC (and clang) and JavaScript also allow $ in symbol names
1598915993
create_file('valid.c', '''

tools/emscripten.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
365365
logger.debug('emscript: skipping js glue generation')
366366
return
367367

368+
for e in settings.EXPORTED_FUNCTIONS:
369+
if not is_valid_js_identifier(e):
370+
exit_with_error(f'invalid export name: {e}')
371+
368372
# memory and global initializers
369373

370374
if settings.RELOCATABLE:
@@ -570,9 +574,6 @@ def finalize_wasm(infile, outfile, js_syms):
570574
# These are any exports that were not requested on the command line and are
571575
# not known auto-generated system functions.
572576
unexpected_exports = [e for e in metadata.all_exports if shared.is_user_export(e)]
573-
for n in unexpected_exports:
574-
if not is_valid_js_identifier(n):
575-
exit_with_error(f'invalid export name: {n}')
576577
unexpected_exports = [asmjs_mangle(e) for e in unexpected_exports]
577578
unexpected_exports = [e for e in unexpected_exports if e not in expected_exports]
578579

0 commit comments

Comments
 (0)