Skip to content

Commit b6396b7

Browse files
committed
Auto merge of rust-lang#74793 - tmiasko:san-macos, r=Mark-Simulacrum
Link sanitizers when creating dynamic libraries on macOS Link sanitizer runtime when creating dynamic libraries on macOS to resolve sanitizer runtime symbols and avoid failure at link time. Closes rust-lang#74571.
2 parents 0a49057 + 4fbbc81 commit b6396b7

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/librustc_codegen_ssa/back/link.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,22 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
769769
}
770770

771771
fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) {
772-
if crate_type != CrateType::Executable {
772+
// On macOS the runtimes are distributed as dylibs which should be linked to
773+
// both executables and dynamic shared objects. Everywhere else the runtimes
774+
// are currently distributed as static liraries which should be linked to
775+
// executables only.
776+
let needs_runtime = match crate_type {
777+
CrateType::Executable => true,
778+
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
779+
sess.target.target.options.is_like_osx
780+
}
781+
CrateType::Rlib | CrateType::Staticlib => false,
782+
};
783+
784+
if !needs_runtime {
773785
return;
774786
}
787+
775788
let sanitizer = sess.opts.debugging_opts.sanitizer;
776789
if sanitizer.contains(SanitizerSet::ADDRESS) {
777790
link_sanitizer_runtime(sess, linker, "asan");

src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# needs-sanitizer-support
22
# needs-sanitizer-address
3-
# only-linux
43

54
-include ../tools.mk
65

src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# needs-sanitizer-support
22
# needs-sanitizer-address
3-
# only-linux
43

54
-include ../tools.mk
65

src/test/run-make-fulldeps/sanitizer-staticlib-link/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# needs-sanitizer-support
22
# needs-sanitizer-address
3-
# only-linux
43

54
-include ../tools.mk
65

0 commit comments

Comments
 (0)