Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not loading on Safari #2

Open
aguycalled opened this issue Oct 7, 2021 · 8 comments
Open

Not loading on Safari #2

aguycalled opened this issue Oct 7, 2021 · 8 comments

Comments

@aguycalled
Copy link

Both Chrome and Firefox work, while Safari fails:

RuntimeError: abort(CompileError: WebAssembly.Module doesn't parse at byte 2702: references are not enabled). Build with -s ASSERTIONS=1 for more info. (evaluating 'new WebAssembly.RuntimeError("abort(" + a + "). Build with -s ASSERTIONS=1 for more info.")')
RuntimeError
x — blsjs.js:20
(anonymous function) — blsjs.js:110
promiseReactionJob

@ChiaMineJP
Copy link
Member

Looks like this is the same issue people discussed in opencv/opencv#19553 .

If you afford to do, could you build npm module following the instruction I described in https://github.com/Chia-Mine/bls-signatures/tree/npm, with ecmscripten 1.39.0 and check it works on safari?

@aguycalled
Copy link
Author

Following your instructions I encounter this issue:

# cmake --build . --
npm WARN prepare removing existing node_modules/ before installation
added 308 packages in 4.507s
[  0%] Built target install_npm_dependencies
[ 11%] Building CXX object CMakeFiles/blsjs.dir/jsbindings.cpp.o
In file included from /root/bls-signatures/js-bindings/jsbindings.cpp:16:
In file included from /root/bls-signatures/js-bindings/wrappers/PrivateKeyWrapper.h:18:
/root/bls-signatures/js-bindings/wrappers/../helpers.h:22:10: fatal error: 'relic.h' file not found
#include "relic.h"
         ^~~~~~~~~
1 error generated.
shared:ERROR: '/root/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=0 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/root/emsdk/upstream/emscripten/system/include/libcxx -Xclang -isystem/root/emsdk/upstream/emscripten/system/lib/libcxxabi/include -Xclang -isystem/root/emsdk/upstream/emscripten/system/include/compat -Xclang -isystem/root/emsdk/upstream/emscripten/system/include -Xclang -isystem/root/emsdk/upstream/emscripten/system/include/libc -Xclang -isystem/root/emsdk/upstream/emscripten/system/lib/libc/musl/arch/emscripten -Xclang -isystem/root/emsdk/upstream/emscripten/system/local/include -I/root/bls-signatures/js-bindings/js_build/_deps/relic-src/include -I/root/bls-signatures/js-bindings/js_build/_deps/relic-build/include -I/root/bls-signatures/js-bindings/../contrib/catch -std=gnu++17 -c -DEMSCRIPTEN /root/bls-signatures/js-bindings/jsbindings.cpp -Xclang -isystem/root/emsdk/upstream/emscripten/system/include/SDL -c -o CMakeFiles/blsjs.dir/jsbindings.cpp.o -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr' failed (1)
make[2]: *** [CMakeFiles/blsjs.dir/build.make:64: CMakeFiles/blsjs.dir/jsbindings.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/blsjs.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

@aguycalled
Copy link
Author

Got past the previous issue copying _deps to the js folder. Had to install jre on my system too, which was not included in your instructions. Finding a new issue now:

# cmake --build . --
npm WARN prepare removing existing node_modules/ before installation
added 308 packages in 4.475s
[  0%] Built target install_npm_dependencies
[ 11%] Linking CXX executable blsjs.js
cache:INFO: generating system library: libc.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libc.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libcompiler_rt.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libcompiler_rt.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc-wasm.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libc-wasm.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc++-noexcept.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libc++-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc++abi-noexcept.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libc++abi-noexcept.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libembind-rtti.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libembind-rtti.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libdlmalloc.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libdlmalloc.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libpthread_stub.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libpthread_stub.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc_rt_wasm.a... (this will be cached in "/root/emsdk/upstream/emscripten/cache/wasm-obj/libc_rt_wasm.a" for subsequent builds)
cache:INFO:  - ok
wasm-ld: error: unable to find library -lblstmp
wasm-ld: error: unable to find library -lrelic_s
shared:ERROR: '/root/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp_j2_pxioc/blsjs.wasm --allow-undefined --lto-O0 CMakeFiles/blsjs.dir/jsbindings.cpp.o CMakeFiles/blsjs.dir/wrappers/BignumWrapper.cpp.o -L/root/emsdk/upstream/emscripten/system/local/lib CMakeFiles/blsjs.dir/wrappers/G1ElementWrapper.cpp.o -L/root/emsdk/upstream/emscripten/system/lib CMakeFiles/blsjs.dir/wrappers/G2ElementWrapper.cpp.o -L/root/emsdk/upstream/emscripten/cache/wasm-obj CMakeFiles/blsjs.dir/wrappers/PrivateKeyWrapper.cpp.o CMakeFiles/blsjs.dir/wrappers/SchemeMPLWrapper.cpp.o CMakeFiles/blsjs.dir/wrappers/UtilWrapper.cpp.o CMakeFiles/blsjs.dir/helpers.cpp.o -lblstmp -lrelic_s /root/emsdk/upstream/emscripten/cache/wasm-obj/libc.a /root/emsdk/upstream/emscripten/cache/wasm-obj/libcompiler_rt.a /root/emsdk/upstream/emscripten/cache/wasm-obj/libc-wasm.a /root/emsdk/upstream/emscripten/cache/wasm-obj/libc++-noexcept.a /root/emsdk/upstream/emscripten/cache/wasm-obj/libc++abi-noexcept.a --whole-archive /root/emsdk/upstream/emscripten/cache/wasm-obj/libembind-rtti.a --no-whole-archive /root/emsdk/upstream/emscripten/cache/wasm-obj/libdlmalloc.a /root/emsdk/upstream/emscripten/cache/wasm-obj/libpthread_stub.a /root/emsdk/upstream/emscripten/cache/wasm-obj/libc_rt_wasm.a --import-memory --import-table -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export __wasm_call_ctors --export __data_end --export main --export malloc --export free --export setThrew --export __errno_location --export _ZSt18uncaught_exceptionv -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (1)
make[2]: *** [CMakeFiles/blsjs.dir/build.make:199: blsjs.js] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/blsjs.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

@ChiaMineJP
Copy link
Member

Hmm. Since I don't have environment I can use to test module in Safari, finding out the cause/fix needs good guesses...

What is your cmake version?
It seems the error below raised because cmake didn't fetch the files of relic module.

/root/bls-signatures/js-bindings/wrappers/../helpers.h:22:10: fatal error: 'relic.h' file not found
#include "relic.h"
         ^~~~~~~~~

@aguycalled
Copy link
Author

aguycalled commented Oct 12, 2021 via email

@aguycalled
Copy link
Author

What environment do you use to compile the library? I can test on my Safari if you are able to compile it with 1.39.0

@ChiaMineJP
Copy link
Member

ChiaMineJP commented Oct 12, 2021

I tried to build module for you to test it in your environment.
But it seems older version of emscripten has another problem.

I leave logs with a hope that anyone who follows this issue can skip what I tried so far.

My Build Environment

  • Ubuntu Ubuntu 20.04.2
  • node-14.15.5-64bit
  • cmake 3.16.3

1. Build with emscripten 1.39.0

Failed to build with error messages below.

chiaminejp@tokyo:~/projects/bls-signatures/js_build$ cmake --build . --
[  1%] Building C object _deps/sodium-build/CMakeFiles/sodium.dir/cmake_pch.h.pch
shared:ERROR: cannot specify -o with -c/-S and multiple source files
make[2]: *** [_deps/sodium-build/CMakeFiles/sodium.dir/build.make:65: _deps/sodium-build/CMakeFiles/sodium.dir/cmake_pch.h.pch] エラー 1
make[1]: *** [CMakeFiles/Makefile2:184: _deps/sodium-build/CMakeFiles/sodium.dir/all] エラー 2
make: *** [Makefile:130: all] エラー 2

This seems to be a bug in emscripten 1.39.0, for it misinterprets command options.
So I tried 1.40.1 which should fix this error.

2. Build with emscripten 1.40.1

Another error stopped building.

[ 95%] Building CXX object src/CMakeFiles/blstmp.dir/schemes.cpp.o
[ 96%] Linking CXX static library libblstmp.a
[ 96%] Built target blstmp
Scanning dependencies of target runbench
[ 96%] Building CXX object src/CMakeFiles/runbench.dir/test-bench.cpp.o
[ 97%] Linking CXX executable runbench.js
wasm-ld: error: 'atomics' feature is used by relic_err.c.o, so --shared-memory must be used
em++: error: '/home/chiaminejp/projects/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp_zrn56fv5/runbench.wasm CMakeFiles/runbench.dir/test-bench.cpp.o -L/home/chiaminejp/projects/emsdk/upstream/emscripten/system/local/lib libblstmp.a -L/home/chiaminejp/projects/emsdk/upstream/emscripten/system/lib ../_deps/relic-build/lib/librelic_s.a -L/home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm ../_deps/sodium-build/libsodium.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libc.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libcompiler_rt.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libc-wasm.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libc++-noexcept.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libc++abi-noexcept.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libdlmalloc.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libpthread_stub.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libc_rt_wasm.a /home/chiaminejp/projects/emsdk/upstream/emscripten/cache/wasm/libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --import-memory --import-table --strip-debug --export main --export malloc --export free --export stackSave --export stackRestore --export stackAlloc --export __data_end --export __wasm_call_ctors --export __errno_location --export setThrew -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (1)
make[2]: *** [src/CMakeFiles/runbench.dir/build.make:90: src/runbench.js] エラー 1
make[1]: *** [CMakeFiles/Makefile2:267: src/CMakeFiles/runbench.dir/all] エラー 2
make: *** [Makefile:130: all] エラー 2

Note: emscripten 2.0.0 showed exact the same error.

My current conclusion

Just wait for new version of emscripten which can produce safari-compatible wasm binary.

@aguycalled
Copy link
Author

aguycalled commented Oct 21, 2021

What about adding --shared-memory to the linker flags?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants