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

-s LINKABLE=1 -s ASYNCIFY=1 causes main loop to stop working #23389

Open
BinBashBanana opened this issue Jan 14, 2025 · 0 comments
Open

-s LINKABLE=1 -s ASYNCIFY=1 causes main loop to stop working #23389

BinBashBanana opened this issue Jan 14, 2025 · 0 comments

Comments

@BinBashBanana
Copy link

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.74 (1092ec30a3fb1d46b1782ff1b4db5094d3d06ae5)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 322eb1a92e6d4266184060346616fa0dbe39e731)
Target: wasm32-unknown-emscripten
Thread model: posix

Take the sample code in emtest.c:

#include <stdio.h>
#include <time.h>

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

void mainloop(void)
{
	time_t rawtime;
	struct tm *timeinfo;
	time(&rawtime);
	timeinfo = localtime(&rawtime);
	printf("%s", asctime(timeinfo));
}

int main()
{
	printf("Hello from main!\n");
#ifdef __EMSCRIPTEN__
	emscripten_set_main_loop(mainloop, 0, 0);
#else
	while(1)
		mainloop();
#endif
	printf("Bye from main!\n");
	return 0;
}

Any of the below commands will produce a working program; i.e. prints the current time forever.

emcc emtest.c -o emtest.html -s MAIN_MODULE=1
emcc emtest.c -o emtest.html -s ASYNCIFY=1
emcc emtest.c -o emtest.html -s ASYNCIFY=1 -s MAIN_MODULE=2

However with these options set, main is called, but emscripten encounters an exception before mainloop is called.

emcc emtest.c -o emtest.html -s ASYNCIFY=1 -s MAIN_MODULE=1
emcc emtest.c -o emtest.html -s ASYNCIFY=1 -s LINKABLE=1

The exception is below:

Uncaught Internal Error! Attempted to invoke wasm function pointer with signature "v", but no such functions have gotten exported!
quit_				@	emtest.js:50
handleException			@	emtest.js:1168
callUserCallback		@	emtest.js:1219
runIter				@	emtest.js:1456
MainLoop_runner			@	emtest.js:1558
requestAnimationFrame
requestAnimationFrame		@	emtest.js:1478
MainLoop_scheduler_rAF		@	emtest.js:1362
setMainLoop			@	emtest.js:1574
_emscripten_set_main_loop	@	emtest.js:1583
imports.<computed>		@	emtest.js:4395
$__original_main		@	emtest.wasm:0x3e3f
$main				@	emtest.wasm:0x3f9e
ret.<computed>			@	emtest.js:4427
(anonymous)			@	emtest.js:593
callMain			@	emtest.js:5151
doRun				@	emtest.js:5201
(anonymous)			@	emtest.js:5210
setTimeout
run				@	emtest.js:5208
runCaller			@	emtest.js:5136
removeRunDependency		@	emtest.js:526
receiveInstance			@	emtest.js:714
receiveInstantiationResult	@	emtest.js:732
createWasm			@	emtest.js:755
await in createWasm
(anonymous)			@	emtest.js:4797

I built with emcc emtest.c -o emtest.html -s MAIN_MODULE=1 -s ASYNCIFY=1 -s ASYNCIFY_DEBUG=1 -s DYLINK_DEBUG=1 -s ASSERTIONS=2 and attached the full console output to this issue.

localhost-1736814751439.log

Also note that compiling with at least -O1 and without at least -s ASSERTIONS=1, the error becomes silent.

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

1 participant