File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed
compiler/rustc_codegen_ssa/src/back Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -3116,12 +3116,31 @@ fn add_lld_args(
31163116
31173117 let self_contained_linker = self_contained_cli || self_contained_target;
31183118 if self_contained_linker && !sess. opts . cg . link_self_contained . is_linker_disabled ( ) {
3119- for path in sess. get_tools_search_paths ( false ) {
3120- cmd. arg ( {
3121- let mut arg = OsString :: from ( "-B" ) ;
3122- arg. push ( path. join ( "gcc-ld" ) ) ;
3123- arg
3124- } ) ;
3119+ // We tell `cc` where to find the lld wrappers, in a similar way to how we locate
3120+ // codegen-backends dylibs:
3121+ // - in the tool search paths: the sysroot's `rustlib` bin path,
3122+ // - and as a fallback for cases where `--sysroot` only contains a target std: in the
3123+ // - default host sysroot where rustc is currently located.
3124+ let fallback_sysroot_paths = filesearch:: sysroot_candidates ( )
3125+ . into_iter ( )
3126+ . map ( |sysroot| filesearch:: make_target_bin_path ( & sysroot, config:: host_triple ( ) ) ) ;
3127+
3128+ let mut linker_path_exists = false ;
3129+ for path in sess. get_tools_search_paths ( false ) . into_iter ( ) . chain ( fallback_sysroot_paths) {
3130+ let linker_path = path. join ( "gcc-ld" ) ;
3131+ if linker_path. exists ( ) {
3132+ linker_path_exists = true ;
3133+ cmd. arg ( {
3134+ let mut arg = OsString :: from ( "-B" ) ;
3135+ arg. push ( linker_path) ;
3136+ arg
3137+ } ) ;
3138+ }
3139+ }
3140+ if !linker_path_exists {
3141+ // As an additional sanity check, we do nothing if the sysroot doesn't contain the
3142+ // linker path at all.
3143+ return ;
31253144 }
31263145 }
31273146
You can’t perform that action at this time.
0 commit comments