emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.79k stars 3.31k forks source link

register_map resulting .keys() function can't be called. #12459

Open georeith opened 4 years ago

georeith commented 4 years ago

To reproduce:

register_map<int, int>("IntMap");

Then when you try and use it in JS:

let intmap = new Module.IntMap()
intmap.keys();

You receive the following error:

"UnboundTypeError: Cannot call IntMap.keys due to unbound types: NSt3__26vectorIiNS_9allocatorIiEEEE
    at UnboundTypeError.<anonymous> (http://localhost:6931/dwr.js:4924:24)
    at new UnboundTypeError (eval at createNamedFunction (http://localhost:6931/dwr.js:4912:14), <anonymous>:4:34)
    at throwUnboundTypeError (http://localhost:6931/dwr.js:5795:13)
    at IntMap.unboundTypesHandler [as keys] (http://localhost:6931/dwr.js:6110:15)
    at <anonymous>:1:8"

Emscripten version: 1.39.16 (since tested in 2.0.6 too)

georeith commented 4 years ago

I am trying to test this on a newer version of emscripten but am hitting issues getting my code to compile (fails at link stage with wasm-ld):

emcc:DEBUG: emcc step "calculate system libraries" took 1.65 seconds
emcc:DEBUG: linking: ['/tmp/emscripten_temp/Canvas_0.o', '/tmp/emscripten_temp/Rectangle_1.o', '-L/usr/local/emsdk/upstream/emscripten/system/local/lib', '/tmp/emscripten_temp/RenderList_2.o', '-L/usr/local/emsdk/upstream/emscripten/system/lib', '/tmp/emscripten_temp/RenderObject_3.o', '-L/usr/local/emsdk/upstream/emscripten/cache/wasm', '/tmp/emscripten_temp/RenderObjectContainer_4.o', '/tmp/emscripten_temp/Shape_5.o', '/tmp/emscripten_temp/Text_6.o', '/tmp/emscripten_temp/main_7.o', '/root/design-wasm-renderer/third_party/skia/out/debug/libskparagraph.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libskshaper.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libharfbuzz.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libicu.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libskia.a', '/tmp/emscripten_temp/NotoMono-Regular.ttf_8.o', '-error-limit=0', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libboost_headers.a', '--whole-archive', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libembind-rtti.a', '--no-whole-archive', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libc.a', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libcompiler_rt.a', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libc++.a', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libc++abi.a', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libdlmalloc.a', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libpthread_stub.a', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libc_rt_wasm.a', '/usr/local/emsdk/upstream/emscripten/cache/wasm/libsockets.a']
shared:DEBUG: successfully executed /usr/local/emsdk/node/12.18.1_64bit/bin/node /usr/local/emsdk/upstream/emscripten/src/compiler.js /tmp/emscripten_temp/tmpszf61qlx.txt
emcc:DEBUG: emcc step "JS symbol generation" took 0.71 seconds
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=18 expected=17
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=19 expected=18
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=20 expected=19
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=4 expected=3
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=21 expected=20
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=22 expected=21
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=8 expected=7
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=9 expected=8
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=25 expected=24
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=28 expected=27
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=30 expected=29
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=31 expected=30
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=3 expected=2
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=3 expected=2
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=1 expected=0
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=29 expected=28
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=28 expected=27
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=31 expected=30
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=32 expected=31
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=33 expected=32
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=35 expected=34
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=34 expected=33
wasm-ld: error: unexpected existing value for R_WASM_TABLE_INDEX_REL_SLEB: existing=30 expected=29
em++: error: '/usr/local/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp/dwr.wasm /tmp/emscripten_temp/Canvas_0.o /tmp/emscripten_temp/Rectangle_1.o -L/usr/local/emsdk/upstream/emscripten/system/local/lib /tmp/emscripten_temp/RenderList_2.o -L/usr/local/emsdk/upstream/emscripten/system/lib /tmp/emscripten_temp/RenderObject_3.o -L/usr/local/emsdk/upstream/emscripten/cache/wasm /tmp/emscripten_temp/RenderObjectContainer_4.o /tmp/emscripten_temp/Shape_5.o /tmp/emscripten_temp/Text_6.o /tmp/emscripten_temp/main_7.o /root/design-wasm-renderer/third_party/skia/out/debug/libskparagraph.a /root/design-wasm-renderer/third_party/skia/out/debug/libskshaper.a /root/design-wasm-renderer/third_party/skia/out/debug/libharfbuzz.a /root/design-wasm-renderer/third_party/skia/out/debug/libicu.a /root/design-wasm-renderer/third_party/skia/out/debug/libskia.a /tmp/emscripten_temp/NotoMono-Regular.ttf_8.o -error-limit=0 /usr/local/emsdk/upstream/emscripten/cache/wasm/libboost_headers.a --whole-archive /usr/local/emsdk/upstream/emscripten/cache/wasm/libembind-rtti.a --no-whole-archive /usr/local/emsdk/upstream/emscripten/cache/wasm/libc.a /usr/local/emsdk/upstream/emscripten/cache/wasm/libcompiler_rt.a /usr/local/emsdk/upstream/emscripten/cache/wasm/libc++.a /usr/local/emsdk/upstream/emscripten/cache/wasm/libc++abi.a /usr/local/emsdk/upstream/emscripten/cache/wasm/libdlmalloc.a /usr/local/emsdk/upstream/emscripten/cache/wasm/libpthread_stub.a /usr/local/emsdk/upstream/emscripten/cache/wasm/libc_rt_wasm.a /usr/local/emsdk/upstream/emscripten/cache/wasm/libsockets.a --fatal-warnings -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/tmp/emscripten_temp/tmplfzzx_xj.undefined --import-memory --export-table --export main --export __cxa_demangle --export stackSave --export stackRestore --export stackAlloc --export __data_end --export __wasm_call_ctors --export fflush --export __errno_location --export malloc --export free --export __cxa_is_pointer_type --export __cxa_can_catch --export setThrew --export memalign --export memset --export _get_tzname --export _get_daylight --export _get_timezone --export emscripten_main_thread_process_queued_calls --export realloc --export testSetjmp --export saveSetjmp -z stack-size=5242880 --initial-memory=134217728 --entry=main --max-memory=2147483648 --global-base=1024' failed (1)
cache:DEBUG: PID 110 released multiprocess file lock to Emscripten cache at /usr/local/emsdk/upstream/emscripten/cache/wasm
sbc100 commented 4 years ago

Can you try rebuilding all your libraries?

i.e. /root/design-wasm-renderer/third_party/skia/out/debug/libskparagraph.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libskshaper.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libharfbuzz.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libicu.a', '/root/design-wasm-renderer/third_party/skia/out/debug/libskia.a

Its kind of a shame that error message doesn't give the name of the file with the bad relocations.

georeith commented 4 years ago

@sbc100 Ah, I had tried that but I think something must have been cached by GN still in my last attempt as I did a complete wipe of the build directory and cache and it built. Other than a memory access out of bounds error now I did manage to test the above and can confirm this issue still happens for me in version 2.0.6.

georeith commented 4 years ago

After some further investigation the issue is that .keys() returns a std::vector of the key type so to fix the above you can register that also:

register_vector<int>("IntVector");
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.