1
Fork 0

Link sanitizers when creating dynamic libraries on macOS

This commit is contained in:
Tomasz Miąsko 2020-07-25 00:00:00 +00:00
parent 814bc4fe93
commit 4fbbc81e5f
4 changed files with 14 additions and 4 deletions

View file

@ -769,9 +769,22 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
} }
fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) { fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) {
if crate_type != CrateType::Executable { // On macOS the runtimes are distributed as dylibs which should be linked to
// both executables and dynamic shared objects. Everywhere else the runtimes
// are currently distributed as static liraries which should be linked to
// executables only.
let needs_runtime = match crate_type {
CrateType::Executable => true,
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
sess.target.target.options.is_like_osx
}
CrateType::Rlib | CrateType::Staticlib => false,
};
if !needs_runtime {
return; return;
} }
let sanitizer = sess.opts.debugging_opts.sanitizer; let sanitizer = sess.opts.debugging_opts.sanitizer;
if sanitizer.contains(SanitizerSet::ADDRESS) { if sanitizer.contains(SanitizerSet::ADDRESS) {
link_sanitizer_runtime(sess, linker, "asan"); link_sanitizer_runtime(sess, linker, "asan");

View file

@ -1,6 +1,5 @@
# needs-sanitizer-support # needs-sanitizer-support
# needs-sanitizer-address # needs-sanitizer-address
# only-linux
-include ../tools.mk -include ../tools.mk

View file

@ -1,6 +1,5 @@
# needs-sanitizer-support # needs-sanitizer-support
# needs-sanitizer-address # needs-sanitizer-address
# only-linux
-include ../tools.mk -include ../tools.mk

View file

@ -1,6 +1,5 @@
# needs-sanitizer-support # needs-sanitizer-support
# needs-sanitizer-address # needs-sanitizer-address
# only-linux
-include ../tools.mk -include ../tools.mk