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

Confusion about EM_JS functions and dead code elimination #18957

Closed
hoodmane opened this issue Mar 14, 2023 · 2 comments
Closed

Confusion about EM_JS functions and dead code elimination #18957

hoodmane opened this issue Mar 14, 2023 · 2 comments

Comments

@hoodmane
Copy link
Collaborator

hoodmane commented Mar 14, 2023

How do I prevent dead code elimination from removing an EM_JS function I define in a different compilation unit? I have mostly been using -sMAIN_MODULE=1 which prevents these errors but now I am trying to use -sMAIN_MODULE=2 or no dynamic linking builds and I am running into trouble with missing EM_JS symbols. I assume I am messing up something simple. How do I prevent these missing symbol errors? (See full example below).

@antocuni

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.32 (eab98adf462c39f3c31d348331c4830bcaa36949)

Failing command line in full:

main.c

void say_hello(void);

int
main(void) {
    say_hello();
}

hello.c

#include <emscripten.h>

EM_JS(void, say_hello, (void), {
    console.log("Hello from JavaScript");
})

Compilation

$ emcc -c hello.c -o hello.o
$ emcc -c main.c -o main.o

Full link command and output with -v appended

$ emcc main.o hello.o -o main.js -v
 "/home/ubuntu/pyodide/emsdk/emsdk/upstream/bin/clang" --version
 "/home/ubuntu/pyodide/emsdk/emsdk/upstream/bin/wasm-ld" -o main.wasm main.o hello.o -L/home/ubuntu/pyodide/emsdk/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/tmp/tmp6cceqbst.undefined --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024
wasm-ld: error: main.o: undefined symbol: say_hello
emcc: error: '/home/ubuntu/pyodide/emsdk/emsdk/upstream/bin/wasm-ld -o main.wasm main.o hello.o -L/home/ubuntu/pyodide/emsdk/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/tmp/tmp6cceqbst.undefined --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1)
@sbc100
Copy link
Collaborator

sbc100 commented Mar 14, 2023

I believe this is a duplicate of #18927 and was fixed in #18928.

Since this is effect multiple folks I guess we should push for a release ASAP to get the fix out.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 14, 2023

Hopefully we will release 3.1.34 today with #18928 included.

Closing this as a duplicate.

@sbc100 sbc100 closed this as completed Mar 14, 2023
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

No branches or pull requests

2 participants