Skip to content

Allow arbitrary export names when not generating JS output #24427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15983,7 +15983,11 @@ def test_cxx20_modules_std_headers(self):
def test_invalid_export_name(self):
create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}')
err = self.expect_fail([EMCC, 'test.c'])
self.assertContained('emcc: error: invalid export name: my.func', err)
self.assertContained('emcc: error: invalid export name: _my.func', err)

# When we are generating only wasm and not JS we don't need exports to
# be valid JS symbols.
self.run_process([EMCC, 'test.c', '--no-entry', '-o', 'out.wasm'])

# GCC (and clang) and JavaScript also allow $ in symbol names
create_file('valid.c', '''
Expand Down
7 changes: 4 additions & 3 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
logger.debug('emscript: skipping js glue generation')
return

for e in settings.EXPORTED_FUNCTIONS:
if not is_valid_js_identifier(e):
exit_with_error(f'invalid export name: {e}')

# memory and global initializers

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

Expand Down