Skip to content

Commit 0e9c3e5

Browse files
committed
Auto merge of #139401 - matthiaskrgr:rollup-uqdfj6u, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #138368 (KCFI: Add KCFI arity indicator support) - #138381 (Implement `SliceIndex` for `ByteStr`) - #139092 (Move `fd` into `std::sys`) - #139398 (Change notifications for Exploit Mitigations PG) r? `@ghost` `@rustbot` modify labels: rollup
2 parents da83217 + 0823b34 commit 0e9c3e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+558
-351
lines changed

compiler/rustc_codegen_llvm/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ codegen_llvm_prepare_thin_lto_module_with_llvm_err = failed to prepare thin LTO
5656
codegen_llvm_run_passes = failed to run LLVM passes
5757
codegen_llvm_run_passes_with_llvm_err = failed to run LLVM passes: {$llvm_err}
5858
59+
codegen_llvm_sanitizer_kcfi_arity_requires_llvm_21_0_0 = `-Zsanitizer-kcfi-arity` requires LLVM 21.0.0 or later.
60+
5961
codegen_llvm_sanitizer_memtag_requires_mte =
6062
`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`
6163

compiler/rustc_codegen_llvm/src/context.rs

+16
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ pub(crate) unsafe fn create_module<'ll>(
328328
pfe.prefix().into(),
329329
);
330330
}
331+
332+
// Add "kcfi-arity" module flag if KCFI arity indicator is enabled. (See
333+
// https://github.com/llvm/llvm-project/pull/117121.)
334+
if sess.is_sanitizer_kcfi_arity_enabled() {
335+
// KCFI arity indicator requires LLVM 21.0.0 or later.
336+
if llvm_version < (21, 0, 0) {
337+
tcx.dcx().emit_err(crate::errors::SanitizerKcfiArityRequiresLLVM2100);
338+
}
339+
340+
llvm::add_module_flag_u32(
341+
llmod,
342+
llvm::ModuleFlagMergeBehavior::Override,
343+
"kcfi-arity",
344+
1,
345+
);
346+
}
331347
}
332348

333349
// Control Flow Guard is currently only supported by MSVC and LLVM on Windows.

compiler/rustc_codegen_llvm/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,7 @@ pub(crate) struct MismatchedDataLayout<'a> {
217217
pub(crate) struct FixedX18InvalidArch<'a> {
218218
pub arch: &'a str,
219219
}
220+
221+
#[derive(Diagnostic)]
222+
#[diag(codegen_llvm_sanitizer_kcfi_arity_requires_llvm_21_0_0)]
223+
pub(crate) struct SanitizerKcfiArityRequiresLLVM2100;

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ fn test_unstable_options_tracking_hash() {
853853
tracked!(sanitizer_cfi_generalize_pointers, Some(true));
854854
tracked!(sanitizer_cfi_normalize_integers, Some(true));
855855
tracked!(sanitizer_dataflow_abilist, vec![String::from("/rustc/abc")]);
856+
tracked!(sanitizer_kcfi_arity, Some(true));
856857
tracked!(sanitizer_memory_track_origins, 2);
857858
tracked!(sanitizer_recover, SanitizerSet::ADDRESS);
858859
tracked!(saturating_float_casts, Some(true));

compiler/rustc_session/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ session_sanitizer_cfi_requires_lto = `-Zsanitizer=cfi` requires `-Clto` or `-Cli
9494
9595
session_sanitizer_cfi_requires_single_codegen_unit = `-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1`
9696
97+
session_sanitizer_kcfi_arity_requires_kcfi = `-Zsanitizer-kcfi-arity` requires `-Zsanitizer=kcfi`
98+
9799
session_sanitizer_kcfi_requires_panic_abort = `-Z sanitizer=kcfi` requires `-C panic=abort`
98100
99101
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target

compiler/rustc_session/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ pub(crate) struct SanitizerCfiGeneralizePointersRequiresCfi;
147147
#[diag(session_sanitizer_cfi_normalize_integers_requires_cfi)]
148148
pub(crate) struct SanitizerCfiNormalizeIntegersRequiresCfi;
149149

150+
#[derive(Diagnostic)]
151+
#[diag(session_sanitizer_kcfi_arity_requires_kcfi)]
152+
pub(crate) struct SanitizerKcfiArityRequiresKcfi;
153+
150154
#[derive(Diagnostic)]
151155
#[diag(session_sanitizer_kcfi_requires_panic_abort)]
152156
pub(crate) struct SanitizerKcfiRequiresPanicAbort;

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,8 @@ written to standard error output)"),
24452445
"enable normalizing integer types (default: no)"),
24462446
sanitizer_dataflow_abilist: Vec<String> = (Vec::new(), parse_comma_list, [TRACKED],
24472447
"additional ABI list files that control how shadow parameters are passed (comma separated)"),
2448+
sanitizer_kcfi_arity: Option<bool> = (None, parse_opt_bool, [TRACKED],
2449+
"enable KCFI arity indicator (default: no)"),
24482450
sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED],
24492451
"enable origins tracking in MemorySanitizer"),
24502452
sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],

compiler/rustc_session/src/session.rs

+9
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ impl Session {
381381
self.opts.unstable_opts.sanitizer_cfi_normalize_integers == Some(true)
382382
}
383383

384+
pub fn is_sanitizer_kcfi_arity_enabled(&self) -> bool {
385+
self.opts.unstable_opts.sanitizer_kcfi_arity == Some(true)
386+
}
387+
384388
pub fn is_sanitizer_kcfi_enabled(&self) -> bool {
385389
self.opts.unstable_opts.sanitizer.contains(SanitizerSet::KCFI)
386390
}
@@ -1211,6 +1215,11 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12111215
}
12121216
}
12131217

1218+
// KCFI arity indicator requires KCFI.
1219+
if sess.is_sanitizer_kcfi_arity_enabled() && !sess.is_sanitizer_kcfi_enabled() {
1220+
sess.dcx().emit_err(errors::SanitizerKcfiArityRequiresKcfi);
1221+
}
1222+
12141223
// LLVM CFI pointer generalization requires CFI or KCFI.
12151224
if sess.is_sanitizer_cfi_generalize_pointers_enabled() {
12161225
if !(sess.is_sanitizer_cfi_enabled() || sess.is_sanitizer_kcfi_enabled()) {

0 commit comments

Comments
 (0)