Skip to content

Commit aab93ca

Browse files
committed
Auto merge of #85559 - 12101111:sanitizer-crt-static, r=nagisa
Diagnose use sanitizers with crt-static Fix: #85459
2 parents c1e8f3a + 4376484 commit aab93ca

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

compiler/rustc_session/src/session.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,14 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
15121512
if let (Some(first), Some(second)) = (sanitizer_iter.next(), sanitizer_iter.next()) {
15131513
sess.err(&format!("`-Zsanitizer={}` is incompatible with `-Zsanitizer={}`", first, second));
15141514
}
1515+
1516+
// Cannot enable crt-static with sanitizers on Linux
1517+
if sess.crt_static(None) && !sess.opts.debugging_opts.sanitizer.is_empty() {
1518+
sess.err(
1519+
"Sanitizer is incompatible with statically linked libc, \
1520+
disable it using `-C target-feature=-crt-static`",
1521+
);
1522+
}
15151523
}
15161524

15171525
/// Holds data on the current incremental compilation session, if there is one.

src/test/ui/sanitize/crt-static.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-flags: -Z sanitizer=address -C target-feature=+crt-static --target x86_64-unknown-linux-gnu
2+
3+
#![feature(no_core)]
4+
#![no_core]
5+
#![no_main]
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: Sanitizer is incompatible with statically linked libc, disable it using `-C target-feature=-crt-static`
2+
3+
error: aborting due to previous error
4+

0 commit comments

Comments
 (0)