Description
I am using https://github.com/richfelker/musl-cross-make to generate a mips-linux-musl
compiler to build mips-unknown-linux-musl
, as it's tier 3 and needs -Zbuild-std
.
First off, I needed to add a couple of -L
to the config, in order to not have Could not find crt0
problems. I don't know if this is a rustc bug, or a cross-compiler bug.
However, the bug that I can't figure out, is that for static binaries(and/or panic=abort
) it still needs the -lunwind
library. Nevertheless, It seems like this should be something it finds from the ~/.rustup/toolchains/
, but nothing I try helps rustc
find this library?
I tried this code:
src/main.rs
:
fn main() {
println!("test");
}
Cargo.toml
:
[profile.release]
strip = true
codegen-units = 1
lto = true
panic = "abort"
opt-level = "z"
.cargo/config
:
[build]
rustflags = [
"-C", "target-feature=+crt-static",
"-L", "/home/wcampbell/projects/wcampbell/musl-cross-make/output/mips-linux-musl/lib",
"-L", "/home/wcampbell/projects/wcampbell/musl-cross-make/output/lib/gcc/mips-linux-musl/9.4.0/",
]
[target.mips-unknown-linux-musl]
linker = "/home/wcampbell/projects/wcampbell/musl-cross-make/output/bin/mips-linux-musl-gcc"
[unstable]
build-std = ["core", "compiler_builtins", "alloc", "std", "panic_abort"]
I expected to see this happen: Statically compiled mips-musl binary with -Zbuild-std
Instead, this happened:
$ cargo build --bin mempeek --locked --release --target mips-unknown-linux-musl
error: linking with `/home/wcampbell/projects/wcampbell/musl-cross-make/output/bin/mips-linux-musl-gcc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/wcampbell/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl" VSLANG="1033" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/bin/mips-linux-musl-gcc" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/mips-linux-musl/lib/crt1.o" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/mips-linux-musl/lib/crti.o" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/lib/gcc/mips-linux-musl/9.4.0/crtbegin.o" "/tmp/rustc2DONcX/symbols.o" "/home/wcampbell/projects/wcampbell/mempeek/target/mips-unknown-linux-musl/release/deps/mempeek-840512eed390a4d1.mempeek.eea5b45178c2269e-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/wcampbell/projects/wcampbell/mempeek/target/mips-unknown-linux-musl/release/deps" "-L" "/home/wcampbell/projects/wcampbell/mempeek/target/release/deps" "-L" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/mips-linux-musl/lib" "-L" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/lib/gcc/mips-linux-musl/9.4.0/" "-L" "/home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mips-unknown-linux-musl/lib" "-Wl,-Bstatic" "-lunwind" "-lc" "/home/wcampbell/projects/wcampbell/mempeek/target/mips-unknown-linux-musl/release/deps/libcompiler_builtins-2264a038ec2e250c.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-nostartfiles" "-L" "/home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mips-unknown-linux-musl/lib" "-L" "/home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mips-unknown-linux-musl/lib/self-contained" "-o" "/home/wcampbell/projects/wcampbell/mempeek/target/mips-unknown-linux-musl/release/deps/mempeek-840512eed390a4d1" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-all" "-nodefaultlibs" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/lib/gcc/mips-linux-musl/9.4.0/crtend.o" "/home/wcampbell/projects/wcampbell/musl-cross-make/output/mips-linux-musl/lib/crtn.o"
= note: /home/wcampbell/projects/wcampbell/musl-cross-make/output/bin/../lib/gcc/mips-linux-musl/9.4.0/../../../../mips-linux-musl/bin/ld: cannot find -lunwind
collect2: error: ld returned 1 exit status
Meta
rustc --version --verbose
:
rustc --version --verbose
rustc 1.77.0-nightly (5bd5d214e 2024-01-25)
binary: rustc
commit-hash: 5bd5d214effd494f4bafb29b3a7a2f6c2070ca5c
commit-date: 2024-01-25
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6