使用Emscripten编译Stockfish 10 wasm时出现内存错误

时间:2019-12-03 11:13:18

标签: emscripten

我在编译过程中遇到内存问题:“致命:由于内存无法展平,因此无法应用sbrk-val”(更多信息请参见下文)。实际上,我只想编译Stockfish js Wasm,但用以下内容替换原始的Makefile:custom makefile

我的目标是尽可能避免对nodejs的依赖,以便可以在React Native中使用它。

这是控制台输出

$> make all                                                                                                                                                        2 ↵
em++ -std=c++11 -c bitbase.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c bitboard.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c endgame.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c evaluate.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c main.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c material.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c misc.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c movegen.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c movepick.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c pawns.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c position.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c psqt.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c search.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c thread.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c timeman.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c tt.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c uci.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -c ucioption.cpp -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM
em++ -std=c++11 -o stockfish.wasm bitbase.o bitboard.o endgame.o evaluate.o main.o material.o misc.o movegen.o movepick.o pawns.o position.o psqt.o search.o thread.o timeman.o tt.o uci.o ucioption.o -Oz -DNDEBUG -s WASM=1 -fPIC -s EVAL_CTORS=0 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_ASYNC_COMPILATION=1 -s TOTAL_MEMORY=33554432 -s NO_FILESYSTEM=1 -s STANDALONE_WASM -s SIDE_MODULE=1
Fatal: cannot apply sbrk-val since memory is not flattenable

Traceback (most recent call last):
  File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 3681, in <module>
    sys.exit(run(sys.argv))
  File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 2514, in run
    optimizer)
  File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/emcc.py", line 3028, in do_binaryen
    debug=intermediate_debug_info)
  File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 2903, in run_wasm_opt
    return Building.run_binaryen_command('wasm-opt', *args, **kwargs)
  File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 2899, in run_binaryen_command
    run_process(cmd)
  File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 188, in run_process
    result.check_returncode()
  File "/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/emscripten/tools/shared.py", line 168, in check_returncode
    raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args, output=self.stdout, stderr=self.stderr)
tools.shared.Py2CalledProcessError: Command '['/home/laurent-bernabe/Documents/Programmation/ProjetsExterieurs/emsdk/upstream/bin/wasm-opt', '--post-emscripten', '--no-exit-runtime', '-Oz', '--low-memory-unused', '--strip-debug', '--strip-producers', '--pass-arg=emscripten-sbrk-ptr@-1', '--pass-arg=emscripten-sbrk-val@-1', 'stockfish.wasm', '-o', 'stockfish.wasm', '--mvp-features']' returned non-zero exit status 1
make: *** [Makefile:16: stockfish.wasm] Error 1

有人可以帮助我理解为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

我发现需要改变的地方: 标志-s TOTAL_MEMORY = 33554432是使内存固定并导致编译器拒绝该过程的原因。