-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Builds on *-unknown-linux-musl that link to C libaries produce broken binaries #108878
Comments
Edit: updated reproduction steps to make them copy-pasteable |
Updating title since I've now reproduced this on amd64 as wel. |
This should be moved to the rust repository I think; rustup isn't involved in the construction of the binaries in the distribution packages |
There's a likely explanation and some more thorough research on this bug in the downstream issue tracker. |
Ok, so the summary is mixed static-and-dylib linking on musl without the static-crt option The link from @WhyNotHugo has more details |
Still an issue with cc: @Amanieu |
I think that the patch in Alpine that tweaks this behaviour is musl-fix-linux_musl_base.patch. I'm not 100% certain though, there's a few other downstream patches. |
i don't think the selfcontained crt object set makes a difference for what default ldso is used. you can probably tweak that patch and leave the first lines untouched, and keep only the |
I think this happening because libxkbcommon.a is not found so it links against libxkbcommon.so.1, which itself dynamically links to glibc. If you install libxkbcommon.a, does this fix the issue? |
> ldd /usr/lib/libxkbcommon.so.0
/lib/ld-musl-x86_64.so.1 (0x7fd7dddb4000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fd7dddb4000) There's no glibc on this host. I tried installing > strace ./target/debug/reproducer
execve("./target/debug/reproducer", ["./target/debug/reproducer"], 0x7ffcf1583680 /* 77 vars */) = 0
arch_prctl(ARCH_SET_FS, 0x7f42a765c8e8) = 0
set_tid_address(0x7f42a765ca98) = 13314
poll([{fd=0, events=0}, {fd=1, events=0}, {fd=2, events=0}], 3, 0) = 0 (Timeout)
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f42a7636006}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGSEGV, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RT_1 RT_2], NULL, 8) = 0
rt_sigaction(SIGSEGV, {sa_handler=0x7f42a760d1a0, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0x7f42a7636006}, NULL, 8) = 0
rt_sigaction(SIGBUS, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
rt_sigaction(SIGBUS, {sa_handler=0x7f42a760d1a0, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0x7f42a7636006}, NULL, 8) = 0
sigaltstack(NULL, {ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}) = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f42a75e3000
mprotect(0x7f42a75e3000, 4096, PROT_NONE) = 0
sigaltstack({ss_sp=0x7f42a75e4000, ss_flags=0, ss_size=8192}, NULL) = 0
brk(NULL) = 0x555556e6f000
brk(0x555556e71000) = 0x555556e71000
mmap(0x555556e6f000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x555556e6f000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f42a75e2000
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=NULL} ---
rt_sigaction(SIGSEGV, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f42a7636006}, NULL, 8) = 0
rt_sigreturn({mask=[]}) = 139924253016624
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=NULL} ---
+++ killed by SIGSEGV +++
zsh: segmentation fault strace ./target/debug/reproducer The output of
|
The problem is that rustc is expecting to build a static binary (and is passing the static-exe crt*.o files for it to the linker), but the linker is somehow ending up producing a dynamically linked binary. I believe this is because of the This could be fixed in the xkbcommon crate by checking for the |
Incidentally this seems to be a duplicate of #102993. |
i had arrived at a conclusion of something like this long ago (downstream in alpine, someone diffed a working/broken linker invocation and found exactly this Bdynamic issue, but we never followed it up ourselves). the issue is that this is inherently quite fragile- there aren't any warnings or failures or anything of the sort, just a silently added -Bdynamic in certain linkage cases that immediately yield you a broken output. perhaps there should be a diagnostic that having +crt-static with static-exe and any dynamic output is fundamentally broken (at least on -musl)? diagnostic aside however, the fact that arbitrary crates can have a
yes, it seems to be exactly that issue. it seems that these discussions always become slightly tangential however, in that the discussion ends up centering around 'whether -musl is dynamic by default' or similar, instead of the root cause of +crt-static producing the broken output regardless of what the default is or not (maybe just a pet peeve of mine). i notice you found why it does that default Bdynamic however, so thank you :) i was looking a long time ago and didn't come upon that exact location. |
Can you give #111698 a try to see if it fixes the issue? I'm having a bit of trouble building a proper musl target on my end. |
Problem
I'm trying to build the following minimal example:
I'm buildling on
aarch64-unknown-linux-musl
, and my target isaarch64-unknown-linux-musl
(e.g.: there's no cross-compiling going on here).The above builds fine, but the resulting binary fails to run:
The resulting binary is clearly linked against glibc, which is not present here:
Steps
Possible Solution(s)
Not sure, I think there's something wrong with the binaries that rustup ships.
Notes
Using cargo/rust/etc from Alpine repositories works fine. It's the binaries pulled by rustup that are faulty somehow.
Originally reported at the library I was trying to use (rust-x-bindings/xkbcommon-rs#37), but eventually realised it seems to be an issue with the binaries that
rustup
pulls.Rustup version
Installed toolchains
The text was updated successfully, but these errors were encountered: