Skip to content

Commit 86747a9

Browse files
committed
Force link with an absolute rpath when using sanitizer on macOS.
1 parent 00dff0a commit 86747a9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/librustc_trans/back/link.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,19 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
11221122
cnum: CrateNum) {
11231123
let src = sess.cstore.used_crate_source(cnum);
11241124
let cratepath = &src.rlib.unwrap().0;
1125+
1126+
if sess.target.target.options.is_like_osx {
1127+
// On Apple platforms, the sanitizer is always built as a dylib, and
1128+
// LLVM will link to `@rpath/*.dylib`, so we need to specify an
1129+
// rpath to the library as well (the rpath should be absolute, see
1130+
// PR #41352 for details).
1131+
//
1132+
// FIXME: Remove this logic into librustc_*san once Cargo supports it
1133+
let rpath = cratepath.parent().unwrap();
1134+
let rpath = rpath.to_str().expect("non-utf8 component in path");
1135+
cmd.args(&["-Wl,-rpath".into(), "-Xlinker".into(), rpath.into()]);
1136+
}
1137+
11251138
let dst = tmpdir.join(cratepath.file_name().unwrap());
11261139
let cfg = archive_config(sess, &dst, Some(cratepath));
11271140
let mut archive = ArchiveBuilder::new(cfg);

0 commit comments

Comments
 (0)