@@ -44,89 +44,94 @@ use crate::spec::{LinkOutputKind, MaybeLazy};
44
44
use std:: borrow:: Cow ;
45
45
use std:: collections:: BTreeMap ;
46
46
47
- pub type CrtObjects = BTreeMap < LinkOutputKind , Vec < Cow < ' static , str > > > ;
48
- pub type LazyCrtObjects = MaybeLazy < CrtObjects > ;
47
+ type LazyCrtObjectsArgs = & ' static [ ( LinkOutputKind , & ' static [ & ' static str ] ) ] ;
48
+ pub struct LazyCrtObjectsState ( LazyCrtObjectsArgs ) ;
49
49
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 LazyCrtObjectsState {
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
+ }
52
55
}
53
56
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 , LazyCrtObjectsState > ;
59
+
60
+ #[ inline]
61
+ pub ( super ) fn new ( obj_table : LazyCrtObjectsArgs ) -> LazyCrtObjects {
62
+ MaybeLazy :: lazied ( LazyCrtObjectsState ( obj_table) )
63
63
}
64
64
65
- pub ( super ) fn pre_musl_self_contained ( ) -> LazyCrtObjects {
66
- MaybeLazy :: lazy ( || {
65
+ macro_rules! all {
66
+ ( $obj : literal ) => {
67
67
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" ] ) ,
68
+ ( LinkOutputKind :: DynamicNoPicExe , & [ $obj ] ) ,
69
+ ( LinkOutputKind :: DynamicPicExe , & [ $obj ] ) ,
70
+ ( LinkOutputKind :: StaticNoPicExe , & [ $obj ] ) ,
71
+ ( LinkOutputKind :: StaticPicExe , & [ $obj ] ) ,
72
+ ( LinkOutputKind :: DynamicDylib , & [ $obj ] ) ,
73
+ ( LinkOutputKind :: StaticDylib , & [ $obj ] ) ,
74
74
] )
75
- } )
75
+ } ;
76
+ }
77
+
78
+ pub ( super ) fn pre_musl_self_contained ( ) -> LazyCrtObjects {
79
+ new ( & [
80
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
81
+ ( LinkOutputKind :: DynamicPicExe , & [ "Scrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
82
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
83
+ ( LinkOutputKind :: StaticPicExe , & [ "rcrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
84
+ ( LinkOutputKind :: DynamicDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
85
+ ( LinkOutputKind :: StaticDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
86
+ ] )
76
87
}
77
88
78
89
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
- } )
90
+ new ( & [
91
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
92
+ ( LinkOutputKind :: DynamicPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
93
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
94
+ ( LinkOutputKind :: StaticPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
95
+ ( LinkOutputKind :: DynamicDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
96
+ ( LinkOutputKind :: StaticDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
97
+ ] )
89
98
}
90
99
91
100
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
- } )
101
+ new ( & [
102
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
103
+ ( LinkOutputKind :: DynamicPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
104
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
105
+ ( LinkOutputKind :: StaticPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
106
+ ( LinkOutputKind :: DynamicDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
107
+ ( LinkOutputKind :: StaticDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
108
+ ] )
102
109
}
103
110
104
111
pub ( super ) fn post_mingw_self_contained ( ) -> LazyCrtObjects {
105
- MaybeLazy :: lazy ( || all ( "rsend.o" ) )
112
+ all ! ( "rsend.o" )
106
113
}
107
114
108
115
pub ( super ) fn pre_mingw ( ) -> LazyCrtObjects {
109
- MaybeLazy :: lazy ( || all ( "rsbegin.o" ) )
116
+ all ! ( "rsbegin.o" )
110
117
}
111
118
112
119
pub ( super ) fn post_mingw ( ) -> LazyCrtObjects {
113
- MaybeLazy :: lazy ( || all ( "rsend.o" ) )
120
+ all ! ( "rsend.o" )
114
121
}
115
122
116
123
pub ( super ) fn pre_wasi_self_contained ( ) -> LazyCrtObjects {
117
124
// Use crt1-command.o instead of crt1.o to enable support for new-style
118
125
// 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
- } )
126
+ new ( & [
127
+ ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1-command.o" ] ) ,
128
+ ( LinkOutputKind :: DynamicPicExe , & [ "crt1-command.o" ] ) ,
129
+ ( LinkOutputKind :: StaticNoPicExe , & [ "crt1-command.o" ] ) ,
130
+ ( LinkOutputKind :: StaticPicExe , & [ "crt1-command.o" ] ) ,
131
+ ( LinkOutputKind :: WasiReactorExe , & [ "crt1-reactor.o" ] ) ,
132
+ ] )
128
133
}
129
134
130
135
pub ( super ) fn post_wasi_self_contained ( ) -> LazyCrtObjects {
131
- MaybeLazy :: lazy ( || new ( & [ ] ) )
136
+ new ( & [ ] )
132
137
}
0 commit comments