WebAssembly / WebAssembly/binaryen

shared:ERROR: unexpected error while trying to eval ctors Fatal: ...stopping since could not flatten memory

Open
#2,418 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

Hi. I am receiving this error when building a WASM project with the upstream emscripten backend and with pthreads enabled:

shared:ERROR: unexpected error while trying to eval ctors:
Fatal:   ...stopping since could not flatten memory

I first build boost libs system, thread, chrono, serialization, filesystem, and regex with -s USE_PTHREADS=1 -s ALLOW_MEMORY_GROWTH=0 passed to emcc and -pthread passed to cxxflags.

Then I build my source project which links to the boost libs as static libraries with -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=10 -s PROXY_TO_PTHREAD=1 -s ALLOW_MEMORY_GROWTH=0 passed to emcc and -pthread passed to cxxflags.

In what appears to be one of the final steps of linking, I get this error if and only if pthreads are enabled in boost and my project source. If I don't use pthreads, both projects build and link successfully, but then I cannot use emscripten's Fetch API synchronously, which is my end goal.

I cannot find any search results on this error except the original source code in wasm-ctor-eval.cpp so it not a commonly encountered problem.

I am not using the ported boost in emscripten-ports. Perhaps I need to?

The project will ultimately be run in node. Perhaps PR #9745 is relevant?

Any advice? Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the pthread-enabled Emscripten build described in the issue, then inspect Binaryen's src/tools/wasm-ctor-eval.cpp around line 338 where the reported error originates. Compare builds with and without pthreads and with the referenced PR #9745 context; done means identifying the cause of the memory-flattening failure and confirming a successful link or a documented incompatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.