Skip to content

Commit

Permalink
Revert "Fix test_dlfcn_self test under wasm and wasm backend (emscrip…
Browse files Browse the repository at this point in the history
…ten-core#8531)"

This reverts commit 1a85480.
  • Loading branch information
VirtualTim authored May 23, 2019
1 parent 97ce0c0 commit f76e7bd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 44 deletions.
31 changes: 5 additions & 26 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions tests/core/test_dlfcn_self.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
24 changes: 10 additions & 14 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f76e7bd

Please sign in to comment.