parse exception: popping from empty stack

未关闭
#27,525 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
c, cpp, shell, wasm
领域
compilers

调研方向

使用 emcc 和 em++ 运行提供的 shell 复现脚本;检查生成的 out.wasm 在 wasm-opt --safe-heap 步骤附近的内容,并在可用时使用 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 天 10 小时
30 天内合并 PR
177

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

emscripten-core/emscripten 的其他 Issue

查看 emscripten-core/emscripten 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。