Skip to content

Commit 0e460d7

Browse files
committed
Allow arbitrary export names when not generating JS output
Fixes: #24413
1 parent d8b2324 commit 0e460d7

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

test/test_other.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5806,13 +5806,13 @@ def test_bad_function_pointer_cast(self, opts, wasm, safe):
58065806
self.assertContained('function signature mismatch', output)
58075807

58085808
def test_bad_export(self):
5809-
for m in ('', ' '):
5809+
for exports in ('_main', '_main,foo'):
58105810
self.clear()
5811-
cmd = [EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=["' + m + '_main"]']
5811+
cmd = [EMCC, test_file('hello_world.c'), f'-sEXPORTED_FUNCTIONS={exports}']
58125812
print(cmd)
58135813
stderr = self.run_process(cmd, stderr=PIPE, check=False).stderr
5814-
if m:
5815-
self.assertContained('undefined exported symbol: " _main"', stderr)
5814+
if 'foo' in exports:
5815+
self.assertContained('undefined exported symbol: "foo"', stderr)
58165816
else:
58175817
self.assertContained('hello, world!', self.run_js('a.out.js'))
58185818

@@ -11390,13 +11390,13 @@ def test_dash_s_list_parsing(self):
1139011390
# Simple one-per-line response file format
1139111391
1139211392
# stray slash
11393-
("EXPORTED_FUNCTIONS=['_a', '_b', \\'_c', '_d']", '''undefined exported symbol: "\\\\'_c'"'''),
11393+
("EXPORTED_FUNCTIONS=['_a', '_b', \\'_c', '_d']", '''invalid export name: "\\\\'_c'"'''),
1139411394
# stray slash
11395-
("EXPORTED_FUNCTIONS=['_a', '_b',\\ '_c', '_d']", '''undefined exported symbol: "\\\\ '_c'"'''),
11395+
("EXPORTED_FUNCTIONS=['_a', '_b',\\ '_c', '_d']", '''invalid export name: "\\\\ '_c'"'''),
1139611396
# stray slash
11397-
('EXPORTED_FUNCTIONS=["_a", "_b", \\"_c", "_d"]', 'undefined exported symbol: "\\\\"_c""'),
11397+
('EXPORTED_FUNCTIONS=["_a", "_b", \\"_c", "_d"]', 'invalid export name: "\\\\"_c""'),
1139811398
# stray slash
11399-
('EXPORTED_FUNCTIONS=["_a", "_b",\\ "_c", "_d"]', 'undefined exported symbol: "\\\\ "_c"'),
11399+
('EXPORTED_FUNCTIONS=["_a", "_b",\\ "_c", "_d"]', 'invalid export name: "\\\\ "_c"'),
1140011400
# missing comma
1140111401
('EXPORTED_FUNCTIONS=["_a", "_b" "_c", "_d"]', 'wasm-ld: error: symbol exported via --export not found: b" "_c'),
1140211402
]:
@@ -16143,7 +16143,11 @@ def test_cxx20_modules_std_headers(self):
1614316143
def test_invalid_export_name(self):
1614416144
create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}')
1614516145
err = self.expect_fail([EMCC, 'test.c'])
16146-
self.assertContained('emcc: error: invalid export name: "my.func"', err)
16146+
self.assertContained('emcc: error: invalid export name: "_my.func"', err)
16147+
16148+
# When we are generating only wasm and not JS we don't need exports to
16149+
# be valid JS symbols.
16150+
self.run_process([EMCC, 'test.c', '--no-entry', '-o', 'out.wasm'])
1614716151

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

tools/emscripten.py

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

367+
for e in settings.EXPORTED_FUNCTIONS:
368+
if not js_manipulation.isidentifier(e):
369+
exit_with_error(f'invalid export name: "{e}"')
370+
367371
# memory and global initializers
368372

369373
if settings.RELOCATABLE:
@@ -562,9 +566,6 @@ def finalize_wasm(infile, outfile, js_syms):
562566
# These are any exports that were not requested on the command line and are
563567
# not known auto-generated system functions.
564568
unexpected_exports = [e for e in metadata.all_exports if shared.is_user_export(e)]
565-
for n in unexpected_exports:
566-
if not js_manipulation.isidentifier(n):
567-
exit_with_error(f'invalid export name: "{n}"')
568569
unexpected_exports = [asmjs_mangle(e) for e in unexpected_exports]
569570
unexpected_exports = [e for e in unexpected_exports if e not in expected_exports]
570571

0 commit comments

Comments
 (0)