-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
rustc 1.59/1.60 builds musl binaries that segfault, when compiling with musl-gcc wrappers, due to static-pie default #95926
Copy link
Copy link
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.O-muslTarget: The musl libcTarget: The musl libcP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnosticsregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.O-muslTarget: The musl libcTarget: The musl libcP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnosticsregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Fields
Give feedbackNo fields configured for issues without a type.
With the
x86_64-unknown-linux-musltarget installed:A
gdbbacktrace shows the segfault in_start_c () at ../src_musl/crt/../ldso/dlstart.c:141.This segfault happens because the
musl-gccwrappers (including cross-compile wrappers likex86_64-linux-musl-gccandaarch64-linux-musl-gcc) don't support static-pie in the way rustc is invoking them.This is a regression in Rust 1.59 and 1.60; 1.58 and before produced working binaries. 1.59 includes #70740 , which not only marked the musl targets as supporting static-pie (which they may or may not depending on the linker), but also made x86_64-unknown-linux-musl default to static-pie.
For context, the
musl-gccwrappers are commonly used for a variety of reasons, including cross-compilation (particularly when linking native C code). Attempting to link usingx86_64-linux-gnu-gccoraarch64-linux-gnu-gcccross-compilers (rather than the corresponding-musl-gcccross-compilers) produces compatibility issues, especially with projects that build and link native C dependencies.I noticed this problem when working with someone trying to cross-compile a project from aarch64 to x86-64, using the x86_64-linux-musl-gcc cross-compiler wrapper, installed via Debian. (I hadn't previously noticed the regression myself, because I hadn't arranged to use the cross-compiler wrappers on x86_64 since my native host is x86_64.)
This problem doesn't currently show up when cross-compiling from x86_64 to aarch64, since aarch64 doesn't use static-pie by default, but enabling PIE with
-C relocation-model=pietriggers the same bug and makes the resulting binaries segfault.I'm currently working around this, but I think this is a stable regression.
(For reference, two possible workarounds: use
-C relocation-model=static, or uselinker=x86_64-linux-gnu-gccand hope it works for you.)