Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

staticlib for wasm32 targets have missing dependencies #75089

Closed
Labels
A-linkageArea: linking into static, shared libraries and binaries C-bugCategory: This is a bug. O-wasmTarget: WASM (WebAssembly), http://webassembly.org/ T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
@osa1

Description

~ $ rustc --version --verbose
rustc 1.46.0-nightly (346aec9b0 2020年07月11日)
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020年07月11日
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0
~ $ cargo --version --verbose
cargo 1.46.0-nightly (4f74d9b2a 2020年07月08日)
release: 1.46.0
commit-hash: 4f74d9b2a771c58b7ef4906b2668afd075bc8081
commit-date: 2020年07月08日
~ $ xargo --version --verbose
xargo 0.3.22
+ "cargo" "--version" "--verbose"
cargo 1.46.0-nightly (4f74d9b2a 2020年07月08日)
release: 1.46.0
commit-hash: 4f74d9b2a771c58b7ef4906b2668afd075bc8081
commit-date: 2020年07月08日

(I asked this on Zulip 4 days ago but got no answers, and I think this is a bug somewhere in the toolchain, so posting here with more details)

A "staticlib" should include all dependencies of the Rust crate and should be linkable with libraries and executables generated by other languages. However it seems like this currently does not hold.

Here's an example. To run, make sure you have xargo, llvm-10, and wabt installed (xargo is needed because core and std for wasm32 are not built with PIC relocation model and can't be used for creating shared libraries) and run ./build.sh. It'll generate a libfinal.wat file. If you open it in your editor you'll see this line:

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

This is a Rust dependency that is not included in the final library and imported. Because we're using "staticlib" crate type this should not happen: all dependencies should be in the library already and there shouldn't be any imports.

I should also note that I can do the same (compile Rust crate to staticlib, link it with C code to a shared library) for x86_64 target.

I tried to understand where does this import come from. If I unpack the generated .a file and generate .wat for the .o files I see that the function is defined in a file called core-b5d07d1a52bf60be.core.au5sshbb-cgu.4.rcgu.o. I guess the "core" here means it's defined in "core" rather than in my code. Then there's another file called rs_nostd_core_lib_1-4e8f00c808934bbd.rs_nostd_core_lib_1.dk7ycmpp-cgu.2.rcgu.o.wat, which I think is generated for my code, which imports this function both from "env" (correct) and from "func.GOT" (incorrect). The relevant lines from the file:

(module
 ...
 (import "env" "_ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT3ドルfmt17h9ba9fea9cadf7bd5E" (func (;4;) (type 1)))
 ...
 (import "GOT.func" "_ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT3ドルfmt17h9ba9fea9cadf7bd5E" (global (;2;) (mut i32)))
 ...)

This is the same function imported twice, from different modules. I think the bug is in the GOT.func line.

I'd be happy to help debugging or debug it myself if anyone gives me pointers on where to start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binaries C-bugCategory: This is a bug. O-wasmTarget: WASM (WebAssembly), http://webassembly.org/ 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

        AltStyle によって変換されたページ (->オリジナル) /