Skip to content

Commit

Permalink
Diagnose use sanitizers with crt-static
Browse files Browse the repository at this point in the history
  • Loading branch information
12101111 committed May 28, 2021
1 parent fc81ad2 commit 4376484
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit 4376484

Please sign in to comment.