Skip to content

Commit 7378676

Browse files
committed
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.
1 parent fe531d5 commit 7378676

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
@@ -887,9 +887,22 @@ fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linke
887887
}
888888

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

0 commit comments

Comments
 (0)