Skip to content

EM_JS functions can only be called from the files in which they're defined #18927

Closed
@curiousdannii

Description

@curiousdannii

Just posting as a new issue so it doesn't get forgotten...

Originally posted by @sbc100 in #16003 (comment)

Sorry to raise an error just after you concluded there were no issues stuck_out_tongue But you know, sometimes it takes a while to try updating dependencies.

I tried updating to 3.1.28+ and I now get errors for undefined symbols when an EM_JS function is defined in a library.

wasm-ld: error: libremglk.a(gi_dispa.c.o): undefined symbol: glk_buffer_to_title_case_uni

I think the reason for this is that the EM_JS macro basically expands to a declaration of the EM_JS function as external with an __attribute__((import_name)) attached to it.

However, when you use it outside in other compilation units they don't see that declaration. Actually that sounds odd now that I say its since those attributes should probably attached to the final symbol.

In any case, I think the soltution that others have uses it to only call the EM_JS function within the file where they are defined, and then define small (difined) wrappers for them for use outside the compilation unit.

e.g. declare glk_buffer_to_title_case_uni_js as the EM_JS function then define a local glk_buffer_to_title_case_uni which then just calls it.

(I will investigate further to see if we can actually this fix with you having to change any code).

There seems to be two options:

  1. A way is found so that EM_JS functions can be called from other files without users needing to wrap them.
  2. The docs are modified to note that this is a limitation and wrapping is needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions