Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/lib/libdylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ var LibraryDylink = {
* @param {Object=} localScope
*/`,
$loadDynamicLibrary: function(libName, flags = {global: true, nodelete: true}, localScope, handle) {
// Avoid duplicate LDSO entries from non-canonical paths (e.g. "sub/../lib.so")
libName = PATH.normalize(libName);
#if DYLINK_DEBUG
dbg(`loadDynamicLibrary: ${libName} handle: ${handle}`);
dbg('existing:', Object.keys(LDSO.loadedLibsByName));
Expand Down Expand Up @@ -1280,7 +1282,6 @@ var LibraryDylink = {
#if DYLINK_DEBUG
dbg('dlopenInternal:', filename);
#endif
filename = PATH.normalize(filename);
var searchpaths = [];

var global = Boolean(flags & {{{ cDefs.RTLD_GLOBAL }}});
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19555,
"a.out.js.gz": 8102,
"a.out.nodebug.wasm": 132813,
"a.out.nodebug.wasm.gz": 49862,
"total": 152368,
"total_gz": 57964,
"a.out.nodebug.wasm": 132865,
"a.out.nodebug.wasm.gz": 49889,
"total": 152420,
"total_gz": 57991,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_ctors2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19532,
"a.out.js.gz": 8087,
"a.out.nodebug.wasm": 132233,
"a.out.nodebug.wasm.gz": 49515,
"total": 151765,
"total_gz": 57602,
"a.out.nodebug.wasm": 132285,
"a.out.nodebug.wasm.gz": 49542,
"total": 151817,
"total_gz": 57629,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_lto.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 18902,
"a.out.js.gz": 7782,
"a.out.nodebug.wasm": 102066,
"a.out.nodebug.wasm.gz": 39421,
"total": 120968,
"total_gz": 47203,
"a.out.nodebug.wasm": 102126,
"a.out.nodebug.wasm.gz": 39426,
"total": 121028,
"total_gz": 47208,
"sent": [
"a (emscripten_resize_heap)",
"b (_setitimer_js)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_noexcept.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19555,
"a.out.js.gz": 8102,
"a.out.nodebug.wasm": 134820,
"a.out.nodebug.wasm.gz": 50699,
"total": 154375,
"total_gz": 58801,
"a.out.nodebug.wasm": 134872,
"a.out.nodebug.wasm.gz": 50724,
"total": 154427,
"total_gz": 58826,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_wasmfs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 7053,
"a.out.js.gz": 3325,
"a.out.nodebug.wasm": 172891,
"a.out.nodebug.wasm.gz": 63277,
"total": 179944,
"total_gz": 66602,
"a.out.nodebug.wasm": 172943,
"a.out.nodebug.wasm.gz": 63297,
"total": 179996,
"total_gz": 66622,
"sent": [
"__cxa_throw",
"_abort_js",
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": 26596,
"a.out.js.gz": 11356,
"a.out.js": 26604,
"a.out.js.gz": 11359,
"a.out.nodebug.wasm": 17730,
"a.out.nodebug.wasm.gz": 8957,
"total": 44326,
"total_gz": 20313,
"total": 44334,
"total_gz": 20316,
"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": 244691,
"a.out.js": 244687,
"a.out.nodebug.wasm": 577692,
"total": 822383,
"total": 822379,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 371,
"a.js": 7262,
"a.js.gz": 3323,
"a.wasm": 7081,
"a.wasm.gz": 3250,
"total": 14891,
"total_gz": 6944
"a.wasm": 7098,
"a.wasm.gz": 3255,
"total": 14908,
"total_gz": 6949
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 371,
"a.js": 5353,
"a.js.gz": 2522,
"a.wasm": 5786,
"a.wasm.gz": 2726,
"total": 11687,
"total_gz": 5619
"a.wasm": 5802,
"a.wasm.gz": 2732,
"total": 11703,
"total_gz": 5625
}
52 changes: 52 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6884,6 +6884,58 @@ def _build(rpath_flag, expected, **kwds):
# case 2) with rpath: success
_build(['-Wl,-rpath,$ORIGIN/subdir,-rpath,$ORIGIN'], "Hello\nHello_dep\nHello_nested_dep\nOk\n")

@also_with_wasmfs
def test_dlopen_rpath_no_duplicate_load(self):
# Test that a library loaded both directly and as a transitive dependency
# via $ORIGIN/.. rpath is not loaded twice. Without path normalization in
# loadDynamicLibrary, the LDSO would contain both "/usr/lib/libbase.so"
# and "/usr/lib/subdir/../libbase.so" as separate entries.
create_file('libbase.c', r'''
static int init_count = 0;
__attribute__((constructor))
void init() { init_count++; }
int base_func() { return 42; }
int get_init_count() { return init_count; }
''')
create_file('libplugin.c', r'''
extern int base_func();
int plugin_func() { return base_func() + 1; }
''')
create_file('main.c', r'''
#include <assert.h>
#include <stdio.h>
#include <dlfcn.h>

int main() {
void *hbase = dlopen("/usr/lib/libbase.so", RTLD_NOW | RTLD_GLOBAL);
assert(hbase);

void *hplugin = dlopen("/usr/lib/subdir/libplugin.so", RTLD_NOW);
assert(hplugin);

int (*base_func)() = dlsym(hbase, "base_func");
int (*plugin_func)() = dlsym(hplugin, "plugin_func");
int (*get_init_count)() = dlsym(hbase, "get_init_count");

assert(base_func() == 42);
assert(plugin_func() == 43);
assert(get_init_count() == 1);

dlclose(hplugin);
dlclose(hbase);
printf("success\n");
return 0;
}
''')
os.mkdir('subdir')
self.run_process([EMCC, '-o', 'libbase.so', 'libbase.c', '-sSIDE_MODULE'])
self.run_process([EMCC, '-o', 'subdir/libplugin.so', 'libplugin.c', '-sSIDE_MODULE', './libbase.so', '-Wl,-rpath,$ORIGIN/..'])
self.do_runf('main.c', 'success\n',
cflags=['--profiling-funcs', '-sMAIN_MODULE=2',
'--embed-file', 'libbase.so@/usr/lib/libbase.so',
'--embed-file', 'subdir/libplugin.so@/usr/lib/subdir/libplugin.so',
'-L.', '-lbase', '-L./subdir', '-lplugin', '-sNO_AUTOLOAD_DYLIBS'])

def test_dlopen_bad_flags(self):
create_file('main.c', r'''
#include <dlfcn.h>
Expand Down