Skip to content

Commit 8dc91db

Browse files
authored
Fix unexported symbol check for library symbols exported with EXPORTED_FUNCTIONS (#24091)
This bug meant that library symbol exported via `EXPORTED_FUNCTIONS` were incorrectly being reported as not exported using unexportedRuntimeSymbol See #24086
1 parent a18be62 commit 8dc91db

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/modules.mjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,11 @@ function exportRuntimeSymbols() {
537537

538538
const unexported = [];
539539
for (const name of runtimeElements) {
540-
if (!EXPORTED_RUNTIME_METHODS.has(name) && !unusedLibSymbols.has(name)) {
540+
if (
541+
!EXPORTED_RUNTIME_METHODS.has(name) &&
542+
!EXPORTED_FUNCTIONS.has(name) &&
543+
!unusedLibSymbols.has(name)
544+
) {
541545
unexported.push(name);
542546
}
543547
}

test/test_other.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -4139,6 +4139,13 @@ def test_exported_runtime_methods_from_js_library(self):
41394139
''')
41404140
self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_RUNTIME_METHODS=ptrToString'])
41414141

4142+
# Same again but using EXPORTED_FUNCTIONS instead.
4143+
self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_FUNCTIONS=ptrToString,_main'])
4144+
4145+
# Check that when ptrToString is not exported we get a reasonable error message
4146+
err = self.do_runf('hello_world.c', assert_returncode=NON_ZERO, emcc_args=['--pre-js=pre.js'])
4147+
self.assertContained("Aborted('ptrToString' was not exported. add it to EXPORTED_RUNTIME_METHODS", err)
4148+
41424149
@crossplatform
41434150
def test_fs_stream_proto(self):
41444151
create_file('src.c', br'''
@@ -4943,8 +4950,8 @@ def test_jslib_exported_functions(self):
49434950
$Foo: () => 43,
49444951
});
49454952
''')
4946-
self.run_process([EMCC, test_file('hello_world.c'), '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=Foo,_main'])
4947-
self.assertContained("Module['Foo'] = ", read_file('a.out.js'))
4953+
create_file('post.js', 'console.log("Foo:", Module.Foo())')
4954+
self.do_runf(test_file('hello_world.c'), emcc_args=['--post-js=post.js', '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=Foo,_main'])
49484955

49494956
def test_jslib_search_path(self):
49504957
create_file('libfoo.js', '''

0 commit comments

Comments
 (0)