Skip to content

Commit 27c3512

Browse files
authored
Allow arbitrary export names when not generating JS output (#24427)
Fixes: #24413
1 parent 2191239 commit 27c3512

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
@@ -5801,13 +5801,13 @@ def test_bad_function_pointer_cast(self, opts, wasm, safe):
58015801
self.assertContained('function signature mismatch', output)
58025802

58035803
def test_bad_export(self):
5804-
for m in ('', ' '):
5804+
for exports in ('_main', '_main,foo'):
58055805
self.clear()
5806-
cmd = [EMCC, test_file('hello_world.c'), '-sEXPORTED_FUNCTIONS=["' + m + '_main"]']
5806+
cmd = [EMCC, test_file('hello_world.c'), f'-sEXPORTED_FUNCTIONS={exports}']
58075807
print(cmd)
58085808
stderr = self.run_process(cmd, stderr=PIPE, check=False).stderr
5809-
if m:
5810-
self.assertContained('undefined exported symbol: " _main"', stderr)
5809+
if 'foo' in exports:
5810+
self.assertContained('undefined exported symbol: "foo"', stderr)
58115811
else:
58125812
self.assertContained('hello, world!', self.run_js('a.out.js'))
58135813

@@ -11350,13 +11350,13 @@ def test_dash_s_list_parsing(self):
1135011350
# Simple one-per-line response file format
1135111351
1135211352
# stray slash
11353-
("EXPORTED_FUNCTIONS=['_a', '_b', \\'_c', '_d']", '''undefined exported symbol: "\\\\'_c'"'''),
11353+
("EXPORTED_FUNCTIONS=['_a', '_b', \\'_c', '_d']", '''invalid export name: "\\\\'_c'"'''),
1135411354
# stray slash
11355-
("EXPORTED_FUNCTIONS=['_a', '_b',\\ '_c', '_d']", '''undefined exported symbol: "\\\\ '_c'"'''),
11355+
("EXPORTED_FUNCTIONS=['_a', '_b',\\ '_c', '_d']", '''invalid export name: "\\\\ '_c'"'''),
1135611356
# stray slash
11357-
('EXPORTED_FUNCTIONS=["_a", "_b", \\"_c", "_d"]', 'undefined exported symbol: "\\\\"_c""'),
11357+
('EXPORTED_FUNCTIONS=["_a", "_b", \\"_c", "_d"]', 'invalid export name: "\\\\"_c""'),
1135811358
# stray slash
11359-
('EXPORTED_FUNCTIONS=["_a", "_b",\\ "_c", "_d"]', 'undefined exported symbol: "\\\\ "_c"'),
11359+
('EXPORTED_FUNCTIONS=["_a", "_b",\\ "_c", "_d"]', 'invalid export name: "\\\\ "_c"'),
1136011360
# missing comma
1136111361
('EXPORTED_FUNCTIONS=["_a", "_b" "_c", "_d"]', 'wasm-ld: error: symbol exported via --export not found: b" "_c'),
1136211362
]:
@@ -16114,7 +16114,11 @@ def test_cxx20_modules_std_headers(self):
1611416114
def test_invalid_export_name(self):
1611516115
create_file('test.c', '__attribute__((export_name("my.func"))) void myfunc() {}')
1611616116
err = self.expect_fail([EMCC, 'test.c'])
16117-
self.assertContained('emcc: error: invalid export name: "my.func"', err)
16117+
self.assertContained('emcc: error: invalid export name: "_my.func"', err)
16118+
16119+
# When we are generating only wasm and not JS we don't need exports to
16120+
# be valid JS symbols.
16121+
self.run_process([EMCC, 'test.c', '--no-entry', '-o', 'out.wasm'])
1611816122

1611916123
# GCC (and clang) and JavaScript also allow $ in symbol names
1612016124
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)