Skip to content

Fix unexported symbol check for library symbols exported with EXPORTED_FUNCTIONS #24091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,11 @@ function exportRuntimeSymbols() {

const unexported = [];
for (const name of runtimeElements) {
if (!EXPORTED_RUNTIME_METHODS.has(name) && !unusedLibSymbols.has(name)) {
if (
!EXPORTED_RUNTIME_METHODS.has(name) &&
!EXPORTED_FUNCTIONS.has(name) &&
!unusedLibSymbols.has(name)
) {
unexported.push(name);
}
}
Expand Down
11 changes: 9 additions & 2 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -4139,6 +4139,13 @@ def test_exported_runtime_methods_from_js_library(self):
''')
self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_RUNTIME_METHODS=ptrToString'])

# Same again but using EXPORTED_FUNCTIONS instead.
self.do_runf('hello_world.c', 'done', emcc_args=['--pre-js=pre.js', '-sEXPORTED_FUNCTIONS=ptrToString,_main'])

# Check that when ptrToString is not exported we get a reasonable error message
err = self.do_runf('hello_world.c', assert_returncode=NON_ZERO, emcc_args=['--pre-js=pre.js'])
self.assertContained("Aborted('ptrToString' was not exported. add it to EXPORTED_RUNTIME_METHODS", err)

@crossplatform
def test_fs_stream_proto(self):
create_file('src.c', br'''
Expand Down Expand Up @@ -4943,8 +4950,8 @@ def test_jslib_exported_functions(self):
$Foo: () => 43,
});
''')
self.run_process([EMCC, test_file('hello_world.c'), '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=Foo,_main'])
self.assertContained("Module['Foo'] = ", read_file('a.out.js'))
create_file('post.js', 'console.log("Foo:", Module.Foo())')
self.do_runf(test_file('hello_world.c'), emcc_args=['--post-js=post.js', '--js-library=lib.js', '-sEXPORTED_FUNCTIONS=Foo,_main'])

def test_jslib_search_path(self):
create_file('libfoo.js', '''
Expand Down