Skip to content
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

Diagnose use sanitizers with crt-static #85559

Merged
merged 1 commit into from
May 31, 2021
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
8 changes: 8 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,14 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
if let (Some(first), Some(second)) = (sanitizer_iter.next(), sanitizer_iter.next()) {
sess.err(&format!("`-Zsanitizer={}` is incompatible with `-Zsanitizer={}`", first, second));
}

// Cannot enable crt-static with sanitizers on Linux
if sess.crt_static(None) && !sess.opts.debugging_opts.sanitizer.is_empty() {
sess.err(
"Sanitizer is incompatible with statically linked libc, \
disable it using `-C target-feature=-crt-static`",
);
}
}

/// Holds data on the current incremental compilation session, if there is one.
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/sanitize/crt-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// compile-flags: -Z sanitizer=address -C target-feature=+crt-static --target x86_64-unknown-linux-gnu

#![feature(no_core)]
#![no_core]
#![no_main]
4 changes: 4 additions & 0 deletions src/test/ui/sanitize/crt-static.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: Sanitizer is incompatible with statically linked libc, disable it using `-C target-feature=-crt-static`

error: aborting due to previous error