@@ -20,7 +20,7 @@ use rustc_session::utils::NativeLibKind;
2020use rustc_session:: { filesearch, Session } ;
2121use rustc_span:: symbol:: Symbol ;
2222use rustc_span:: DebuggerVisualizerFile ;
23- use rustc_target:: spec:: crt_objects:: { CrtObjects , CrtObjectsFallback } ;
23+ use rustc_target:: spec:: crt_objects:: { CrtObjects , LinkSelfContainedDefault } ;
2424use rustc_target:: spec:: { LinkOutputKind , LinkerFlavor , LldFlavor , SplitDebuginfo } ;
2525use rustc_target:: spec:: { PanicStrategy , RelocModel , RelroLevel , SanitizerSet , Target } ;
2626
@@ -764,15 +764,15 @@ fn link_natively<'a>(
764764 "Linker does not support -static-pie command line option. Retrying with -static instead."
765765 ) ;
766766 // Mirror `add_(pre,post)_link_objects` to replace CRT objects.
767- let self_contained = crt_objects_fallback ( sess, crate_type) ;
767+ let self_contained = self_contained ( sess, crate_type) ;
768768 let opts = & sess. target ;
769769 let pre_objects = if self_contained {
770- & opts. pre_link_objects_fallback
770+ & opts. pre_link_objects_self_contained
771771 } else {
772772 & opts. pre_link_objects
773773 } ;
774774 let post_objects = if self_contained {
775- & opts. post_link_objects_fallback
775+ & opts. post_link_objects_self_contained
776776 } else {
777777 & opts. post_link_objects
778778 } ;
@@ -1556,26 +1556,26 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
15561556 true
15571557}
15581558
1559- /// Whether we link to our own CRT objects instead of relying on gcc to pull them.
1559+ /// Various toolchain components used during linking are used from rustc distribution
1560+ /// instead of being found somewhere on the host system.
15601561/// We only provide such support for a very limited number of targets.
1561- fn crt_objects_fallback ( sess : & Session , crate_type : CrateType ) -> bool {
1562+ fn self_contained ( sess : & Session , crate_type : CrateType ) -> bool {
15621563 if let Some ( self_contained) = sess. opts . cg . link_self_contained {
15631564 return self_contained;
15641565 }
15651566
1566- match sess. target . crt_objects_fallback {
1567+ match sess. target . link_self_contained {
1568+ LinkSelfContainedDefault :: False => false ,
1569+ LinkSelfContainedDefault :: True => true ,
15671570 // FIXME: Find a better heuristic for "native musl toolchain is available",
15681571 // based on host and linker path, for example.
15691572 // (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
1570- Some ( CrtObjectsFallback :: Musl ) => sess. crt_static ( Some ( crate_type) ) ,
1571- Some ( CrtObjectsFallback :: Mingw ) => {
1573+ LinkSelfContainedDefault :: Musl => sess. crt_static ( Some ( crate_type) ) ,
1574+ LinkSelfContainedDefault :: Mingw => {
15721575 sess. host == sess. target
15731576 && sess. target . vendor != "uwp"
15741577 && detect_self_contained_mingw ( & sess)
15751578 }
1576- // FIXME: Figure out cases in which WASM needs to link with a native toolchain.
1577- Some ( CrtObjectsFallback :: Wasm ) => true ,
1578- None => false ,
15791579 }
15801580}
15811581
@@ -1592,7 +1592,7 @@ fn add_pre_link_objects(
15921592 let opts = & sess. target ;
15931593 let empty = Default :: default ( ) ;
15941594 let objects = if self_contained {
1595- & opts. pre_link_objects_fallback
1595+ & opts. pre_link_objects_self_contained
15961596 } else if !( sess. target . os == "fuchsia" && flavor == LinkerFlavor :: Gcc ) {
15971597 & opts. pre_link_objects
15981598 } else {
@@ -1610,9 +1610,11 @@ fn add_post_link_objects(
16101610 link_output_kind : LinkOutputKind ,
16111611 self_contained : bool ,
16121612) {
1613- let opts = & sess. target ;
1614- let objects =
1615- if self_contained { & opts. post_link_objects_fallback } else { & opts. post_link_objects } ;
1613+ let objects = if self_contained {
1614+ & sess. target . post_link_objects_self_contained
1615+ } else {
1616+ & sess. target . post_link_objects
1617+ } ;
16161618 for obj in objects. get ( & link_output_kind) . iter ( ) . copied ( ) . flatten ( ) {
16171619 cmd. add_object ( & get_object_file_path ( sess, obj, self_contained) ) ;
16181620 }
@@ -1891,12 +1893,12 @@ fn linker_with_args<'a>(
18911893 out_filename : & Path ,
18921894 codegen_results : & CodegenResults ,
18931895) -> Result < Command , ErrorGuaranteed > {
1894- let crt_objects_fallback = crt_objects_fallback ( sess, crate_type) ;
1896+ let self_contained = self_contained ( sess, crate_type) ;
18951897 let cmd = & mut * super :: linker:: get_linker (
18961898 sess,
18971899 path,
18981900 flavor,
1899- crt_objects_fallback ,
1901+ self_contained ,
19001902 & codegen_results. crate_info . target_cpu ,
19011903 ) ;
19021904 let link_output_kind = link_output_kind ( sess, crate_type) ;
@@ -1923,7 +1925,7 @@ fn linker_with_args<'a>(
19231925 // ------------ Object code and libraries, order-dependent ------------
19241926
19251927 // Pre-link CRT objects.
1926- add_pre_link_objects ( cmd, sess, flavor, link_output_kind, crt_objects_fallback ) ;
1928+ add_pre_link_objects ( cmd, sess, flavor, link_output_kind, self_contained ) ;
19271929
19281930 add_linked_symbol_object (
19291931 cmd,
@@ -2033,7 +2035,7 @@ fn linker_with_args<'a>(
20332035 cmd,
20342036 sess,
20352037 link_output_kind,
2036- crt_objects_fallback ,
2038+ self_contained ,
20372039 flavor,
20382040 crate_type,
20392041 codegen_results,
@@ -2049,7 +2051,7 @@ fn linker_with_args<'a>(
20492051 // ------------ Object code and libraries, order-dependent ------------
20502052
20512053 // Post-link CRT objects.
2052- add_post_link_objects ( cmd, sess, link_output_kind, crt_objects_fallback ) ;
2054+ add_post_link_objects ( cmd, sess, link_output_kind, self_contained ) ;
20532055
20542056 // ------------ Late order-dependent options ------------
20552057
@@ -2066,7 +2068,7 @@ fn add_order_independent_options(
20662068 cmd : & mut dyn Linker ,
20672069 sess : & Session ,
20682070 link_output_kind : LinkOutputKind ,
2069- crt_objects_fallback : bool ,
2071+ self_contained : bool ,
20702072 flavor : LinkerFlavor ,
20712073 crate_type : CrateType ,
20722074 codegen_results : & CodegenResults ,
@@ -2098,7 +2100,7 @@ fn add_order_independent_options(
20982100 // Make the binary compatible with data execution prevention schemes.
20992101 cmd. add_no_exec ( ) ;
21002102
2101- if crt_objects_fallback {
2103+ if self_contained {
21022104 cmd. no_crt_objects ( ) ;
21032105 }
21042106
@@ -2127,7 +2129,7 @@ fn add_order_independent_options(
21272129
21282130 cmd. linker_plugin_lto ( ) ;
21292131
2130- add_library_search_dirs ( cmd, sess, crt_objects_fallback ) ;
2132+ add_library_search_dirs ( cmd, sess, self_contained ) ;
21312133
21322134 cmd. output_filename ( out_filename) ;
21332135
0 commit comments