Skip to content

Commit

Permalink
Disallow exports that are not valid C/C++ identifiers
Browse files Browse the repository at this point in the history
I use `std.isdentifier()` here from python since it has the same rules
for valid identifiers are C/C++.

We could try instead to allow this but I'm not sure it worth it given
that our inputs are almost exclusively compiled from C/C++/rust.

See #23560
  • Loading branch information
sbc100 committed Jan 31, 2025
1 parent 1a1c303 commit 6015bc4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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

0 comments on commit 6015bc4

Please sign in to comment.