Skip to content

Commit 27abbc2

Browse files
Rollup merge of #80933 - rcvalle:fix-sysroot-option, r=nagisa
Fix sysroot option not being honored across rustc Change link_sanitizer_runtime() to check if the sanitizer library exists in the specified/session sysroot, and if it doesn't exist, use the default sysroot. (See #79253.)
2 parents e8ef15d + 7378676 commit 27abbc2

File tree

1 file changed

+21
-7
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+21
-7
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,22 @@ fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linke
885885
}
886886

887887
fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
888-
let default_sysroot = filesearch::get_or_default_sysroot();
889-
let default_tlib =
890-
filesearch::make_target_lib_path(&default_sysroot, sess.opts.target_triple.triple());
888+
fn find_sanitizer_runtime(sess: &Session, filename: &String) -> PathBuf {
889+
let session_tlib =
890+
filesearch::make_target_lib_path(&sess.sysroot, sess.opts.target_triple.triple());
891+
let path = session_tlib.join(&filename);
892+
if path.exists() {
893+
return session_tlib;
894+
} else {
895+
let default_sysroot = filesearch::get_or_default_sysroot();
896+
let default_tlib = filesearch::make_target_lib_path(
897+
&default_sysroot,
898+
sess.opts.target_triple.triple(),
899+
);
900+
return default_tlib;
901+
}
902+
}
903+
891904
let channel = option_env!("CFG_RELEASE_CHANNEL")
892905
.map(|channel| format!("-{}", channel))
893906
.unwrap_or_default();
@@ -898,18 +911,19 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
898911
// LLVM will link to `@rpath/*.dylib`, so we need to specify an
899912
// rpath to the library as well (the rpath should be absolute, see
900913
// PR #41352 for details).
901-
let libname = format!("rustc{}_rt.{}", channel, name);
902-
let rpath = default_tlib.to_str().expect("non-utf8 component in path");
914+
let filename = format!("rustc{}_rt.{}", channel, name);
915+
let path = find_sanitizer_runtime(&sess, &filename);
916+
let rpath = path.to_str().expect("non-utf8 component in path");
903917
linker.args(&["-Wl,-rpath", "-Xlinker", rpath]);
904-
linker.link_dylib(Symbol::intern(&libname));
918+
linker.link_dylib(Symbol::intern(&filename));
905919
}
906920
"aarch64-fuchsia"
907921
| "aarch64-unknown-linux-gnu"
908922
| "x86_64-fuchsia"
909923
| "x86_64-unknown-freebsd"
910924
| "x86_64-unknown-linux-gnu" => {
911925
let filename = format!("librustc{}_rt.{}.a", channel, name);
912-
let path = default_tlib.join(&filename);
926+
let path = find_sanitizer_runtime(&sess, &filename).join(&filename);
913927
linker.link_whole_rlib(&path);
914928
}
915929
_ => {}

0 commit comments

Comments
 (0)