wasmtime: Cranelift: assertion `left == right` failed: the memory base pointer may be incorrect due to sharing memory

Steps to Reproduce

I have a binary (wasm-ld, which is lld from the LLVM distribution) built with wasi-sdk-22.0 for the wasm32-wasi-threads target, with CFLAGS of -pthread and LDFLAGS of -Wl,--max-memory=4294967296. It is built with debug symbols using the normal LLVM mechanism (RelWithDebInfo). It is too big to include here but I believe the relevant excerpt is:

  (memory (;0;) 53 65536 shared)
  (export "memory" (memory 0))

I run the binary with RUST_BACKTRACE=full WASMTIME_BACKTRACE_DETAILS=1 wasmtime -S threads --dir . --dir /tmp -D debug-info -D address-map ./llvm-build/bin/wasm-ld <...arguments that cause a trap...>.

Expected Results

A backtrace with Wasm-level symbols is displayed.

Actual Results

An assertion failure in Cranelift.
thread 'main' panicked at /home/whitequark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-cranelift-20.0.2/src/compiler.rs:559:13:
assertion `left == right` failed: the memory base pointer may be incorrect due to sharing memory
  left: 1
 right: 0
stack backtrace:
   0:     0x55f64b236496 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h402f02d9b4df5fe1
   1:     0x55f64b262c4c - core::fmt::write::h8fddb4828840201f
   2:     0x55f64b23234f - std::io::Write::write_fmt::h38b9b1a6a63dbb61
   3:     0x55f64b236244 - std::sys_common::backtrace::print::h98a1789ae7f04118
   4:     0x55f64b237a3b - std::panicking::default_hook::{{closure}}::hbf9ed991ae15cec9
   5:     0x55f64b237789 - std::panicking::default_hook::h0e9a403389616b5a
   6:     0x55f64b237edd - std::panicking::rust_panic_with_hook::h47d6ea0dd5408232
   7:     0x55f64b237db2 - std::panicking::begin_panic_handler::{{closure}}::h92169a5d672aa955
   8:     0x55f64b236976 - std::sys_common::backtrace::__rust_end_short_backtrace::h78311f5de6c73a58
   9:     0x55f64b237ae4 - rust_begin_unwind
  10:     0x55f649eb0a15 - core::panicking::panic_fmt::h9fcc2d8bb7eb13a8
  11:     0x55f649eb0e8f - core::panicking::assert_failed_inner::h77eb1113bacb0f31
  12:     0x55f649e588af - core::panicking::assert_failed::he44b2686efc08dff
  13:     0x55f64abe2d30 - <wasmtime_cranelift::compiler::Compiler as wasmtime_environ::compile::Compiler>::append_dwarf::h14d11c20fa9e5f82
  14:     0x55f64aafb697 - wasmtime::compile::FunctionIndices::link_and_append_code::hf766901eb87a60b8
  15:     0x55f64aaf4c31 - wasmtime::compile::build_artifacts::h1809dbb6af98174d
  16:     0x55f64ab4360c - core::ops::function::FnOnce::call_once::h8f5620eee6192dd4
  17:     0x55f64ab6bdc5 - wasmtime_cache::ModuleCacheEntry::get_data_raw::h5918a4673179324b
  18:     0x55f64ab4f059 - wasmtime::compile::runtime::<impl wasmtime::compile::code_builder::CodeBuilder>::compile_module::h6cfb67fd1fb024ce
  19:     0x55f649ee4dec - wasmtime_cli::common::RunCommon::load_module::h0243b5cafcaca8ef
  20:     0x55f649fd2f2a - wasmtime_cli::commands::run::RunCommand::execute::h741dadf6ee6383ad
  21:     0x55f649eb9c01 - wasmtime::Wasmtime::execute::h9f6abe47b919fe59
  22:     0x55f649eb5088 - wasmtime::old_cli::main::hbf2a698a610c379d
  23:     0x55f649eb69a3 - std::sys_common::backtrace::__rust_begin_short_backtrace::h2d92647e84e7ad00
  24:     0x55f649eb69bd - std::rt::lang_start::{{closure}}::h3b525ebc181e5daf
  25:     0x55f64b228533 - std::rt::lang_start_internal::hb867f343d27fa61e
  26:     0x55f649ebb4a5 - main
  27:     0x7f85f8f3f24a - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  28:     0x7f85f8f3f305 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  29:     0x55f649eb10c1 - _start
  30:                0x0 - <unknown>

Versions and Environment

Cranelift version or commit: wasmtime-cranelift-20.0.2

Operating system: Linux

Architecture: x86_64

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 24 (24 by maintainers)

Commits related to this issue

Most upvoted comments

I had to pass -O0 to wasm-ld (which, while we’re at it, is an incredibly unintuitive flag–it took me literal years and the compiler driver source to find out that it removes the wasm-opt invocation; made worse by the fact that wasm-opt corrupts the debug info)

FWIW, a number of us are frustrated at the default llvm behavior here to invoke wasm-opt automagically if it’s found in the path (and only if – nondeterministic builds!). You can find a (very) long thread of folks discovering this footgun and registering new reasons for it to be removed at llvm/llvm-project#55781 (nothing would be more welcome than to fix this imho; I’ve been bitten by it a handful of times too). In the meantime, a workaround a number of folks have found – and even used in quasi-official places like WASI builds of SpiderMonkey in various SDKs – is to prepend a fake wasm-opt to the path that is an empty shell script (with exit 0 or whatever). Perhaps we should document this footgun and workaround somewhere.