Skip to content

Commit 9f26263

Browse files
rustc: Apply target features to the entry function
Link: rust-lang/rust#146144 Signed-off-by: Ilikara <[email protected]>
1 parent 1d0c427 commit 9f26263

5 files changed

+80
-4
lines changed

lang-rust/rustc/autobuild/patches/0001-Add-i486-unknown-linux-gnu-compiler-target.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From c62e1c6dcc6eeb8db7619b6e30e00657b98f5162 Mon Sep 17 00:00:00 2001
22
From: Jiajie Chen <[email protected]>
33
Date: Fri, 9 Feb 2024 18:48:33 -0800
4-
Subject: [PATCH 1/3] Add i486-unknown-linux-gnu compiler target
4+
Subject: [PATCH 1/4] Add i486-unknown-linux-gnu compiler target
55

66
---
77
compiler/rustc_target/src/spec/mod.rs | 1 +

lang-rust/rustc/autobuild/patches/0002-ARCHLINUX-compiler-Swap-primary-and-secondary-lib-di.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From d775cc8d435c34ad5147161c5082775bc1a0f45b Mon Sep 17 00:00:00 2001
22
From: "Jan Alexander Steffens (heftig)" <[email protected]>
33
Date: Thu, 7 Aug 2025 20:12:53 +0200
4-
Subject: [PATCH 2/3] ARCHLINUX: compiler: Swap primary and secondary lib dirs
4+
Subject: [PATCH 2/4] ARCHLINUX: compiler: Swap primary and secondary lib dirs
55

66
Arch Linux (editor's note: also AOSC OS) prefers "lib" over "lib64".
77
---

lang-rust/rustc/autobuild/patches/0003-ARCHLINUX-bootstrap-Workaround-for-system-stage0.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From 4558c3cef1db12eb171c992e12c88a53b79101ed Mon Sep 17 00:00:00 2001
22
From: "Jan Alexander Steffens (heftig)" <[email protected]>
33
Date: Thu, 7 Aug 2025 19:01:26 +0200
4-
Subject: [PATCH 3/3] ARCHLINUX: bootstrap: Workaround for system stage0
4+
Subject: [PATCH 3/4] ARCHLINUX: bootstrap: Workaround for system stage0
55

66
See: https://github.com/rust-lang/rust/issues/143735
77
---
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
From 3f3b1288db7f4e21337ddfa107e42211dafebee0 Mon Sep 17 00:00:00 2001
2+
From: WANG Rui <[email protected]>
3+
Date: Wed, 3 Sep 2025 11:34:15 +0800
4+
Subject: [PATCH 4/4] compiler: Apply target features to the entry function
5+
6+
---
7+
compiler/rustc_codegen_gcc/src/context.rs | 4 ++++
8+
compiler/rustc_codegen_llvm/src/context.rs | 10 ++++++++++
9+
compiler/rustc_codegen_ssa/src/base.rs | 1 +
10+
compiler/rustc_codegen_ssa/src/traits/misc.rs | 2 ++
11+
4 files changed, 17 insertions(+)
12+
13+
diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs
14+
index ff141ad365..bf873cd156 100644
15+
--- a/compiler/rustc_codegen_gcc/src/context.rs
16+
+++ b/compiler/rustc_codegen_gcc/src/context.rs
17+
@@ -489,6 +489,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
18+
// TODO(antoyo)
19+
}
20+
21+
+ fn apply_target_features(&self, _llfn: Function<'gcc>) {
22+
+ // TODO(antoyo)
23+
+ }
24+
+
25+
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
26+
let entry_name = self.sess().target.entry_name.as_ref();
27+
if !self.functions.borrow().contains_key(entry_name) {
28+
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs
29+
index 0324dff6ff..029855700d 100644
30+
--- a/compiler/rustc_codegen_llvm/src/context.rs
31+
+++ b/compiler/rustc_codegen_llvm/src/context.rs
32+
@@ -819,6 +819,16 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
33+
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);
34+
}
35+
36+
+ fn apply_target_features(&self, llfn: &'ll Value) {
37+
+ let mut attrs = SmallVec::<[_; 2]>::new();
38+
+ let global_features = self.tcx.global_backend_features(()).iter().map(|s| s.as_str());
39+
+ let target_features: String = global_features.intersperse(",").collect();
40+
+ if !target_features.is_empty() {
41+
+ attrs.push(llvm::CreateAttrStringValue(self.llcx, "target-features", &target_features));
42+
+ }
43+
+ attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);
44+
+ }
45+
+
46+
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
47+
let entry_name = self.sess().target.entry_name.as_ref();
48+
if self.get_declared_value(entry_name).is_none() {
49+
diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs
50+
index a3d6c73ba8..9b1a734c6b 100644
51+
--- a/compiler/rustc_codegen_ssa/src/base.rs
52+
+++ b/compiler/rustc_codegen_ssa/src/base.rs
53+
@@ -546,6 +546,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
54+
// `main` should respect same config for frame pointer elimination as rest of code
55+
cx.set_frame_pointer_type(llfn);
56+
cx.apply_target_cpu_attr(llfn);
57+
+ cx.apply_target_features(llfn);
58+
59+
let llbb = Bx::append_block(cx, llfn, "top");
60+
let mut bx = Bx::build(cx, llbb);
61+
diff --git a/compiler/rustc_codegen_ssa/src/traits/misc.rs b/compiler/rustc_codegen_ssa/src/traits/misc.rs
62+
index 710fab2790..24218d4ed0 100644
63+
--- a/compiler/rustc_codegen_ssa/src/traits/misc.rs
64+
+++ b/compiler/rustc_codegen_ssa/src/traits/misc.rs
65+
@@ -23,6 +23,8 @@ pub trait MiscCodegenMethods<'tcx>: BackendTypes {
66+
fn sess(&self) -> &Session;
67+
fn set_frame_pointer_type(&self, llfn: Self::Function);
68+
fn apply_target_cpu_attr(&self, llfn: Self::Function);
69+
+ /// Apply global target features to a given LLVM function.
70+
+ fn apply_target_features(&self, llfn: Self::Function);
71+
/// Declares the extern "C" main function for the entry point. Returns None if the symbol
72+
/// already exists.
73+
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function>;
74+
--
75+
2.51.0
76+

lang-rust/rustc/spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
VER=1.89.0
2-
REL=1
2+
REL=2
33
# Note: Uncomment this if we have the last version built and ready.
44
SRCS="tbl::https://static.rust-lang.org/dist/rustc-${VER}-src.tar.xz"
55
CHKSUMS="sha256::0b9d55610d8270e06c44f459d1e2b7918a5e673809c592abed9b9c600e33d95a"

0 commit comments

Comments
 (0)