-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Sudden failure to link statically on Arch Linux #43647
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
Comments
Downgrading musl package to version 1.1.16-1 does not help. Any other options for testing? |
Can you paste the output of |
env -u LD_PRELOAD ldd -v ./target/x86_64-unknown-linux-musl/debug/bla
That seems fine then. The My issue came up when I was trying to run the statically linked executables under Alpine Linux, as before. See this weird situation: sudo env UNIFIED_CGROUP_HIERARCHY=no \
rkt run --insecure-options=image docker://alpine:3.5 \
--volume=bla,kind=host,source=/tmp/bla/target/x86_64-unknown-linux-musl/debug/ \
--mount volume=bla,target=/bla/ \
--exec=/bin/sh -- -c 'ldd -- /bla/bla; stat /bla/bla; /bla/bla; stat /lib64/ld-linux-x86-64.so.2'
Seems the interpreter path isn't correct. |
I've just tried to follow your steps on the latest nightly and I can't reproduce this - Your choice of the version of musl package shouldn't make a difference (unless it's related to the custom packaging I mention) because Rust bundles the musl |
Heh, it appears I had rustup installed as an Arch Linux package and via the common installer. Also, |
I can reproduce this as well with rustup-managed 1.19 on Arch, but not on Debian Jessie, where the file type is
It seems like it'd probably have to do with the way Arch's musl toolchain is configured? |
Though it looks like you haven't told rustc to use |
@sfackler unless I've misunderstood the intent, linking a static binary with the musl target should not require a custom linker unless this is an oddity of arch. In fact, the host musl toolchain should be totally unused (unless depending on a crate that invokes |
Ah! There is a difference between Debian and Arch's musl-gcc wrappers - Debian's pulls in spec files that disable PIE in addition to the normal MUSL one. This custom linker setup produces fully static binaries on Arch: test-gcc #!/bin/sh
exec "${REALGCC:-gcc}" "$@" -specs "$HOME/no-pie-compile.specs" -specs "$HOME/no-pie-link.specs" no-pie-link.specs
It looks like we may want to disable PIE for MUSL targets. |
We already appear to not enable PIE for MUSL targets, but it looks like we should actually explicitly be disabling PIE rather than relying on the linker default.
|
Some linkers (e.g. Debian and Arch's) that are configured to make PIEs by default will make dynamically linked executables that don't actually dynamically link to anything. Fix that by explicitly passing -no-pie in those cases. Closes rust-lang#43647
It seems like #40113 may resolve this. |
Nominating for prioritization, though it looks like this is potentially already fixed? Confirmation would be good. |
Discussed in the compiler team meeting. P-high, we want to keep an eye on this. |
#40113 seems close to landing, just a final bug or two to iron out. @sfackler I'm curious though shouldn't we land #43693 regardless? It seems like a "more correct" patch regardless of what happens to the musl target? We may just stop exercising it once #40113 lands. |
I haven't been following #40113 super closely, but it seemed like it'd end up generating statically linked PIE executables, which seems better than statically linked non-PIE executables, right? |
Looking at this again, this is tagged as a regression but we don't know what caused it. @sanmai-NL do you have a way for me to reproduce locally? Failing that, do you know when this stopped working? If so, you wouldn't happen to know the relevant change, would you? @sfackler oh sure yeah I don't even remember at this point why musl is non-PIE. If we have future targets that are not PIE (for whatever reason) though it seems like they could benefit from #43693 |
@alexcrichton: mkdir /tmp/bla/ || rm -fr /tmp/bla/ &&
sudo env UNIFIED_CGROUP_HIERARCHY=no \
rkt run --insecure-options=image 'docker://stephank/archlinux:makepkg' \
--net=host \
--dns=host \
--user=0 \
--working-dir='/bla/' \
--volume=bla,kind=host,source=/tmp/bla/ \
--mount volume=bla,target=/bla/ \
--exec=/bin/sh -- -c '
set -x
yes | pacman -Sy rustup musl pax-utils &&
rustup install nightly-x86_64-unknown-linux-gnu &&
rustup default nightly-x86_64-unknown-linux-gnu &&
rustup target add x86_64-unknown-linux-musl &&
cargo init --bin --name bla --vcs none . &&
env RUSTFLAGS="-C target-feature=+crt-static" \
cargo build --target x86_64-unknown-linux-musl &&
file target/x86_64-unknown-linux-musl/debug/bla
scanelf -ain target/x86_64-unknown-linux-musl/debug/bla
target/x86_64-unknown-linux-musl/debug/bla'
sudo env UNIFIED_CGROUP_HIERARCHY=no \
rkt run --insecure-options=image 'docker://alpine' \
--working-dir='/bla/' \
--net=host \
--dns=host \
--volume=bla,kind=host,source=/tmp/bla/ \
--mount volume=bla,target=/bla/ \
--exec=/bin/sh -- -c '
set -x
apk add --update file
target/x86_64-unknown-linux-musl/debug/bla
ldd target/x86_64-unknown-linux-musl/debug/bla
file target/x86_64-unknown-linux-musl/debug/bla' On my own system the issue is still present though. Apparently the regression is between the age of the Docker image and the date of this GitHub issue. Apparently that is two months. |
@sfackler due to my most recent comment I believe we will end up needing #43693 regardless. |
Some linkers (e.g. Debian and Arch's) that are configured to make PIEs by default will make dynamically linked executables that don't actually dynamically link to anything. Fix that by explicitly passing -no-pie in those cases. Closes rust-lang#43647
#44070 didn't land in the latest nightly, but I compiled it myself. on my host ubuntu:16.04:
i.e. still works fine then continuing in the same terminal with arch:
i.e. I verified I could reproduce with stable rust, but the recompiled rust fixes the issue. I'm going to close this since all the pieces are are in place and you should be able to take advantage in the next nightly. Ping me or open an issue if you have any other issues - thanks for reporting! |
It's always worked before. Turning back to compiling Rust after some period of other activities, and found out my binaries don't work anymore.
Actual
Expected
A description of an executable statically linked to musl libc.
Meta
OS
Arch Linux with
musl
package version1.1.16-2
.The text was updated successfully, but these errors were encountered: