parse exception: popping from empty stack

オープン
#27,525 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
c, cpp, shell, wasm
領域
compilers

調査の方向性

提供された shell 再現スクリプトを emcc と em++ で実行し、wasm-opt --safe-heap のステップ付近にある生成された out.wasm を調査し、利用可能な場合は wasm-validate --enable-all を使用します。再現によって wasm-opt が「popping from empty stack」と報告することがなくなり、リンクが正常に完了すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Please include the following in your bug report:

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 6.0.5-git
clang version 24.0.0git
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/6.0.5/libexec/llvm/bin

Failing command line in full:

$ em++ -v $LINK_FLAGS -o out.js main.o functable.o
 /opt/homebrew/Cellar/emscripten/6.0.5/libexec/llvm/bin/clang --version
 /opt/homebrew/Cellar/emscripten/6.0.5/libexec/llvm/bin/wasm-ld -o out.wasm /var/folders/tn/r_t_4vv55572jny2jgw1082r0000gq/T/tmp3ne1o_u7libemscripten_js_symbols.so -Bstatic --import-undefined --strip-debug --export-if-defined=malloc --export-if-defined=sbrk --export-if-defined=emscripten_stack_get_end --export-if-defined=emscripten_stack_get_free --export-if-defined=emscripten_stack_get_base --export-if-defined=emscripten_stack_get_current --export-if-defined=emscripten_stack_init --export-if-defined=_emscripten_stack_alloc --export-if-defined=emscripten_get_sbrk_ptr --export-if-defined=__wasm_call_ctors --export-if-defined=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1 main.o functable.o -L/opt/homebrew/Cellar/emscripten/6.0.5/libexec/cache/sysroot/lib/wasm32-emscripten -L/opt/homebrew/Cellar/emscripten/6.0.5/libexec/src/lib -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc-debug -lclang_rt.builtins -lc++-debug-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr
 /opt/homebrew/Cellar/emscripten/6.0.5/libexec/llvm/bin/llvm-objcopy out.wasm out.wasm '--remove-section=llvm.func_attr.annotate.*' --remove-section=producers --remove-section=name '--remove-section=.debug*'
em++: warning: warnings in JS library compilation [-Wjs-compiler]
 /opt/homebrew/Cellar/emscripten/6.0.5/libexec/binaryen/bin/wasm-opt --safe-heap out.wasm -oout.wasm --mvp-features --enable-bulk-memory --enable-bulk-memory-opt --enable-call-indirect-overlong --enable-multivalue --enable-mutable-globals --enable-nontrapping-float-to-int --enable-reference-types --enable-sign-ext
[parse exception: popping from empty stack (at 0:683)]
Fatal: error parsing wasm (try --debug for more info)
em++: error: '/opt/homebrew/Cellar/emscripten/6.0.5/libexec/binaryen/bin/wasm-opt --safe-heap out.wasm -o out.wasm --mvp-features --enable-bulk-memory --enable-bulk-memory-opt --enable-call-indirect-overlong --enable-multivalue --enable-mutable-globals --enable-nontrapping-float-to-int --enable-reference-types --enable-sign-ext' failed (returned 1)

Full link command and output with -v appended:

Here's a repro script you can modify or use as is:

#!/bin/bash
set -e

WORKDIR=$(mktemp -d)
cd "$WORKDIR"
echo "Working in $WORKDIR"

cat > functable.c << 'EOF'
void (*t)();
void x();
void o() {
  void (*local)() = x;
  __atomic_store(&t, &local, 5);
  __atomic_thread_fence(5);
  t();
}
EOF

cat > main.cxx << 'EOF'
#include <emscripten.h>
extern "C" void o();
extern "C" EMSCRIPTEN_KEEPALIVE void load() {
    o();
}
EOF

echo "--- compiling functable.c (-O1 -fPIC) ---"
emcc -O1 -fPIC -c -o functable.o functable.c

echo "--- compiling main.cxx ---"
em++ -c -o main.o main.cxx

echo "--- linking ---"
LINK_FLAGS="-sASSERTIONS -sERROR_ON_UNDEFINED_SYMBOLS=0 -sSAFE_HEAP=1 -sEXPORTED_FUNCTIONS=_malloc"

set +e
em++ $LINK_FLAGS -o out.js main.o functable.o
LINK_STATUS=$?
set -e

echo
echo "=== link exit status: $LINK_STATUS ==="
if [ -f out.wasm ]; then
  echo "=== wasm-validate output ==="
  if command -v wasm-validate >/dev/null 2>&1; then
    wasm-validate --enable-all out.wasm || true
  else
    echo "wasm-validate not found on PATH"
  fi
else
  echo "out.wasm was not produced"
fi

echo
if [ "$LINK_STATUS" -ne 0 ]; then
  echo "reproduces"
else
  echo "failed to reproduce"
fi
主要言語
C++
スター
27.8k
フォーク
3.6k
平均マージ
1日 3時間
マージ済み PR(30日)
179

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

emscripten-core/emscripten のほかの issue

emscripten-core/emscripten の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。