Skip to content
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

Disallow exports that are not valid C/C++ identifiers #23563

Merged
merged 1 commit into from
Feb 3, 2025
Merged
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
5 changes: 5 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15539,3 +15539,8 @@ def test_cxx20_modules_std_headers(self):
}
''')
self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++20', '-fmodules'])

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)
3 changes: 3 additions & 0 deletions tools/emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ 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 treat_as_user_export(e)]
for n in unexpected_exports:
if not n.isidentifier():
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
2 changes: 1 addition & 1 deletion tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def is_c_symbol(name):


def treat_as_user_export(name):
return not name.startswith('dynCall_')
return not name.startswith(('dynCall_', 'orig$'))


def asmjs_mangle(name):
Expand Down