Skip to content

Commit

Permalink
Rollup merge of #80933 - rcvalle:fix-sysroot-option, r=nagisa
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
jonas-schievink authored Jan 24, 2021
2 parents e8ef15d + 7378676 commit 27abbc2
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,9 +885,22 @@ fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linke
}

fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
let default_sysroot = filesearch::get_or_default_sysroot();
let default_tlib =
filesearch::make_target_lib_path(&default_sysroot, sess.opts.target_triple.triple());
fn find_sanitizer_runtime(sess: &Session, filename: &String) -> PathBuf {
let session_tlib =
filesearch::make_target_lib_path(&sess.sysroot, sess.opts.target_triple.triple());
let path = session_tlib.join(&filename);
if path.exists() {
return session_tlib;
} else {
let default_sysroot = filesearch::get_or_default_sysroot();
let default_tlib = filesearch::make_target_lib_path(
&default_sysroot,
sess.opts.target_triple.triple(),
);
return default_tlib;
}
}

let channel = option_env!("CFG_RELEASE_CHANNEL")
.map(|channel| format!("-{}", channel))
.unwrap_or_default();
Expand All @@ -898,18 +911,19 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
// LLVM will link to `@rpath/*.dylib`, so we need to specify an
// rpath to the library as well (the rpath should be absolute, see
// PR #41352 for details).
let libname = format!("rustc{}_rt.{}", channel, name);
let rpath = default_tlib.to_str().expect("non-utf8 component in path");
let filename = format!("rustc{}_rt.{}", channel, name);
let path = find_sanitizer_runtime(&sess, &filename);
let rpath = path.to_str().expect("non-utf8 component in path");
linker.args(&["-Wl,-rpath", "-Xlinker", rpath]);
linker.link_dylib(Symbol::intern(&libname));
linker.link_dylib(Symbol::intern(&filename));
}
"aarch64-fuchsia"
| "aarch64-unknown-linux-gnu"
| "x86_64-fuchsia"
| "x86_64-unknown-freebsd"
| "x86_64-unknown-linux-gnu" => {
let filename = format!("librustc{}_rt.{}.a", channel, name);
let path = default_tlib.join(&filename);
let path = find_sanitizer_runtime(&sess, &filename).join(&filename);
linker.link_whole_rlib(&path);
}
_ => {}
Expand Down

0 comments on commit 27abbc2

Please sign in to comment.