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

Pointer to EM_JS function won't compile with MAIN_MODULE #18370

Closed
arseneyr opened this issue Dec 14, 2022 · 2 comments · Fixed by #18391
Closed

Pointer to EM_JS function won't compile with MAIN_MODULE #18370

arseneyr opened this issue Dec 14, 2022 · 2 comments · Fixed by #18391

Comments

@arseneyr
Copy link

Compiling the following file:

#include <emscripten.h>

EM_JS(void, foo, (), {});

void(*foo_ptr)() = &foo;

with emcc test.c -sMAIN_MODULE results in the following error:

Traceback (most recent call last):
  File "/emsdk/upstream/emscripten/emcc.py", line 4309, in <module>
    sys.exit(main(sys.argv))
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/emsdk/upstream/emscripten/emcc.py", line 4302, in main
    ret = run(args)
  File "/emsdk/upstream/emscripten/emcc.py", line 1319, in run
    phase_post_link(options, state, wasm_target, wasm_target, target)
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/emsdk/upstream/emscripten/emcc.py", line 3022, in phase_post_link
    phase_emscript(options, in_wasm, wasm_target, memfile)
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/emsdk/upstream/emscripten/emcc.py", line 3052, in phase_emscript
    emscripten.run(in_wasm, wasm_target, final_js, memfile)
  File "/emsdk/upstream/emscripten/emscripten.py", line 893, in run
    emscript(in_wasm, out_wasm, outfile_js, memfile)
  File "/emsdk/upstream/emscripten/emscripten.py", line 341, in emscript
    assert imp.kind == webassembly.ExternType.FUNC
AssertionError

I'm not sure if this is a bug or just a construct that is not allowed during dynamic linking. If it's the latter, perhaps the error message should be improved.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.28 (f11d6196dd4e8748a726f19895c859b40ff6a4f3)
clang version 16.0.0 (https://github.com/llvm/llvm-project ea4be70cea8509520db8638bb17bcd7b5d8d60ac)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
@kripken
Copy link
Member

kripken commented Dec 16, 2022

@sbc100 I think you recently got EM_ASM working but EM_JS is still a TODO?

@sbc100
Copy link
Collaborator

sbc100 commented Dec 16, 2022

This is the main module (where EM_JS and EM_ASM have always worked), not the side module.

Notably the problem goes away if I do -sMAIN_MODULE=2 (which is highly recommended).

Investigating more.

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.

3 participants