diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b458f325b737..24aa6fc4c5f8 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1280,8 +1280,9 @@ fn link_sanitizer_runtime( let filename = format!("rustc{channel}_rt.{name}"); let path = find_sanitizer_runtime(sess, &filename); let rpath = path.to_str().expect("non-utf8 component in path"); + let search_paths = SearchPaths::default(); linker.args(&["-Wl,-rpath", "-Xlinker", rpath]); - linker.link_dylib_by_name(&filename, false, true); + linker.link_dylib_by_name(&filename, false, &search_paths, true); } else if sess.target.is_like_msvc && flavor == LinkerFlavor::Msvc(Lld::No) && name == "asan" { // MSVC provides the `/INFERASANLIBS` argument to automatically find the // compatible ASAN library. @@ -2568,7 +2569,7 @@ fn add_native_libs_from_crate( } NativeLibKind::Dylib { as_needed } => { if link_dynamic { - cmd.link_dylib_by_name(name, verbatim, as_needed.unwrap_or(true)) + cmd.link_dylib_by_name(name, verbatim, search_paths, as_needed.unwrap_or(true)) } } NativeLibKind::Unspecified => { @@ -2580,7 +2581,7 @@ fn add_native_libs_from_crate( } } else { if link_dynamic { - cmd.link_dylib_by_name(name, verbatim, true); + cmd.link_dylib_by_name(name, verbatim, search_paths, true); } } } @@ -2912,7 +2913,8 @@ fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) { let stem = stem.unwrap().to_str().unwrap(); // Convert library file-stem into a cc -l argument. let prefix = if stem.starts_with("lib") && !sess.target.is_like_windows { 3 } else { 0 }; - cmd.link_dylib_by_name(&stem[prefix..], false, true); + let search_paths = SearchPaths::default(); + cmd.link_dylib_by_name(&stem[prefix..], false, &search_paths, true); } fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool { diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index ad973a5cb787..174acb7fb277 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -167,7 +167,13 @@ pub fn get_linker<'a>( pub trait Linker { fn cmd(&mut self) -> &mut Command; fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path); - fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, as_needed: bool); + fn link_dylib_by_name( + &mut self, + name: &str, + verbatim: bool, + search_paths: &SearchPaths, + as_needed: bool, + ); fn link_framework_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) { bug!("framework linked with unsupported linker") } @@ -432,7 +438,13 @@ impl<'a> Linker for GccLinker<'a> { } } - fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, as_needed: bool) { + fn link_dylib_by_name( + &mut self, + name: &str, + verbatim: bool, + _search_paths: &SearchPaths, + as_needed: bool, + ) { if self.sess.target.os == "illumos" && name == "c" { // libc will be added via late_link_args on illumos so that it will // appear last in the library search order. @@ -807,7 +819,7 @@ impl<'a> Linker for MsvcLinker<'a> { } } - fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _search_paths: &SearchPaths, _as_needed: bool) { self.cmd.arg(format!("{}{}", name, if verbatim { "" } else { ".lib" })); } @@ -1051,7 +1063,13 @@ impl<'a> Linker for EmLinker<'a> { fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {} - fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name( + &mut self, + name: &str, + _verbatim: bool, + _search_paths: &SearchPaths, + _as_needed: bool, + ) { // Emscripten always links statically self.cmd.arg("-l").arg(name); } @@ -1225,7 +1243,13 @@ impl<'a> Linker for WasmLd<'a> { } } - fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name( + &mut self, + name: &str, + _verbatim: bool, + _search_paths: &SearchPaths, + _as_needed: bool, + ) { self.cmd.arg("-l").arg(name); } @@ -1372,7 +1396,13 @@ impl<'a> Linker for L4Bender<'a> { fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {} - fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name( + &mut self, + _name: &str, + _verbatim: bool, + _search_paths: &SearchPaths, + _as_needed: bool, + ) { bug!("dylibs are not supported on L4Re"); } @@ -1549,7 +1579,13 @@ impl<'a> Linker for AixLinker<'a> { } } - fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name( + &mut self, + name: &str, + _verbatim: bool, + _search_paths: &SearchPaths, + _as_needed: bool, + ) { self.hint_dynamic(); self.cmd.arg(format!("-l{name}")); } @@ -1755,7 +1791,13 @@ impl<'a> Linker for PtxLinker<'a> { fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {} - fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name( + &mut self, + _name: &str, + _verbatim: bool, + _search_paths: &SearchPaths, + _as_needed: bool, + ) { panic!("external dylibs not supported") } @@ -1837,7 +1879,13 @@ impl<'a> Linker for LlbcLinker<'a> { fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {} - fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name( + &mut self, + _name: &str, + _verbatim: bool, + _search_paths: &SearchPaths, + _as_needed: bool, + ) { panic!("external dylibs not supported") } @@ -1928,7 +1976,13 @@ impl<'a> Linker for BpfLinker<'a> { fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {} - fn link_dylib_by_name(&mut self, _name: &str, _verbatim: bool, _as_needed: bool) { + fn link_dylib_by_name( + &mut self, + _name: &str, + _verbatim: bool, + _search_paths: &SearchPaths, + _as_needed: bool, + ) { panic!("external dylibs not supported") }