Skip to content

Commit 08d2cc3

Browse files
authored
Disallow exports that are not valid C/C++ identifiers (#23563)
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
1 parent 92d0bb5 commit 08d2cc3

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15539,3 +15539,8 @@ def test_cxx20_modules_std_headers(self):
1553915539
}
1554015540
''')
1554115541
self.do_runf('main.cpp', 'Hello Module!', emcc_args=['-std=c++20', '-fmodules'])
15542+
15543+
def test_invalid_export_name(self):
15544+
create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}')
15545+
err = self.expect_fail([EMCC, 'test.c'])
15546+
self.assertContained('emcc: error: invalid export name: my.func', err)

tools/emscripten.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ def finalize_wasm(infile, outfile, js_syms):
578578
# These are any exports that were not requested on the command line and are
579579
# not known auto-generated system functions.
580580
unexpected_exports = [e for e in metadata.all_exports if treat_as_user_export(e)]
581+
for n in unexpected_exports:
582+
if not n.isidentifier():
583+
exit_with_error(f'invalid export name: {n}')
581584
unexpected_exports = [asmjs_mangle(e) for e in unexpected_exports]
582585
unexpected_exports = [e for e in unexpected_exports if e not in expected_exports]
583586

tools/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def is_c_symbol(name):
651651

652652

653653
def treat_as_user_export(name):
654-
return not name.startswith('dynCall_')
654+
return not name.startswith(('dynCall_', 'orig$'))
655655

656656

657657
def asmjs_mangle(name):

0 commit comments

Comments
 (0)