public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/rust] f44: Add a `-static-pie` fallback when `rcrt1.o` is missing
@ 2026-10-20 17:59 Josh Stone
0 siblings, 0 replies; only message in thread
From: Josh Stone @ 2026-10-20 17:59 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/rust
Branch : f44
Commit : 29d7b25adbfdb113642b75461646277683c0f76a
Author : Josh Stone <jistone@redhat.com>
Date : 2026-10-19T10:10:59-07:00
Stats : +65/-1 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/rust/c/29d7b25adbfdb113642b75461646277683c0f76a?branch=f44
Log:
Add a `-static-pie` fallback when `rcrt1.o` is missing
---
diff --git a/0001-Add-a-fallback-for-static-pie-missing-CRT-objects.patch b/0001-Add-a-fallback-for-static-pie-missing-CRT-objects.patch
new file mode 100644
index 0000000..a0bf6ba
--- /dev/null
+++ b/0001-Add-a-fallback-for-static-pie-missing-CRT-objects.patch
@@ -0,0 +1,55 @@
+From 4332bd9e92063767333e53d32af2d035109adf04 Mon Sep 17 00:00:00 2001
+From: Josh Stone <jistone@redhat.com>
+Date: Fri, 16 Oct 2026 17:44:34 -0700
+Subject: [PATCH] Add a fallback for `-static-pie` missing CRT objects
+
+We already have a fallback when the linker doesn't support `-static-pie`
+to use plain `-static` instead. However, it is also possible that the
+linker understands that option, but the C library doesn't have the
+necessary CRT objects. For example, `gcc` has known this option for a
+long time, but `glibc` doesn't support it for `powerpc` targets at all.
+We can detect this case in the link output for `-static` fallback too.
+---
+ compiler/rustc_codegen_ssa/src/back/link.rs | 22 ++++++++++++++-------
+ 1 file changed, 15 insertions(+), 7 deletions(-)
+
+diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
+index a7540e294ec3..622ac2a905d7 100644
+--- a/compiler/rustc_codegen_ssa/src/back/link.rs
++++ b/compiler/rustc_codegen_ssa/src/back/link.rs
+@@ -1349,17 +1349,25 @@ fn link_natively(
+ continue;
+ }
+
+- // Detect '-static-pie' used with an older version of gcc or clang not supporting it.
+- // Fallback from '-static-pie' to '-static' in that case.
++ // Detect '-static-pie' used with an older version of gcc or clang not supporting it,
++ // or with glibc that's missing crt objects, e.g. for arches that don't support it.
++ // Fallback from '-static-pie' to '-static' in either case.
++ let mut static_pie_message = None;
+ if matches!(flavor, LinkerFlavor::Gnu(Cc::Yes, _))
+- && unknown_arg_regex.is_match(&out)
+- && (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
+ && cmd.get_args().iter().any(|e| e == "-static-pie")
+ {
++ if unknown_arg_regex.is_match(&out)
++ && (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
++ {
++ static_pie_message =
++ Some("Linker does not support -static-pie command line option.");
++ } else if Regex::new(r"cannot (find|open) g?rcrt1\.o:").unwrap().is_match(&out) {
++ static_pie_message = Some("C library is missing static-PIE startup objects.");
++ }
++ }
++ if let Some(message) = static_pie_message {
+ info!("linker output: {:?}", out);
+- warn!(
+- "Linker does not support -static-pie command line option. Retrying with -static instead."
+- );
++ warn!("{message} Retrying with -static instead.");
+ // Mirror `add_(pre,post)_link_objects` to replace CRT objects.
+ let self_contained_crt_objects = self_contained_components.is_crt_objects_enabled();
+ let opts = &sess.target;
+--
+2.55.0
+
diff --git a/rust.spec b/rust.spec
index 795be86..c8f8d2e 100644
--- a/rust.spec
+++ b/rust.spec
@@ -159,7 +159,12 @@ Patch7: 0001-only-copy-rustlib-into-stage0-sysroot.patch
Patch8: 0001-Enable-SHSTK-by-default-on-x86_64-unknown-linux-gnu.patch
# Ensure llvm worker threads have sufficient stack space. Backport of #163289.
-Patch9: 0001-Ensure-llvm-worker-threads-have-sufficient-stack-spa.patch
+Patch9: 0001-Ensure-llvm-worker-threads-have-sufficient-stack-spa.patch
+
+# Add a `-static-pie` fallback when `rcrt1.o` is missing
+# https://github.com/rust-lang/rust/issues/164448
+# https://github.com/rust-lang/rust/pull/164451
+Patch10: 0001-Add-a-fallback-for-static-pie-missing-CRT-objects.patch
### RHEL-specific patches below ###
@@ -741,6 +746,7 @@ test "$(cut -d' ' -f1 ./version)" = "%{lua: print((rpm.expand('%version'):gsub('
%patch -P7 -p1
%patch -P8 -p1
%patch -P9 -p1
+%patch -P10 -p1
%if %with disabled_libssh2
%patch -P100 -p1
@@ -1095,6 +1101,9 @@ TMP_HELLO=$(mktemp -d)
%{buildroot}%{_bindir}/cargo init --name hello-world
%{buildroot}%{_bindir}/cargo run --verbose
+ # Sanity-check that a static executable builds and runs
+ env RUSTFLAGS="-Ctarget-feature=+crt-static" %{buildroot}%{_bindir}/cargo run --verbose
+
# Sanity-check that code-coverage builds and runs
env RUSTFLAGS="-Cinstrument-coverage" %{buildroot}%{_bindir}/cargo run --verbose
test -r default_*.profraw
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-20 17:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 17:59 [rpms/rust] f44: Add a `-static-pie` fallback when `rcrt1.o` is missing Josh Stone
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox