Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target mips-unknown-linux-musl and mipsel-unknown-linux-musl are not statically linked. #80693

Closed
abcfy2 opened this issue Jan 4, 2021 · 5 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries A-target-specs Area: compile-target specifications C-bug Category: This is a bug. O-linux Operating system: Linux O-MIPS Target: MIPS processors O-musl Target: The musl libc

Comments

@abcfy2
Copy link

abcfy2 commented Jan 4, 2021

Here issue is from: rust-lang/cargo#9039

Meta

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0

Problem

Target mips-unknown-linux-musl and mipsel-unknown-linux-musl are not statically linked, maybe it's an rustc issue?

Steps

  1. download build toolchain from: musl.cc
  2. cargo new cargo-hello && cd cargo-hello
  3. cargo build --target mips-unknown-linux-musl or cargo build --target mipsel-unknown-linux-musl
  4. file target/<target>/debug/cargo-hello

Here is my ~/.cargo/config

[target.aarch64-unknown-linux-musl]
linker = "/home/fengyu/projects/cross_prefix/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc"

[target.arm-unknown-linux-musleabi]
linker = "/home/fengyu/projects/cross_prefix/arm-linux-musleabi-cross/bin/arm-linux-musleabi-gcc"

[target.mips-unknown-linux-musl]
linker = "/home/fengyu/projects/cross_prefix/mips-linux-musl-cross/bin/mips-linux-musl-gcc"

[target.mips64-unknown-linux-muslabi64]
linker = "/home/fengyu/projects/cross_prefix/mips64-linux-musl-cross/bin/mips64-linux-musl-gcc"

[target.mips64el-unknown-linux-muslabi64]
linker = "/home/fengyu/projects/cross_prefix/mips64el-linux-musl-cross/bin/mips64el-linux-musl-gcc"

[target.mipsel-unknown-linux-musl]
linker = "/home/fengyu/projects/cross_prefix/mipsel-linux-musl-cross/bin/mipsel-linux-musl-gcc"

[target.x86_64-unknown-linux-musl]
linker = "/home/fengyu/projects/cross_prefix/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc"

I find only mips-unknown-linux-musl and mipsel-unknown-linux-musl are not staticlly linked.

$ echo aarch64-unknown-linux-musl arm-unknown-linux-musleabi mips-unknown-linux-musl mips64-unknown-linux-muslabi64 mips64el-unknown-linux-muslabi64 mipsel-unknown-linux-musl x86_64-unknown-linux-musl | xargs -n 1 rustup target add
$ echo aarch64-unknown-linux-musl arm-unknown-linux-musleabi mips-unknown-linux-musl mips64-unknown-linux-muslabi64 mips64el-unknown-linux-muslabi64 mipsel-unknown-linux-musl x86_64-unknown-linux-musl | xargs -n 1 cargo build --target
$ file target/*/debug/cargo-hello
target/aarch64-unknown-linux-musl/debug/cargo-hello:       ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, with debug_info, not stripped
target/arm-unknown-linux-musleabi/debug/cargo-hello:       ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
target/mips64el-unknown-linux-muslabi64/debug/cargo-hello: ELF 64-bit LSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), statically linked, with debug_info, not stripped
target/mips64-unknown-linux-muslabi64/debug/cargo-hello:   ELF 64-bit MSB executable, MIPS, MIPS64 rel2 version 1 (SYSV), statically linked, with debug_info, not stripped
target/mipsel-unknown-linux-musl/debug/cargo-hello:        ELF 32-bit LSB pie executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mipsel.so.1, with debug_info, not stripped
target/mips-unknown-linux-musl/debug/cargo-hello:          ELF 32-bit MSB pie executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mips.so.1, with debug_info, not stripped
target/x86_64-unknown-linux-musl/debug/cargo-hello:        ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped

Notes

Output of cargo version: cargo 1.49.0 (d00d64df9 2020-12-05)

@abcfy2 abcfy2 added the C-bug Category: This is a bug. label Jan 4, 2021
@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries A-target-specs Area: compile-target specifications O-linux Operating system: Linux O-MIPS Target: MIPS processors labels Jan 4, 2021
@Darlelet
Copy link

Darlelet commented May 7, 2021

Seems that x86_64-unknown-linux-musl is also affected (from your output).

I checked myself, still the case in cargo 1.52.0 (69767412a 2021-04-21)

1.41.0 and earlier used to work just fine:

  • testbinstatic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug info, not stripped -> OK
  • testbindynamic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld64.so.1, with debug info, not stripped -> OK

1.52.0:

  • testbinstatic: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped -> NOK
  • testbindynamic: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, with debug_info, not stripped -> NOK

The real issue there is that for expected static binaries we end up with dynamically linked bin, and for expected dynamic binaries: no linking is done to the default interpreter.
Trying to run it on the target system will make the program crash (because of missing interpreter initialization)

I'm forced to revert to cargo v1.41 to make my build system (X86_64 cross compile) functional.

@jonas-schievink
Copy link
Contributor

cc rust-lang/compiler-team#422, which suggests that these targets behave correctly

@zengming00
Copy link

I use this configuration and it works

[target.mips-unknown-linux-musl]
linker = "mips-linux-musl-gcc"
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s"]

@abcfy2
Copy link
Author

abcfy2 commented May 30, 2021

I use this configuration and it works

[target.mips-unknown-linux-musl]
linker = "mips-linux-musl-gcc"
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-s"]

I think this feature should enable by default. https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html As cargo official blog said, musl support for fully static binaries.

@workingjubilee
Copy link
Contributor

Unfortunately, we have decided that was the wrong default. You may still enable this feature on purpose, and we do support that and will continue to support that. See here:

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-target-specs Area: compile-target specifications C-bug Category: This is a bug. O-linux Operating system: Linux O-MIPS Target: MIPS processors O-musl Target: The musl libc
Projects
None yet
Development

No branches or pull requests

6 participants