emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.75k stars 3.3k forks source link

Dynamic linking broken in 3.1.57 #21973

Closed goldwaving closed 2 months ago

goldwaving commented 5 months ago

When using dynamically linking, we are now getting a runtime error BindingError: Cannot register type 'void' twice. This occurs in the loadDyLibs function, which calls sharedRegisterType at some point. The error does not occur when using 3.1.56.

throwBindingError   
sharedRegisterType  
registerType    
__embind_register_void  
$embind_init_builtin()
$_GLOBAL__sub_I_bind.cpp
$__wasm_call_ctors  
callRuntimeCallbacks    
initRuntime 
doRun   
run 
runCaller   
removeRunDependency 
(anonymous)
Promise.then (async)
loadDylibs  
receiveInstance
goldwaving commented 2 months ago

Any update on this issue? If I hack sharedRegisterType to ignore duplicate registrations, everything seems to work normally.

sbc100 commented 2 months ago

Can you share the full link flags you are using when building your main module and your side module(s)?

sbc100 commented 2 months ago

The embind_init_builtin code is coming from bind.cpp and is in a static constructor. See https://github.com/emscripten-core/emscripten/blob/95e2146355f3e152ca0f42be4fec2f8c7cb637b3/system/lib/embind/bind.cpp#L122.

This static constructor should only exist in the main module and not in the side module. I wonder if somehow bind.cpp (which lives in libembind.a is somehow being linked into your side module? Can you shared the output of your side module linking when you add -v? My guess is that -lembind is being added to the link line when it shouldn't.

goldwaving commented 2 months ago

That was the problem. After ensuring -lembind was removed from all side modules and rebuilding, everything worked. Thanks for the help!

sbc100 commented 2 months ago

I do wonder if we should fix this somehow, since others might run into the same thing.

I also wonder why this seems to not be a problem with older versions of emscripten?