Skip to content

extern symbols are always mangled on wasm32-unknown-emscripten #135901

Open
@JaniM

Description

@JaniM

Attempting to compile a program with EMCC_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" cargo build --target wasm32-unknown-emscripten --release results in all extern functions having unpredictable names, whether or not they have #[no_mangle].

I tried this code:

extern "C" {
    fn foo() -> f64;
}

fn main() {
    println!("{}", unsafe { foo() });
}

I expected to see this happen: A generated .js loader with a stub in wasmImports["foo"].

Instead, this happened: The js loader renames the function to a practically random symbol. In this case:

function _foo() {
    abort("missing function: foo")
}
_foo.stub = true;
var wasmImports = {
    // .. more
    y: _foo,
    // .. more
};

Meta

Tested against 1.83.0 and latest nightly.

rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-name-manglingArea: name mangling / decorationC-bugCategory: This is a bug.O-emscriptenTarget: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL!T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions