@@ -2816,6 +2816,15 @@ fn rehome_sysroot_lib_dir(sess: &Session, lib_dir: &Path) -> PathBuf {
28162816 }
28172817}
28182818
2819+ fn rehome_lib_path ( sess : & Session , path : & Path ) -> PathBuf {
2820+ if let Some ( dir) = path. parent ( ) {
2821+ let file_name = path. file_name ( ) . expect ( "library path has no file name component" ) ;
2822+ rehome_sysroot_lib_dir ( sess, dir) . join ( file_name)
2823+ } else {
2824+ fix_windows_verbatim_for_gcc ( path)
2825+ }
2826+ }
2827+
28192828// Adds the static "rlib" versions of all crates to the command line.
28202829// There's a bit of magic which happens here specifically related to LTO,
28212830// namely that we remove upstream object files.
@@ -2847,12 +2856,7 @@ fn add_static_crate(
28472856 let cratepath = & src. rlib . as_ref ( ) . unwrap ( ) . 0 ;
28482857
28492858 let mut link_upstream = |path : & Path | {
2850- let rlib_path = if let Some ( dir) = path. parent ( ) {
2851- let file_name = path. file_name ( ) . expect ( "rlib path has no file name path component" ) ;
2852- rehome_sysroot_lib_dir ( sess, dir) . join ( file_name)
2853- } else {
2854- fix_windows_verbatim_for_gcc ( path)
2855- } ;
2859+ let rlib_path = rehome_lib_path ( sess, path) ;
28562860 cmd. link_staticlib_by_path ( & rlib_path, false ) ;
28572861 } ;
28582862
@@ -2918,27 +2922,16 @@ fn add_static_crate(
29182922
29192923// Same thing as above, but for dynamic crates instead of static crates.
29202924fn add_dynamic_crate ( cmd : & mut dyn Linker , sess : & Session , cratepath : & Path ) {
2921- // Just need to tell the linker about where the library lives and
2922- // what its name is
2923- let parent = cratepath. parent ( ) ;
29242925 // When producing a dll, the MSVC linker may not actually emit a
29252926 // `foo.lib` file if the dll doesn't actually export any symbols, so we
29262927 // check to see if the file is there and just omit linking to it if it's
29272928 // not present.
29282929 if sess. target . is_like_msvc && !cratepath. with_extension ( "dll.lib" ) . exists ( ) {
29292930 return ;
29302931 }
2931- if let Some ( dir) = parent {
2932- cmd. include_path ( & rehome_sysroot_lib_dir ( sess, dir) ) ;
2933- }
2934- // "<dir>/name.dll -> name.dll" on windows-msvc
2935- // "<dir>/name.dll -> name" on windows-gnu
2936- // "<dir>/libname.<ext> -> name" elsewhere
2937- let stem = if sess. target . is_like_msvc { cratepath. file_name ( ) } else { cratepath. file_stem ( ) } ;
2938- let stem = stem. unwrap ( ) . to_str ( ) . unwrap ( ) ;
2939- // Convert library file-stem into a cc -l argument.
2940- let prefix = if stem. starts_with ( "lib" ) && !sess. target . is_like_windows { 3 } else { 0 } ;
2941- cmd. link_dylib_by_name ( & stem[ prefix..] , false , true ) ;
2932+
2933+ let dylib_path = rehome_lib_path ( sess, cratepath) ;
2934+ cmd. link_dylib_by_path ( & dylib_path, true ) ;
29422935}
29432936
29442937fn relevant_lib ( sess : & Session , lib : & NativeLib ) -> bool {
0 commit comments