Skip to content

Link sanitizers when creating dynamic libraries on macOS #74793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,22 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
}

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;
}

let sanitizer = sess.opts.debugging_opts.sanitizer;
if sanitizer.contains(SanitizerSet::ADDRESS) {
link_sanitizer_runtime(sess, linker, "asan");
Expand Down
1 change: 0 additions & 1 deletion src/test/run-make-fulldeps/sanitizer-cdylib-link/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# needs-sanitizer-support
# needs-sanitizer-address
# only-linux

-include ../tools.mk

Expand Down
1 change: 0 additions & 1 deletion src/test/run-make-fulldeps/sanitizer-dylib-link/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# needs-sanitizer-support
# needs-sanitizer-address
# only-linux

-include ../tools.mk

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# needs-sanitizer-support
# needs-sanitizer-address
# only-linux

-include ../tools.mk

Expand Down