Skip to content

Commit b44ca11

Browse files
committed
Auto merge of #128370 - petrochenkov:libsearch, r=<try>
linker: Pass fewer search directories to the linker Work in progress. try-job: dist-x86_64-musl try-job: dist-x86_64-mingw try-job: dist-x86_64-msvc try-job: dist-x86_64-apple try-job: dist-various-1 try-job: dist-various-2
2 parents 1ddedba + 66a962e commit b44ca11

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -2066,16 +2066,20 @@ fn add_local_crate_metadata_objects(
20662066

20672067
/// Add sysroot and other globally set directories to the directory search list.
20682068
fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: bool) {
2069-
// The default library location, we need this to find the runtime.
2070-
// The location of crates will be determined as needed.
2071-
let lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
2072-
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
2073-
20742069
// Special directory with libraries used only in self-contained linkage mode
20752070
if self_contained {
20762071
let lib_path = sess.target_filesearch(PathKind::All).get_self_contained_lib_path();
20772072
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
20782073
}
2074+
2075+
// The default library location, we need this to find the runtime.
2076+
// The location of crates will be determined as needed.
2077+
// `copy_third_party_objects`
2078+
if sess.target.vendor == "fortanix" || sess.target.os == "linux" || sess.target.os == "fuchsia"
2079+
{
2080+
let lib_path = sess.target_filesearch(PathKind::Native).get_lib_path();
2081+
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
2082+
}
20792083
}
20802084

20812085
/// Add options making relocation sections in the produced ELF files read-only
@@ -2638,14 +2642,13 @@ fn add_local_native_libraries(
26382642
link_output_kind: LinkOutputKind,
26392643
) {
26402644
if sess.opts.unstable_opts.link_native_libraries {
2641-
// User-supplied library search paths (-L on the command line). These are the same paths
2642-
// used to find Rust crates, so some of them may have been added already by the previous
2643-
// crate linking code. This only allows them to be found at compile time so it is still
2644-
// entirely up to outside forces to make sure that library can be found at runtime.
2645-
for search_path in sess.target_filesearch(PathKind::All).search_paths() {
2646-
match search_path.kind {
2647-
PathKind::Framework => cmd.framework_path(&search_path.dir),
2648-
_ => cmd.include_path(&fix_windows_verbatim_for_gcc(&search_path.dir)),
2645+
for search_path in sess.target_filesearch(PathKind::Native).cli_search_paths() {
2646+
cmd.include_path(&fix_windows_verbatim_for_gcc(&search_path.dir));
2647+
}
2648+
for search_path in sess.target_filesearch(PathKind::Framework).cli_search_paths() {
2649+
// Contrary to the `-L` docs only framework-specific paths are considered here.
2650+
if search_path.kind != PathKind::All {
2651+
cmd.framework_path(&search_path.dir);
26492652
}
26502653
}
26512654
}
@@ -3012,9 +3015,9 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
30123015
// search path.
30133016

30143017
// The flags are called `-L` and `-F` both in Clang, ld64 and ldd.
3015-
let sdk_root = Path::new(&sdk_root);
3016-
cmd.include_path(&sdk_root.join("System/iOSSupport/usr/lib"));
3017-
cmd.framework_path(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"));
3018+
// let sdk_root = Path::new(&sdk_root);
3019+
// cmd.include_path(&sdk_root.join("System/iOSSupport/usr/lib"));
3020+
// cmd.framework_path(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"));
30183021
}
30193022
}
30203023

compiler/rustc_session/src/filesearch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ pub struct FileSearch<'a> {
1919
}
2020

2121
impl<'a> FileSearch<'a> {
22+
pub fn cli_search_paths(&self) -> impl Iterator<Item = &'a SearchPath> {
23+
let kind = self.kind;
24+
self.cli_search_paths.iter().filter(move |sp| sp.kind.matches(kind))
25+
}
26+
2227
pub fn search_paths(&self) -> impl Iterator<Item = &'a SearchPath> {
2328
let kind = self.kind;
2429
self.cli_search_paths

0 commit comments

Comments
 (0)