4040//! but not gcc's. As a result rustc cannot link with C++ static libraries (#36710)
4141//! when linking in self-contained mode.
4242
43- use crate :: spec:: LinkOutputKind ;
43+ use crate :: spec:: { LinkOutputKind , MaybeLazy } ;
4444use std:: borrow:: Cow ;
4545use std:: collections:: BTreeMap ;
4646
4747pub type CrtObjects = BTreeMap < LinkOutputKind , Vec < Cow < ' static , str > > > ;
48+ pub type LazyCrtObjects = MaybeLazy < CrtObjects > ;
4849
4950pub ( super ) fn new ( obj_table : & [ ( LinkOutputKind , & [ & ' static str ] ) ] ) -> CrtObjects {
5051 obj_table. iter ( ) . map ( |( z, k) | ( * z, k. iter ( ) . map ( |b| ( * b) . into ( ) ) . collect ( ) ) ) . collect ( )
@@ -61,63 +62,71 @@ pub(super) fn all(obj: &'static str) -> CrtObjects {
6162 ] )
6263}
6364
64- pub ( super ) fn pre_musl_self_contained ( ) -> CrtObjects {
65- new ( & [
66- ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
67- ( LinkOutputKind :: DynamicPicExe , & [ "Scrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
68- ( LinkOutputKind :: StaticNoPicExe , & [ "crt1.o" , "crti.o" , "crtbegin.o" ] ) ,
69- ( LinkOutputKind :: StaticPicExe , & [ "rcrt1.o" , "crti.o" , "crtbeginS.o" ] ) ,
70- ( LinkOutputKind :: DynamicDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
71- ( LinkOutputKind :: StaticDylib , & [ "crti.o" , "crtbeginS.o" ] ) ,
72- ] )
65+ pub ( super ) fn pre_musl_self_contained ( ) -> LazyCrtObjects {
66+ MaybeLazy :: lazy ( || {
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" ] ) ,
74+ ] )
75+ } )
7376}
7477
75- pub ( super ) fn post_musl_self_contained ( ) -> CrtObjects {
76- new ( & [
77- ( LinkOutputKind :: DynamicNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
78- ( LinkOutputKind :: DynamicPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
79- ( LinkOutputKind :: StaticNoPicExe , & [ "crtend.o" , "crtn.o" ] ) ,
80- ( LinkOutputKind :: StaticPicExe , & [ "crtendS.o" , "crtn.o" ] ) ,
81- ( LinkOutputKind :: DynamicDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
82- ( LinkOutputKind :: StaticDylib , & [ "crtendS.o" , "crtn.o" ] ) ,
83- ] )
78+ 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+ } )
8489}
8590
86- pub ( super ) fn pre_mingw_self_contained ( ) -> CrtObjects {
87- new ( & [
88- ( LinkOutputKind :: DynamicNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
89- ( LinkOutputKind :: DynamicPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
90- ( LinkOutputKind :: StaticNoPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
91- ( LinkOutputKind :: StaticPicExe , & [ "crt2.o" , "rsbegin.o" ] ) ,
92- ( LinkOutputKind :: DynamicDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
93- ( LinkOutputKind :: StaticDylib , & [ "dllcrt2.o" , "rsbegin.o" ] ) ,
94- ] )
91+ 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+ } )
95102}
96103
97- pub ( super ) fn post_mingw_self_contained ( ) -> CrtObjects {
98- all ( "rsend.o" )
104+ pub ( super ) fn post_mingw_self_contained ( ) -> LazyCrtObjects {
105+ MaybeLazy :: lazy ( || all ( "rsend.o" ) )
99106}
100107
101- pub ( super ) fn pre_mingw ( ) -> CrtObjects {
102- all ( "rsbegin.o" )
108+ pub ( super ) fn pre_mingw ( ) -> LazyCrtObjects {
109+ MaybeLazy :: lazy ( || all ( "rsbegin.o" ) )
103110}
104111
105- pub ( super ) fn post_mingw ( ) -> CrtObjects {
106- all ( "rsend.o" )
112+ pub ( super ) fn post_mingw ( ) -> LazyCrtObjects {
113+ MaybeLazy :: lazy ( || all ( "rsend.o" ) )
107114}
108115
109- pub ( super ) fn pre_wasi_self_contained ( ) -> CrtObjects {
116+ pub ( super ) fn pre_wasi_self_contained ( ) -> LazyCrtObjects {
110117 // Use crt1-command.o instead of crt1.o to enable support for new-style
111118 // commands. See https://reviews.llvm.org/D81689 for more info.
112- new ( & [
113- ( LinkOutputKind :: DynamicNoPicExe , & [ "crt1-command.o" ] ) ,
114- ( LinkOutputKind :: DynamicPicExe , & [ "crt1-command.o" ] ) ,
115- ( LinkOutputKind :: StaticNoPicExe , & [ "crt1-command.o" ] ) ,
116- ( LinkOutputKind :: StaticPicExe , & [ "crt1-command.o" ] ) ,
117- ( LinkOutputKind :: WasiReactorExe , & [ "crt1-reactor.o" ] ) ,
118- ] )
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+ } )
119128}
120129
121- pub ( super ) fn post_wasi_self_contained ( ) -> CrtObjects {
122- new ( & [ ] )
130+ pub ( super ) fn post_wasi_self_contained ( ) -> LazyCrtObjects {
131+ MaybeLazy :: lazy ( || new ( & [ ] ) )
123132}
0 commit comments