Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
742a3e6
Fix nested dependencies handling in rpath
ryanking13 May 1, 2025
f1f85ff
fallback
ryanking13 May 1, 2025
65f39d4
syntax
ryanking13 May 1, 2025
8bc8fff
Automatic rebaseline of codesize expectations. NFC
ryanking13 May 1, 2025
3fb1ddd
Merge remote-tracking branch 'upstream/main' into rpath-nested-deps
ryanking13 May 2, 2025
62dc4a4
wasm ==> so
ryanking13 May 2, 2025
81b1dbd
Always pass absolute path in loadDynamicLibrary
ryanking13 May 2, 2025
f4e3b25
Remove unnecessary changes
ryanking13 May 2, 2025
8d92565
Automatic rebaseline of codesize expectations. NFC
ryanking13 May 2, 2025
d9289c2
Merge branch 'main' into rpath-nested-deps
ryanking13 May 7, 2025
3396b43
Merge remote-tracking branch 'upstream/main' into rpath-nested-deps
ryanking13 May 31, 2025
af36541
Store filename only
ryanking13 May 31, 2025
f4fecbb
Revert "Store filename only"
ryanking13 Jun 1, 2025
b86e1f0
Fix codesize
ryanking13 Jun 1, 2025
805749f
Merge remote-tracking branch 'upstream/main' into rpath-nested-deps
ryanking13 Nov 8, 2025
12f094a
rebaseline
ryanking13 Nov 8, 2025
ee7070d
Automatic rebaseline of codesize expectations. NFC
ryanking13 Nov 8, 2025
2813537
Merge remote-tracking branch 'upstream/main' into rpath-nested-deps
ryanking13 Nov 20, 2025
9d7550f
Automatic rebaseline of codesize expectations. NFC
ryanking13 Nov 20, 2025
bd87116
Merge remote-tracking branch 'upstream/main' into rpath-nested-deps
ryanking13 Nov 21, 2025
e0fda6d
Automatic rebaseline of codesize expectations. NFC
ryanking13 Nov 21, 2025
1680a0e
Automatic rebaseline of codesize expectations. NFC
ryanking13 Nov 21, 2025
7fc0ca7
Remove codesize files that are not used anymore
ryanking13 Nov 21, 2025
df8125e
Automatic rebaseline of codesize expectations. NFC
ryanking13 Nov 21, 2025
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
12 changes: 9 additions & 3 deletions src/lib/libdylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,13 +977,19 @@ var LibraryDylink = {
// now load needed libraries and the module itself.
if (flags.loadAsync) {
return metadata.neededDynlibs
.reduce((chain, dynNeeded) => chain.then(() =>
loadDynamicLibrary(dynNeeded, flags, localScope)
), Promise.resolve())
.reduce((chain, needed) => chain.then(() => {
#if FILESYSTEM
needed = findLibraryFS(needed, flags.rpath) ?? needed;
#endif
return loadDynamicLibrary(needed, flags, localScope);
}), Promise.resolve())
.then(loadModule);
}

for (var needed of metadata.neededDynlibs) {
#if FILESYSTEM
needed = findLibraryFS(needed, flags.rpath) ?? needed;
#endif
loadDynamicLibrary(needed, flags, localScope)
}
return loadModule();
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_dylink.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 26672,
"a.out.js.gz": 11377,
"a.out.js": 26712,
"a.out.js.gz": 11400,
"a.out.nodebug.wasm": 17751,
"a.out.nodebug.wasm.gz": 8984,
"total": 44423,
"total_gz": 20361,
"total": 44463,
"total_gz": 20384,
"sent": [
"__syscall_stat64",
"emscripten_resize_heap",
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 245679,
"a.out.js": 245720,
"a.out.nodebug.wasm": 574007,
"total": 819686,
"total": 819727,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
27 changes: 20 additions & 7 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6773,11 +6773,22 @@ def test_ld_library_path(self, args):

@also_with_wasmfs
def test_dlopen_rpath(self):
create_file('hello_nested_dep.c', r'''
#include <stdio.h>

void hello_nested_dep() {
printf("Hello_nested_dep\n");
return;
}
''')
create_file('hello_dep.c', r'''
#include <stdio.h>

void hello_nested_dep();

void hello_dep() {
printf("Hello_dep\n");
hello_nested_dep();
return;
}
''')
Expand All @@ -6804,7 +6815,7 @@ def test_dlopen_rpath(self):
void (*f)();
double (*f2)(double);

h = dlopen("/usr/lib/libhello.wasm", RTLD_NOW);
h = dlopen("/usr/lib/libhello.so", RTLD_NOW);
assert(h);
f = dlsym(h, "hello");
assert(f);
Expand All @@ -6819,20 +6830,22 @@ def test_dlopen_rpath(self):
os.mkdir('subdir')

def _build(rpath_flag, expected, **kwds):
self.run_process([EMCC, '-o', 'subdir/libhello_dep.so', 'hello_dep.c', '-sSIDE_MODULE'])
self.run_process([EMCC, '-o', 'hello.wasm', 'hello.c', '-sSIDE_MODULE', 'subdir/libhello_dep.so'] + rpath_flag)
self.run_process([EMCC, '-o', 'subdir/libhello_nested_dep.so', 'hello_nested_dep.c', '-sSIDE_MODULE'])
self.run_process([EMCC, '-o', 'subdir/libhello_dep.so', 'hello_dep.c', '-sSIDE_MODULE', 'subdir/libhello_nested_dep.so'] + rpath_flag)
self.run_process([EMCC, '-o', 'hello.so', 'hello.c', '-sSIDE_MODULE', 'subdir/libhello_dep.so'] + rpath_flag)
args = ['--profiling-funcs', '-sMAIN_MODULE=2', '-sINITIAL_MEMORY=32Mb',
'--embed-file', 'hello.wasm@/usr/lib/libhello.wasm',
'--embed-file', 'hello.so@/usr/lib/libhello.so',
'--embed-file', 'subdir/libhello_dep.so@/usr/lib/subdir/libhello_dep.so',
'hello.wasm', '-sNO_AUTOLOAD_DYLIBS',
'-L./subdir', '-lhello_dep']
'--embed-file', 'subdir/libhello_nested_dep.so@/usr/lib/subdir/libhello_nested_dep.so',
'hello.so', '-sNO_AUTOLOAD_DYLIBS',
'-L./subdir', '-lhello_dep', '-lhello_nested_dep']
self.do_runf('main.c', expected, cflags=args, **kwds)

# case 1) without rpath: fail to locate the library
_build([], r"no such file or directory, open '.*libhello_dep\.so'", regex=True, assert_returncode=NON_ZERO)

# case 2) with rpath: success
_build(['-Wl,-rpath,$ORIGIN/subdir'], "Hello\nHello_dep\nOk\n")
_build(['-Wl,-rpath,$ORIGIN/subdir,-rpath,$ORIGIN'], "Hello\nHello_dep\nHello_nested_dep\nOk\n")

def test_dlopen_bad_flags(self):
create_file('main.c', r'''
Expand Down