Skip to content

Missing signature argument to addFunction when using EM_JS (+ MAIN_MODULE & -fexceptions) #25483

@ptc-lfruehstueck

Description

@ptc-lfruehstueck

When built with the right combination of flags, the following code produces output that fails to load in the browser with this error:

test.js:648 Aborted(Assertion failed: Missing signature argument to addFunction: function HelloJS(message) { console.log(UTF8ToString(message)); })
abort	@	test.js:648
assert	@	test.js:239
addFunction	@	test.js:1342
reportUndefinedSymbols	@	test.js:4529
loadDylibs	@	test.js:4540
receiveInstance	@	test.js:788
receiveInstantiationResult	@	test.js:811
createWasm	@	test.js:837
await in createWasm		
(anonymous)	@	test.js:5714

Example code:

#include <emscripten.h>
#include <string>

class MyClass
{
public:
    MyClass();
    std::string something;
};

EM_JS(void, HelloJS, (const char* message),
    {
        console.log(UTF8ToString(message));
    }
);

MyClass::MyClass()
{
    HelloJS("test");
}

int main() 
{
    MyClass instance;
    return 0;
}

Build command:

em++ -s MAIN_MODULE=2 -fexceptions -c -o test.o test.cpp
em++ -s MAIN_MODULE=2 -fexceptions -o test.html test.o

Any one of the following changes "fixes" the problem:

  • Removing -s MAIN_MODULE=1/2
  • Removing -fexceptions (or using -fwasm-exceptions instead)
  • Adding -flto
  • And the weirdest part: Removing the std::string something class member or changing it to a simple type like int.
    • Other stdlib types (e.g. std::vector<int>) also trigger the issue.
    • Having a std::string instance in e.g. the main function and not as a class member does not trigger the issue.

I have seen other issues/discussions (#16997, #14959) about related problems, but those seem to deal with existing/library JS code, not JS code coming from EM_JS().

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.15 (09f52557f0d48b65b8c724853ed8f4e8bf80e669)
clang version 22.0.0git (https:/github.com/llvm/llvm-project 3388d40684742e950b3c5d1d2dafe5a40695cfc1)
Target: wasm32-unknown-emscripten
Thread model: posix

(the same behavior exists on older versions like 4.0.10)

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