Stream: t-compiler/help

Topic: Undefined symbols in staticlib compiled to wasm32?

osa1 (Jul 30 2020 at 14:26, on Zulip):

According to the reference "staticlib" should include dependencies of the crate and allow linking the crate with non-Rust programs. In I have an example project setup where I build a "staticlib" crate, and link it with a C library into a shared library, targeting wasm32-unknown-emscripten. I already do this stuff using C and Rust and it works. However the problem when I target wasm32 is I get undefined Rust 'core' symbols, which are compiled to "GOT.func" imports, as a result the final Wasm library is not really linkable.

I'm not sure that this is a bug in rustc, maybe it's a bug in LLVM (the code generator), or in wasm-ld, or maybe I'm doing something wrong. I'm wondering how to debug this. The question basically is why do I get those "GOT.func" imports.

To reproduce make sure you have llvm-10 and xargo installed and have nightly Rust, and run ./ You'll see a file "libfinal.wat". If you open it you'll see this import:

(import "GOT.func" "_ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17h9ba9fea9cadf7bd5E" (global (;3;) (mut i32)))

This basically means there's a Rust function not defined in this shared library file, which seems wrong as the crate is compiled to a "staticlib" which should include all dependencies.

Does anyone have any ideas? Thanks.

osa1 (Aug 03 2020 at 08:33, on Zulip):

I moved this to Rust issue tracker:

Last update: Sep 27 2020 at 14:30UTC