Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlopen - missing dynCall_ji in Module #17707

Open
gl84 opened this issue Aug 23, 2022 · 1 comment · May be fixed by #17759
Open

dlopen - missing dynCall_ji in Module #17707

gl84 opened this issue Aug 23, 2022 · 1 comment · May be fixed by #17759

Comments

@gl84
Copy link
Contributor

gl84 commented Aug 23, 2022

Please include the following in your bug report:

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.19 (a5f7b1c)
clang version 16.0.0 (https://github.com/llvm/llvm-project 30171e76f0e5ea8037bc4d1450dd3e12af4d9938)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/user/emscripten/emsdk_tot/emsdk/upstream/bin

When I'm opening a library through dlopen an assert in dynCallLegacy is triggered and a RuntimeError: Aborted(Assertion failed: bad function pointer type - no table for sig 'ji') is thrown.

Dynamically linking the library works as expected.

Test case that triggers the behavior:

Side library: side.cpp
Build with:
em++ -Wall -g -O0 -sDISABLE_EXCEPTION_CATCHING=0 -sSIDE_MODULE=1 side.cpp -o libside.wasm

#include <stdint.h>
extern "C" {
    typedef int64_t (*i64Fn)();
    int64_t calc(i64Fn f) {   return f();  }  
    int64_t callI64(i64Fn f) {
        try {
            return calc(f);
        } catch (...) {
            return calc(f);
        }
    }
}

Main: main_dlopen.cpp
Build with:
em++ -g -sDISABLE_EXCEPTION_CATCHING=0 -s MAIN_MODULE=2 main_dlopen.cpp -sDYLINK_DEBUG=1 -o main_dlopen.js -sASSERTIONS=2 -sEXPORTED_FUNCTIONS=[_main] -sNO_AUTOLOAD_DYLIBS libside.wasm

#include <stdint.h>
#include <dlfcn.h>

typedef int64_t (*i64Fn)();
typedef int64_t (*fun_ptr_type_callI64)(i64Fn);

int64_t return_main() { return -1; }

int main() {
    void * handle = dlopen("libside.wasm", RTLD_NOW);
    fun_ptr_type_callI64 get_function_ptr = ( fun_ptr_type_callI64 )dlsym(handle, "callI64");
    get_function_ptr(return_main);
    return 0;
}
@sbc100
Copy link
Collaborator

sbc100 commented Aug 23, 2022

I think this might be the same issue that #17328 addresses.

sbc100 added a commit that referenced this issue Aug 23, 2022
The 'no table for sig' dates back to the fastcomp era I believe.

See: #17707
sbc100 added a commit that referenced this issue Aug 23, 2022
The 'no table for sig' dates back to the fastcomp era I believe.

See: #17707
gl84 added a commit to gl84/emscripten that referenced this issue Aug 30, 2022
Follow up on PR emscripten-core#17328.

- Create the wasm adaptor also for MAIN_MODULE == 2
- Remove obsolete assert (triggers for all cases were we create the wrapper)
@gl84 gl84 linked a pull request Aug 30, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants