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

Static musl hello-world segfaults on nixos #81987

Closed
g-w1 opened this issue Feb 11, 2021 · 5 comments
Closed

Static musl hello-world segfaults on nixos #81987

g-w1 opened this issue Feb 11, 2021 · 5 comments
Labels
C-bug Category: This is a bug.

Comments

@g-w1
Copy link

g-w1 commented Feb 11, 2021

I tried this code:

cargo new bug
cd bug
cargo build --target x86_64-unknown-linux-musl
./target/x86_64-unknown-linux-musl/debug/bug
> Segmentation fault (core dumped)

I expected to have it say hello world.

Instead, this happened:

(gdb) r
Starting program: /tmp/bug/target/x86_64-unknown-linux-musl/debug/bug

Program received signal SIGSEGV, Segmentation fault.
0x000055555555916b in _start_c ()
(gdb) bt
#0  0x000055555555916b in _start_c ()
#1  0x00007fffffffbb89 in ?? ()
#2  0x00000000bfebfbff in ?? ()
#3  0x0000000000000064 in ?? ()
#4  0x0000000000000000 in ?? ()
(gdb)

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

I am on nixos 20.09.2812.f18fbc33930 (Nightingale)
uname -a: Linux dell 5.4.93 #1-NixOS SMP Wed Jan 27 10:47:55 UTC 2021 x86_64 GNU/Linux

@g-w1 g-w1 added the C-bug Category: This is a bug. label Feb 11, 2021
@JustAnotherStrange
Copy link

Cannot reproduce on EndeavourOS (Arch based) - creates a statically linked binary just fine. Must be an issue related to NixOS.

$ rustc --version --verbose
rustc 1.52.0-nightly (07194ffcd 2021-02-10)
binary: rustc
commit-hash: 07194ffcd25b0871ce560b9f702e52db27ac9f77
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
$ uname -a 
Linux dell 5.10.15-arch1-1 #1 SMP PREEMPT Wed, 10 Feb 2021 18:32:40 +0000 x86_64 GNU/Linux

@cole-h
Copy link

cole-h commented Feb 26, 2021

Also can't reproduce, but on NixOS.

$ rustc --version --verbose
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.50.0
$ uname -a
Linux scadrial 5.11.1-zen1 #1-NixOS ZEN SMP Tue Jan 1 00:00:00 UTC 1980 x86_64 GNU/Linux

Running from NixOS/nixpkgs@cb5f00d -- possibly fixed "recently" (e.g. after the release of 20.09) but not backported?

(Note: I used rustup and added the musl target, since I don't know how to add the musl target in a NixOS-native way... :)

@g-w1
Copy link
Author

g-w1 commented Mar 1, 2021

After some googling, seems like #74757 (probably a dupe) I have to disable PIE and then it works RUSTFLAGS='-C relocation-model=static' cargo build --target=x86_64-unknown-linux-musl. Seems like it warrants a nixos bug as well as maybe a musl one. Here is the nixos one. NixOS/nixpkgs#94228 I think it is due to compiling static musl binaries with gcc on nixos. @cole-h when it said can't find linker cc, did you do nix-shell -p gcc or did you already have cc? I think this is due to how rustc links the final binary with musl. (Not sure though.)

@cole-h
Copy link

cole-h commented Mar 1, 2021

Ah, I have gcc in my environment.systemPackages. That may be why.

@g-w1
Copy link
Author

g-w1 commented Mar 1, 2021

Closing since it is a upstream bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants