-
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
rustc 1.59/1.60 builds musl binaries that segfault, when compiling with musl-gcc wrappers, due to static-pie default #95926
Comments
Unfortunately Rust 1.59 produces binaries that segfault when compiled with musl-gcc wrappers. Which is exactly how we produce out aarch64 and musl binaries for the release. See: rust-lang/rust#95926 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
Unfortunately Rust 1.59 produces binaries that segfault when compiled with musl-gcc wrappers. Which is exactly how we produce out aarch64 and musl binaries for the release. See: rust-lang/rust#95926 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
Can you provide the linker command? |
|
rust/compiler/rustc_codegen_ssa/src/back/linker.rs Lines 382 to 402 in 327caac
The musl-gcc wrapper don't recongnize -static-pie/-pie/-no-pie, but do recongnize -static. The combination of
Fedora fix this https://src.fedoraproject.org/rpms/musl/blob/rawhide/f/musl-1.2.0-Support-static-pie-with-musl-gcc-specs.patch and Debian don't have this patch. |
thanks @12101111 for the investigation. This looks like a distro specific issue that should be probably handled by them, correct? Just trying to understand if there's an actionable on our side. |
Yes, we can't fix the broken wrapper in our side ( we can detect it but can't fix it expect creating a new wrapper). |
@apiraino The action on the Rust side would be to roll back the use of this by default until it's more widely supported. Or, alternatively, attempt to detect the use of the wrapper and roll it back in that circumstance, but that seems fraught. |
(Also, long-term, we could fix this by making the wrappers not necessary anymore for cross compiling with musl.) |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-high |
This reverts commit 6a09925. It is now clear that pinning the toolchain for cross compilation is not necessary since we only use it for building to aarch64: rust-lang/rust#95926 (comment) "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=pie triggers the same bug and makes the resulting binaries segfault." Fixes: cloud-hypervisor#3962 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This reverts commit 6a09925. It is now clear that pinning the toolchain for cross compilation is not necessary since we only use it for building to aarch64: rust-lang/rust#95926 (comment) "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=pie triggers the same bug and makes the resulting binaries segfault." Fixes: #3962 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This seems possibly related to two issues I've been having: But when I try to follow this example, the second command gives me:
|
At this point I doubt we would roll-back the default setting, at least not silently. (Maybe via an MCP or something, if there was a push.) But I suspect the best short term act to take would be a diagnostic warning when we attempt to compile with the known-to-be-problematic combination of flags? @joshtriplett would that satisify you here? |
@pnkfelix Some kind of detection and warning would be helpful at a minimum, yes. |
Discussed at 2023-Q1 P-high review I'm willing (*) to mentor someone who would like to add the aforementioned detection+issuing-of-diagnostic of the problematic combination of flags. I'm mainly wondering whether doing so will be E-easy, or E-medium. (*): However, I will be away from computers for a week, coming back on 2023-04-24. So not available to mentor until late April at earliest. You can probably find someone who can assist. I'll try to write up some guidance in the meantime. |
I don't understand this whatever this is about, but in case this helps anyone here, I used to set
And it totally worked, but now it causes a segfault. Both |
With the
x86_64-unknown-linux-musl
target installed:A
gdb
backtrace shows the segfault in_start_c () at ../src_musl/crt/../ldso/dlstart.c:141
.This segfault happens because the
musl-gcc
wrappers (including cross-compile wrappers likex86_64-linux-musl-gcc
andaarch64-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-gcc
wrappers are commonly used for a variety of reasons, including cross-compilation (particularly when linking native C code). Attempting to link usingx86_64-linux-gnu-gcc
oraarch64-linux-gnu-gcc
cross-compilers (rather than the corresponding-musl-gcc
cross-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=pie
triggers 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-gcc
and hope it works for you.)The text was updated successfully, but these errors were encountered: