diff --git a/src/lib/libdylink.js b/src/lib/libdylink.js index 50020af24a7fc..90a97fd277652 100644 --- a/src/lib/libdylink.js +++ b/src/lib/libdylink.js @@ -972,13 +972,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(); diff --git a/test/codesize/test_codesize_hello_dylink.json b/test/codesize/test_codesize_hello_dylink.json index ca963a0cb05fa..78061e2d6e97e 100644 --- a/test/codesize/test_codesize_hello_dylink.json +++ b/test/codesize/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { - "a.out.js": 26552, - "a.out.js.gz": 11345, + "a.out.js": 26592, + "a.out.js.gz": 11362, "a.out.nodebug.wasm": 17757, "a.out.nodebug.wasm.gz": 8972, - "total": 44309, - "total_gz": 20317, + "total": 44349, + "total_gz": 20334, "sent": [ "__syscall_stat64", "emscripten_resize_heap", diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index 0d1f74f824ac2..5ba64ae9ce9e7 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 245483, + "a.out.js": 245524, "a.out.nodebug.wasm": 574042, - "total": 819525, + "total": 819566, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize new file mode 100644 index 0000000000000..c32c6049908ed --- /dev/null +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -0,0 +1 @@ +11696 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize new file mode 100644 index 0000000000000..f95e9327160ee --- /dev/null +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -0,0 +1 @@ +27613 diff --git a/test/test_other.py b/test/test_other.py index a0fc309d2e0dc..b2a8f1f152728 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -6793,11 +6793,22 @@ def test_ld_library_path(self, args): @also_with_wasmfs def test_dlopen_rpath(self): + create_file('hello_nested_dep.c', r''' + #include + + void hello_nested_dep() { + printf("Hello_nested_dep\n"); + return; + } + ''') create_file('hello_dep.c', r''' #include + void hello_nested_dep(); + void hello_dep() { printf("Hello_dep\n"); + hello_nested_dep(); return; } ''') @@ -6824,7 +6835,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); @@ -6839,20 +6850,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'''