Skip to content

Commit 47b7197

Browse files
committed
Move CRT Objects to stateful MaybeLazy
1 parent 7c3b6c9 commit 47b7197

File tree

4 files changed

+72
-70
lines changed

4 files changed

+72
-70
lines changed

compiler/rustc_target/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1313
#![doc(rust_logo)]
1414
#![feature(assert_matches)]
15+
#![feature(fn_traits)]
1516
#![feature(iter_intersperse)]
1617
#![feature(let_chains)]
1718
#![feature(min_exhaustive_patterns)]
1819
#![feature(rustc_attrs)]
1920
#![feature(rustdoc_internals)]
21+
#![feature(unboxed_closures)]
2022
// tidy-alphabetical-end
2123

2224
use std::path::{Path, PathBuf};

compiler/rustc_target/src/spec/base/aix.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::abi::Endian;
2+
use crate::spec::TargetOptions;
23
use crate::spec::{crt_objects, cvs, Cc, CodeModel, LinkOutputKind, LinkerFlavor};
3-
use crate::spec::{MaybeLazy, TargetOptions};
44

55
pub fn opts() -> TargetOptions {
66
TargetOptions {
@@ -23,12 +23,10 @@ pub fn opts() -> TargetOptions {
2323
is_like_aix: true,
2424
default_dwarf_version: 3,
2525
function_sections: true,
26-
pre_link_objects: MaybeLazy::lazy(|| {
27-
crt_objects::new(&[
28-
(LinkOutputKind::DynamicNoPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
29-
(LinkOutputKind::DynamicPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
30-
])
31-
}),
26+
pre_link_objects: crt_objects::new(&[
27+
(LinkOutputKind::DynamicNoPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
28+
(LinkOutputKind::DynamicPicExe, &["/usr/lib/crt0_64.o", "/usr/lib/crti_64.o"]),
29+
]),
3230
dll_suffix: ".a".into(),
3331
..Default::default()
3432
}

compiler/rustc_target/src/spec/base/fuchsia.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ pub fn opts() -> TargetOptions {
3434
dynamic_linking: true,
3535
families: cvs!["unix"],
3636
pre_link_args,
37-
pre_link_objects: MaybeLazy::lazy(|| {
38-
crt_objects::new(&[
39-
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),
40-
(LinkOutputKind::DynamicPicExe, &["Scrt1.o"]),
41-
(LinkOutputKind::StaticNoPicExe, &["Scrt1.o"]),
42-
(LinkOutputKind::StaticPicExe, &["Scrt1.o"]),
43-
])
44-
}),
37+
pre_link_objects: crt_objects::new(&[
38+
(LinkOutputKind::DynamicNoPicExe, &["Scrt1.o"]),
39+
(LinkOutputKind::DynamicPicExe, &["Scrt1.o"]),
40+
(LinkOutputKind::StaticNoPicExe, &["Scrt1.o"]),
41+
(LinkOutputKind::StaticPicExe, &["Scrt1.o"]),
42+
]),
4543
position_independent_executables: true,
4644
has_thread_local: true,
4745
frame_pointer: FramePointer::NonLeaf,

compiler/rustc_target/src/spec/crt_objects.rs

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,89 +44,93 @@ use crate::spec::{LinkOutputKind, MaybeLazy};
4444
use std::borrow::Cow;
4545
use std::collections::BTreeMap;
4646

47-
pub type CrtObjects = BTreeMap<LinkOutputKind, Vec<Cow<'static, str>>>;
48-
pub type LazyCrtObjects = MaybeLazy<CrtObjects>;
47+
type Tralala = &'static [(LinkOutputKind, &'static [&'static str])];
48+
pub struct Trulala(Tralala);
4949

50-
pub(super) fn new(obj_table: &[(LinkOutputKind, &[&'static str])]) -> CrtObjects {
51-
obj_table.iter().map(|(z, k)| (*z, k.iter().map(|b| (*b).into()).collect())).collect()
50+
impl FnOnce<()> for Trulala {
51+
type Output = CrtObjects;
52+
extern "rust-call" fn call_once(self, _args: ()) -> Self::Output {
53+
self.0.iter().map(|(z, k)| (*z, k.iter().map(|b| (*b).into()).collect())).collect()
54+
}
5255
}
5356

54-
pub(super) fn all(obj: &'static str) -> CrtObjects {
55-
new(&[
56-
(LinkOutputKind::DynamicNoPicExe, &[obj]),
57-
(LinkOutputKind::DynamicPicExe, &[obj]),
58-
(LinkOutputKind::StaticNoPicExe, &[obj]),
59-
(LinkOutputKind::StaticPicExe, &[obj]),
60-
(LinkOutputKind::DynamicDylib, &[obj]),
61-
(LinkOutputKind::StaticDylib, &[obj]),
62-
])
57+
pub type CrtObjects = BTreeMap<LinkOutputKind, Vec<Cow<'static, str>>>;
58+
pub type LazyCrtObjects = MaybeLazy<CrtObjects, Trulala>;
59+
60+
pub(super) fn new(obj_table: Tralala) -> LazyCrtObjects {
61+
MaybeLazy::lazied(Trulala(obj_table))
6362
}
6463

65-
pub(super) fn pre_musl_self_contained() -> LazyCrtObjects {
66-
MaybeLazy::lazy(|| {
64+
macro_rules! all {
65+
($obj: literal) => {
6766
new(&[
68-
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
69-
(LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]),
70-
(LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
71-
(LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o", "crtbeginS.o"]),
72-
(LinkOutputKind::DynamicDylib, &["crti.o", "crtbeginS.o"]),
73-
(LinkOutputKind::StaticDylib, &["crti.o", "crtbeginS.o"]),
67+
(LinkOutputKind::DynamicNoPicExe, &[$obj]),
68+
(LinkOutputKind::DynamicPicExe, &[$obj]),
69+
(LinkOutputKind::StaticNoPicExe, &[$obj]),
70+
(LinkOutputKind::StaticPicExe, &[$obj]),
71+
(LinkOutputKind::DynamicDylib, &[$obj]),
72+
(LinkOutputKind::StaticDylib, &[$obj]),
7473
])
75-
})
74+
};
75+
}
76+
77+
pub(super) fn pre_musl_self_contained() -> LazyCrtObjects {
78+
new(&[
79+
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
80+
(LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]),
81+
(LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
82+
(LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o", "crtbeginS.o"]),
83+
(LinkOutputKind::DynamicDylib, &["crti.o", "crtbeginS.o"]),
84+
(LinkOutputKind::StaticDylib, &["crti.o", "crtbeginS.o"]),
85+
])
7686
}
7787

7888
pub(super) fn post_musl_self_contained() -> LazyCrtObjects {
79-
MaybeLazy::lazy(|| {
80-
new(&[
81-
(LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
82-
(LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
83-
(LinkOutputKind::StaticNoPicExe, &["crtend.o", "crtn.o"]),
84-
(LinkOutputKind::StaticPicExe, &["crtendS.o", "crtn.o"]),
85-
(LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.o"]),
86-
(LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.o"]),
87-
])
88-
})
89+
new(&[
90+
(LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
91+
(LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
92+
(LinkOutputKind::StaticNoPicExe, &["crtend.o", "crtn.o"]),
93+
(LinkOutputKind::StaticPicExe, &["crtendS.o", "crtn.o"]),
94+
(LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.o"]),
95+
(LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.o"]),
96+
])
8997
}
9098

9199
pub(super) fn pre_mingw_self_contained() -> LazyCrtObjects {
92-
MaybeLazy::lazy(|| {
93-
new(&[
94-
(LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]),
95-
(LinkOutputKind::DynamicPicExe, &["crt2.o", "rsbegin.o"]),
96-
(LinkOutputKind::StaticNoPicExe, &["crt2.o", "rsbegin.o"]),
97-
(LinkOutputKind::StaticPicExe, &["crt2.o", "rsbegin.o"]),
98-
(LinkOutputKind::DynamicDylib, &["dllcrt2.o", "rsbegin.o"]),
99-
(LinkOutputKind::StaticDylib, &["dllcrt2.o", "rsbegin.o"]),
100-
])
101-
})
100+
new(&[
101+
(LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]),
102+
(LinkOutputKind::DynamicPicExe, &["crt2.o", "rsbegin.o"]),
103+
(LinkOutputKind::StaticNoPicExe, &["crt2.o", "rsbegin.o"]),
104+
(LinkOutputKind::StaticPicExe, &["crt2.o", "rsbegin.o"]),
105+
(LinkOutputKind::DynamicDylib, &["dllcrt2.o", "rsbegin.o"]),
106+
(LinkOutputKind::StaticDylib, &["dllcrt2.o", "rsbegin.o"]),
107+
])
102108
}
103109

104110
pub(super) fn post_mingw_self_contained() -> LazyCrtObjects {
105-
MaybeLazy::lazy(|| all("rsend.o"))
111+
all!("rsend.o")
106112
}
107113

108114
pub(super) fn pre_mingw() -> LazyCrtObjects {
109-
MaybeLazy::lazy(|| all("rsbegin.o"))
115+
all!("rsbegin.o")
110116
}
111117

112118
pub(super) fn post_mingw() -> LazyCrtObjects {
113-
MaybeLazy::lazy(|| all("rsend.o"))
119+
all!("rsend.o")
114120
}
115121

116122
pub(super) fn pre_wasi_self_contained() -> LazyCrtObjects {
117123
// Use crt1-command.o instead of crt1.o to enable support for new-style
118124
// commands. See https://reviews.llvm.org/D81689 for more info.
119-
MaybeLazy::lazy(|| {
120-
new(&[
121-
(LinkOutputKind::DynamicNoPicExe, &["crt1-command.o"]),
122-
(LinkOutputKind::DynamicPicExe, &["crt1-command.o"]),
123-
(LinkOutputKind::StaticNoPicExe, &["crt1-command.o"]),
124-
(LinkOutputKind::StaticPicExe, &["crt1-command.o"]),
125-
(LinkOutputKind::WasiReactorExe, &["crt1-reactor.o"]),
126-
])
127-
})
125+
new(&[
126+
(LinkOutputKind::DynamicNoPicExe, &["crt1-command.o"]),
127+
(LinkOutputKind::DynamicPicExe, &["crt1-command.o"]),
128+
(LinkOutputKind::StaticNoPicExe, &["crt1-command.o"]),
129+
(LinkOutputKind::StaticPicExe, &["crt1-command.o"]),
130+
(LinkOutputKind::WasiReactorExe, &["crt1-reactor.o"]),
131+
])
128132
}
129133

130134
pub(super) fn post_wasi_self_contained() -> LazyCrtObjects {
131-
MaybeLazy::lazy(|| new(&[]))
135+
new(&[])
132136
}

0 commit comments

Comments
 (0)