Issue with dynamic linking

54 views
Skip to first unread message

Mehdi Sabwat

unread,
Dec 17, 2019, 11:08:16 AM12/17/19
to emscripten-discuss
Hi,

I am trying to understand the expected behavior of Emscripten when we have a SIDE_MODULE that links to a standard library.

I am having this message:
Assertion failed: missing linked function `_emscripten_log`. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment

with the following code :

test1.c:
#include <dlfcn.h>
#include <stdio.h>
#include <pthread.h>
#include <emscripten.h>

int main(int ac, char **av)
{
 
void *handle = dlopen("./libwasmdog.wasm", RTLD_LAZY);
 
void (*fun_print_name)(const char *) = dlsym(handle, "print_name");
  fun_print_name
(av[1]);
 
/*                                                                                                                  
    emscripten_log(EM_LOG_CONSOLE, "removing this call will brake linking\n");                                        
    emscripten_debugger();                                                                                            
  */

 
return 0;
}

EMCC_FORCE_STDLIBS
=1 emcc -g -s MAIN_MODULE=1 test1.c -o test.html --preload-file ./libwasmdog.wasm -s ALLOW_MEMORY_GROWTH=1
and
dog.c:
#include "animal.h"
#include <stdio.h>
#include <stdlib.h>
#include <emscripten.h>

void print_name(const char *type)
{
  emscripten_log
(EM_LOG_JS_STACK, "\n");
  emscripten_debugger
();
  printf
("Je suis un %s\n", type);
}
emcc
-g -s SIDE_MODULE=1 dog.c -o libwasmdog.wasm -s "EXPORTED_FUNCTIONS=['_emscripten_log', '_emscripten_debugger']"

Is this a bug, or am I doing it wrong?

Thank you!

Sam Clegg

unread,
Dec 18, 2019, 5:53:02 PM12/18/19
to emscripte...@googlegroups.com
One this that looks wrong here is that you should be exporting  `print_name` from the side module..  Those emscripten functions are being imported (in this case from JS).

However that doesn't explain why _emscripten_log would be undefined.   One thing you could try is calling `emscripten_log` from the main module too.. that would force the JS code for this function to be included.   If that fixes the problem then I guess you need to `EXTRA_EXPORTED_RUNTIME_METHODS`.  TBH I'm surprised this isn't already included when building with MAIN_MODULE.   I seems like all JS functions should be included in that case, but I must be mis-remembering.



Thank you!

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/470197cd-6ade-440b-a945-9e271b09c77f%40googlegroups.com.

Alon Zakai

unread,
Dec 19, 2019, 1:14:06 PM12/19/19
to emscripte...@googlegroups.com
I think the emscripten_log issue is


which I am not sure what to do about. Perhaps at minimum we should make that error message also suggest flipping EXPORT_ALL?

Alon Zakai

unread,
Dec 19, 2019, 1:22:09 PM12/19/19
to emscripte...@googlegroups.com
Actually I see that is a real difference between the backends, so we should flip that flag on automatically. I will open a PR.

Meanwhile as a workaround, -s EXPORT_ALL (on the main module) should fix things for you, Mehdi.

- Alon

Mehdi Sabwat

unread,
Dec 19, 2019, 2:11:42 PM12/19/19
to emscripte...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages