Skip to content

Compiling WebAssembly with --pie fails with missing __heap_base symbol #155173

@Creative0708

Description

@Creative0708

I tried this code:

// src/lib.rs
// anything works, this is just the most minimal cdylib crate that should compile
#![no_std]

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    loop {}
}

With this Cargo.toml:

[package]
name = "a"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]

And this command:

RUSTFLAGS="-Clink-args=--pie -Cpanic=abort" cargo +nightly-2026-04-06 build --target wasm32-unknown-unknown -Zbuild-std=core

I expected to see this happen: Code produces a WASM module with no errors

Instead, this happened: Code fails to link:

   Compiling compiler_builtins v0.1.160 (/home/***/.rustup/toolchains/nightly-2026-04-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/compiler-builtins/compiler-builtins)
   Compiling core v0.0.0 (/home/***/.rustup/toolchains/nightly-2026-04-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling a v0.1.0 (/tmp/a)
error: linking with `rust-lld` failed: exit status: 1
  |
  = note:  "rust-lld" "-flavor" "wasm" "--export=__heap_base" "--export=__data_end" "-z" "stack-size=1048576" "--stack-first" "--no-demangle" "--no-entry" "<1 object files omitted>" "/tmp/a/target/wasm32-unknown-unknown/release/deps/{libcore-68bb26808566f5b1,libcompiler_builtins-3bf64fec5aa5fa4c}.rlib" "-L" "<sysroot>/lib/rustlib/wasm32-unknown-unknown/lib/self-contained" "-o" "/tmp/a/target/wasm32-unknown-unknown/release/deps/a.wasm" "--gc-sections" "--no-entry" "-O3" "--strip-debug" "--pie"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: warning: creating PIEs, with -pie, is not yet stable
          rust-lld: error: symbol exported via --export not found: __heap_base

error: could not compile `a` (lib) due to 1 previous error

Meta

rustc --version --verbose:

rustc 1.96.0-nightly (9602bda1d 2026-04-05)
binary: rustc
commit-hash: 9602bda1dd0c1bbf5787e398385bbac81fd532f8
commit-date: 2026-04-05
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2

For context: I'm building a dynamic WASM module with -Clink-args=--pie -Crelocation-model=pic, but the latter flag doesn't affect whether it errors or not. On a semi-related note, I do feel like some of the flags (namely --stack-size and --stack-first) shouldn't be there as the __stack_pointer isn't controlled by the module anyways.
If it helps narrow anything down, the nightly-2026-04-01 toolchain builds fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions