diff --git a/src/library.js b/src/library.js index f0df8227910b..21fe9a84c699 100644 --- a/src/library.js +++ b/src/library.js @@ -2152,37 +2152,16 @@ LibraryManager.library = { } var lib = LDSO.loadedLibs[handle]; - var isMainModule = lib.module == Module; - - var mangled = '_' + symbol; - var modSymbol = mangled; -#if WASM_BACKEND - if (!isMainModule) { - modSymbol = symbol; - } +#if !WASM_BACKEND + symbol = '_' + symbol; #endif - - if (!lib.module.hasOwnProperty(modSymbol)) { - DLFCN.errorMsg = ('Tried to lookup unknown symbol "' + modSymbol + + if (!lib.module.hasOwnProperty(symbol)) { + DLFCN.errorMsg = ('Tried to lookup unknown symbol "' + symbol + '" in dynamic lib: ' + lib.name); return 0; } - var result = lib.module[modSymbol]; -#if WASM - // Attempt to get the real "unwrapped" symbol so we have more chance of - // getting wasm function which can be added to a table. - if (isMainModule) { -#if WASM_BACKEND - var asmSymbol = symbol; -#else - var asmSymbol = mangled; -#endif - if (lib.module["asm"][asmSymbol]) { - result = lib.module["asm"][asmSymbol]; - } - } -#endif + var result = lib.module[symbol]; if (typeof result !== 'function') return result; diff --git a/tests/core/test_dlfcn_self.c b/tests/core/test_dlfcn_self.c index 6ba45bbdd657..bdf912e91950 100644 --- a/tests/core/test_dlfcn_self.c +++ b/tests/core/test_dlfcn_self.c @@ -19,10 +19,6 @@ EMSCRIPTEN_KEEPALIVE void repeatable() { void* self = dlopen(NULL, RTLD_LAZY); int* global_ptr = (int*)dlsym(self, "global"); void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo"); - if (!foo_ptr) { - printf("dlsym failed: %s\n", dlerror()); - return; - } foo_ptr(*global_ptr); dlclose(self); } diff --git a/tests/test_core.py b/tests/test_core.py index 044c8f5d07c5..4ea2274c7999 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2765,27 +2765,23 @@ def test_dlfcn_alignment_and_zeroing(self): ''' self.do_run(src, 'success.\n') + @no_wasm('needs to be able to add JS functions to the wasm table') @needs_dlfcn def test_dlfcn_self(self): self.set_setting('MAIN_MODULE') self.set_setting('EXPORT_ALL') def post(filename): - js = open(filename).read() - start = js.find('var NAMED_GLOBALS') - first = js.find('{', start) - last = js.find('}', start) - exports = js[first + 1:last] - exports = exports.split(',') + with open(filename) as f: + for line in f: + if 'var NAMED_GLOBALS' in line: + table = line + break + else: + self.fail('Could not find symbol table!') + table = table[table.find('{'):table.find('}') + 1] # ensure there aren't too many globals; we don't want unnamed_addr - exports = [e.split(':')[0].strip('"') for e in exports] - exports.sort() - self.assertGreater(len(exports), 20) - # wasm backend includes alias in NAMED_GLOBALS - if self.is_wasm_backend(): - self.assertLess(len(exports), 43) - else: - self.assertLess(len(exports), 30) + assert table.count(',') <= 30, table.count(',') self.do_run_in_out_file_test('tests', 'core', 'test_dlfcn_self', post_build=post)