Skip to content

[WASM Exception]: WasmOffsetConverter fails with: bad import kind: 12 #18592

Closed

Description

@gl84

I tried switching from emscripten EH -> wasm EH (using -sASSERTIONS + dynamic linking).

Unfortunately running the code fails with
failed to asynchronously prepare wasm: bad import kind: 12.

It seems that the produced wasm sections are not considered in WasmOffsetConverter

Activity

  1. sbc100 commented on Jan 25, 2023

    @sbc100
    Collaborator

    I guess we must not have any testing of that particular configuration. We should fix that.

  2. aheejin commented on Feb 3, 2023

    @aheejin
    Member

    Can you provide a reproducer? I did a simple test but it seemed working. What I did was:

    main.cpp:

    void side_throw();
    int main() {
      side_throw();
      return 0;
    }

    liblib.cpp:

    void side_throw() {
      throw 3;
    }
    $ em++ liblib.cpp -o liblib.so -g -sASSERTIONS -sSIDE_MODULE -O0 -fwasm-exceptions -sENVIRONMENT=shell
    
    $ em++ main.cpp -o main.js -sMAIN_MODULE=2 -O0 -fwasm-exceptions -sASSERTIONS liblib.so -sENVIRONMENT=shell
    
    $ d8 main.js
    aheejin@aheejin:~/test/stack/dylink$ d8 main.js
    exiting due to exception: [object WebAssembly.Exception],Error: int,
        at wasm://wasm/00073456:wasm-function[149]:0xb639
        at side_throw() (wasm://wasm/6d51dda6:wasm-function[4]:0x140)
        at __Z10side_throwv (main.js:2069:41)
        at wasm://wasm/00073456:wasm-function[12]:0x525a
        at wasm://wasm/00073456:wasm-function[13]:0x5277
        at callMain (main.js:5050:15)
        at doRun (main.js:5118:23)
        at run (main.js:5133:5)
        at runCaller (main.js:5024:19)
  3. gl84 commented on Feb 3, 2023

    @gl84
    ContributorAuthor

    I've created a small repro case:

    reader.hpp:

    struct reader {
        public:
            reader() {}
            ~reader();
    };
    

    reader.cpp:

    #include "reader.hpp"
    #include "emscripten.h"
    EMSCRIPTEN_KEEPALIVE reader::~reader() {}
    

    exported_api.cpp:

    #include "emscripten.h"
    #include "reader.hpp"
    extern "C" {
        EMSCRIPTEN_KEEPALIVE void reader_destroy(reader* r) {
            delete r;
        }
    }
    EMSCRIPTEN_KEEPALIVE int main() {}
    

    Compile it with:
    em++ -fPIC -o lib.so -sSIDE_MODULE=2 -sEXPORTED_FUNCTIONS=[_ZN6readerD1Ev] -fwasm-exceptions reader.cpp
    em++ -fwasm-exceptions -o exported_api.cpp.o -c exported_api.cpp
    em++ -fsanitize=null -sMAIN_MODULE=2 -sASSERTIONS=2 -sEXPORTED_FUNCTIONS=_main -fwasm-exceptions exported_api.cpp.o -o exported_api.js lib.so

    and execute it.

  4. added a commit that references this issue on Feb 9, 2023
    0f7fd43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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