about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-04-20 08:31:43 +0800
committerkennytm <kennytm@gmail.com>2017-04-25 10:31:01 +0800
commit86747a9952d9d112f64dd2671cfa8694a7822158 (patch)
tree3366356ed61807e76d94b22f5cf02c3cc1366057
parent00dff0aa59ce2d71957ca16a4444c303910686a3 (diff)
downloadrust-86747a9952d9d112f64dd2671cfa8694a7822158.tar.gz
rust-86747a9952d9d112f64dd2671cfa8694a7822158.zip
Force link with an absolute rpath when using sanitizer on macOS.
-rw-r--r--src/librustc_trans/back/link.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
index 7c0522a9c8c..e42e69d2a76 100644
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
@@ -1122,6 +1122,19 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
                               cnum: CrateNum) {
         let src = sess.cstore.used_crate_source(cnum);
         let cratepath = &src.rlib.unwrap().0;
+
+        if sess.target.target.options.is_like_osx {
+            // On Apple platforms, the sanitizer is always built as a dylib, and
+            // 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).
+            //
+            // FIXME: Remove this logic into librustc_*san once Cargo supports it
+            let rpath = cratepath.parent().unwrap();
+            let rpath = rpath.to_str().expect("non-utf8 component in path");
+            cmd.args(&["-Wl,-rpath".into(), "-Xlinker".into(), rpath.into()]);
+        }
+
         let dst = tmpdir.join(cratepath.file_name().unwrap());
         let cfg = archive_config(sess, &dst, Some(cratepath));
         let mut archive = ArchiveBuilder::new(cfg);