Wrong linker used for wasm32-unknown-unknown


#1

I’m trying to build rust on Gentoo with wasm support. There is how I configured rust:

config.toml

[llvm]
optimize = true
release-debuginfo = false
assertions = false
targets = “X86;Mips;NVPTX;BPF;AArch64”
[build]
build = “x86_64-unknown-linux-gnu”
host = [“x86_64-unknown-linux-gnu”]
target = [“i686-unknown-linux-gnu”,“x86_64-unknown-linux-gnu”,“wasm32-unknown-unknown”]
docs = true
submodules = false
python = “python2.7”
locked-deps = true
vendor = false
verbose = 2
sanitizers = true
extended = true
tools=[“src”, “rls”, “analysis”]
[install]
prefix = “/usr”
libdir = “lib64/rust-9999”
docdir = “share/doc/rust-9999”
mandir = “share/rust-9999/man”
[rust]
optimize = true
debuginfo = false
debug-assertions = false
use-jemalloc = true
default-linker = “x86_64-pc-linux-gnu-gcc”
rpath = false
ignore-git = false
[target.i686-unknown-linux-gnu]
cc = “x86_64-pc-linux-gnu-gcc”
cxx = “x86_64-pc-linux-gnu-g++”
linker = “x86_64-pc-linux-gnu-gcc”
ar = “x86_64-pc-linux-gnu-ar”
[target.x86_64-unknown-linux-gnu]
cc = “x86_64-pc-linux-gnu-gcc”
cxx = “x86_64-pc-linux-gnu-g++”
linker = “x86_64-pc-linux-gnu-gcc”
ar = “x86_64-pc-linux-gnu-ar”
[target.wasm32-unknown-unknown]
linker = “ld”

I’ve tried “gcc”, “ld” and none linker in target.wasm32-unknown-unknown but each time it uses x86_64-pc-linux-gnu-gcc and I get error:

rustc --target wasm32-unknown-unknown src/main.rs

$ rustc --target wasm32-unknown-unknown src/main.rs
error: linking with x86_64-pc-linux-gnu-gcc failed: exit code: 1
|
= note: “x86_64-pc-linux-gnu-gcc” “-flavor” “wasm” “-L” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib” “main.main0.rcgu.o” “main.main1.rcgu.o” “main.main2.rcgu.o” “main.main3.rcgu.o” “main.main4.rcgu.o” “-o” “main.wasm” “main.crate.allocator.rcgu.o” “-L” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/libstd-b97479bfdb66b67e.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-1a607150f707a305.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/libunwind-3fd6fcd99b465dfb.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/liblibc-b1b95c23f3849a0e.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/liballoc_system-38f549b4f74afbaf.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-7815ce64da9c7faa.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/liballoc-4dc0f9151b8c66fe.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/libcore-20bbc048326b2cba.rlib” “/usr/lib64/rust-9999/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-ff69777c2859ebcb.rlib” “–no-threads” “-z” “stack-size=1048576” “–allow-undefined” “–no-entry”
= note: x86_64-pc-linux-gnu-gcc: error: wasm: No such file or directory
x86_64-pc-linux-gnu-gcc: error: unrecognized command line option ‘-flavor’; did you mean ‘-flto’?
x86_64-pc-linux-gnu-gcc: error: unrecognized command line option ‘–no-threads’; did you mean ‘–no-ltrans’?
x86_64-pc-linux-gnu-gcc: error: unrecognized command line option ‘–allow-undefined’; did you mean ‘–all-warnings’?
x86_64-pc-linux-gnu-gcc: error: unrecognized command line option ‘–no-entry’; did you mean ‘-mno-fentry’?

What should be used as a linker and how to define it?


#2

I’ve added lld=true to config.toml. But it works only if I adds RUSTFLAGS="-C linker=lld"