Skip to content

Commit cdb1e11

Browse files
committed
sanitizers: Fix tests/ui/sanitize/leak.rs fails on
Fix rust-lang#111073 by checking if `-Zexport-executable-symbols` is passed when LeakSanitizer is enabled.
1 parent 22572d0 commit cdb1e11

File tree

7 files changed

+29
-2
lines changed

7 files changed

+29
-2
lines changed

compiler/rustc_session/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ session_sanitizer_cfi_requires_single_codegen_unit = `-Zsanitizer=cfi` with `-Cl
9898
9999
session_sanitizer_kcfi_requires_panic_abort = `-Z sanitizer=kcfi` requires `-C panic=abort`
100100
101+
session_sanitizer_leak_requires_export_executable_symbols = `-Zsanitizer=leak` requires `-Zexport-executable-symbols`
102+
101103
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
102104
103105
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target

compiler/rustc_session/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ pub(crate) struct CannotMixAndMatchSanitizers {
127127
#[diag(session_cannot_enable_crt_static_linux)]
128128
pub(crate) struct CannotEnableCrtStaticLinux;
129129

130+
#[derive(Diagnostic)]
131+
#[diag(session_sanitizer_leak_requires_export_executable_symbols)]
132+
pub(crate) struct SanitizerLeakRequiresExportExecutableSymbols;
133+
130134
#[derive(Diagnostic)]
131135
#[diag(session_sanitizer_cfi_requires_lto)]
132136
pub(crate) struct SanitizerCfiRequiresLto;

compiler/rustc_session/src/session.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ impl Session {
390390
self.opts.unstable_opts.sanitizer.contains(SanitizerSet::KCFI)
391391
}
392392

393+
pub fn is_sanitizer_leak_enabled(&self) -> bool {
394+
self.opts.unstable_opts.sanitizer.contains(SanitizerSet::LEAK)
395+
}
396+
393397
pub fn is_split_lto_unit_enabled(&self) -> bool {
394398
self.opts.unstable_opts.split_lto_unit == Some(true)
395399
}
@@ -1223,6 +1227,11 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12231227
sess.dcx().emit_err(errors::CannotEnableCrtStaticLinux);
12241228
}
12251229

1230+
// LeakSanitizer requires export_executable_symbols.
1231+
if sess.is_sanitizer_leak_enabled() && !sess.opts.unstable_opts.export_executable_symbols {
1232+
sess.dcx().emit_err(errors::SanitizerLeakRequiresExportExecutableSymbols);
1233+
}
1234+
12261235
// LLVM CFI requires LTO.
12271236
if sess.is_sanitizer_cfi_enabled()
12281237
&& !(sess.lto() == config::Lto::Fat || sess.opts.cg.linker_plugin_lto.enabled())

tests/ui/sanitizer/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//@[kcfi]compile-flags: -Zsanitizer=kcfi --cfg kcfi --target x86_64-unknown-none
1414
//@[kcfi]compile-flags: -C panic=abort
1515
//@[leak]needs-sanitizer-leak
16-
//@[leak]compile-flags: -Zsanitizer=leak --cfg leak
16+
//@[leak]compile-flags: -Zsanitizer=leak --cfg leak -Zexport-executable-symbols
1717
//@[memory]needs-sanitizer-memory
1818
//@[memory]compile-flags: -Zsanitizer=memory --cfg memory
1919
//@[thread]needs-sanitizer-thread
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Verifies that `-Zsanitizer=leak` requires `-Zexport-executable-symbols`.
2+
//
3+
//@ needs-sanitizer-leak
4+
//@ compile-flags: -Zsanitizer=leak
5+
6+
#![feature(no_core)]
7+
#![no_core]
8+
#![no_main]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: `-Zsanitizer=leak` requires `-Zexport-executable-symbols`
2+
3+
error: aborting due to 1 previous error
4+

tests/ui/sanitizer/unsupported-target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Z sanitizer=leak --target i686-unknown-linux-gnu
1+
//@ compile-flags: -Z sanitizer=leak -Zexport-executable-symbols --target i686-unknown-linux-gnu
22
//@ needs-llvm-components: x86
33
//@ error-pattern: error: leak sanitizer is not supported for this target
44
#![feature(no_core)]

0 commit comments

Comments
 (0)