Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2013776
sess: remove target modifier implementation
davidtwco Jun 25, 2026
25a69ed
sess: rename some `options!` metavars
davidtwco Jun 25, 2026
40cda79
sess: option metadata
davidtwco Jun 26, 2026
e76a414
sess: re-implement target modifiers
davidtwco Jun 26, 2026
1ba2ba5
sess: mark target modifier options are unstable
davidtwco Jul 21, 2026
6117b29
sess: `-Tbranch-protection`
davidtwco Jun 29, 2026
ad05266
sess: `-Tregparm`
davidtwco Jun 29, 2026
351c329
sess: `-Tindirect-branch-cs-prefix`
davidtwco Jun 29, 2026
509401c
sess: `-Tfixed-x18`
davidtwco Jun 29, 2026
27616e3
sess: `-Tretpoline{,-external-thunk}`
davidtwco Jun 29, 2026
81120a2
sess: `-Treg-struct-return`
davidtwco Jun 29, 2026
a6b328f
sess: `-Tsanitizers{,-cfi-normalize-integers}`
davidtwco Jun 29, 2026
f025b1c
sess: `-Tpointer-authentication`
davidtwco Jul 29, 2026
a0e9235
sess: `-Ttarget-cpu`
davidtwco Jul 29, 2026
a7936d0
sess: `-Tllvm-target-feature`
davidtwco Aug 12, 2026
e445ab2
sess: add `is_target_modifier` option to setters
davidtwco Jul 24, 2026
80a639e
sess: flags are both `-T` and `-C`
davidtwco Jul 24, 2026
4600d8f
sess: reimplement `is_set` using `$key_name`
davidtwco Jul 27, 2026
fae2f75
sess: `-Tsanitizer{,-cfi-normalize-integers}` (again)
davidtwco Jul 24, 2026
7e5229b
sess: `-Tbranch-protection` (again)
davidtwco Jul 24, 2026
5c0d43a
sess: `-Tregparm` (again)
davidtwco Jul 24, 2026
24853d4
sess: `-Tindirect-branch-cs-prefix` (again)
davidtwco Jul 24, 2026
97147fc
sess: `-Tfixed-x18` (again)
davidtwco Jul 24, 2026
56abd29
sess: `-Tretpoline{,-external-thunk}` (again)
davidtwco Jul 24, 2026
472b312
sess: `-Treg-struct-return` (again)
davidtwco Jul 24, 2026
032d22a
sess: `-Ttarget-cpu` (again)
davidtwco Jul 29, 2026
7a26574
sess: `-Tpointer-authentication` (again)
davidtwco Jul 29, 2026
f5c60c8
sess: `-Tllvm-target-feature` (again)
davidtwco Aug 12, 2026
7b9bf71
sess: existing flags cannot be used with `-T`
davidtwco Aug 12, 2026
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
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> {
impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> {
fn x86_abi_opt(&self) -> X86Abi {
X86Abi {
regparm: self.tcx.sess.opts.unstable_opts.regparm,
reg_struct_return: self.tcx.sess.opts.unstable_opts.reg_struct_return,
regparm: self.tcx.sess.opts.cg.regparm,
reg_struct_return: self.tcx.sess.opts.cg.reg_struct_return,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ pub(crate) unsafe fn create_module<'ll>(
}
}

if let Some(regparm_count) = sess.opts.unstable_opts.regparm {
if let Some(regparm_count) = sess.opts.cg.regparm {
llvm::add_module_flag_u32(
llmod,
llvm::ModuleFlagMergeBehavior::Error,
Expand Down Expand Up @@ -514,7 +514,7 @@ pub(crate) unsafe fn create_module<'ll>(
);
}

if sess.opts.unstable_opts.indirect_branch_cs_prefix {
if sess.opts.cg.indirect_branch_cs_prefix {
llvm::add_module_flag_u32(
llmod,
llvm::ModuleFlagMergeBehavior::Override,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub(crate) struct MismatchedDataLayout<'a> {
}

#[derive(Diagnostic)]
#[diag("the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture")]
#[diag("the `-Tfixed-x18` flag is not supported on the `{$arch}` architecture")]
pub(crate) struct FixedX18InvalidArch<'a> {
pub arch: &'a str,
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ fn llvm_features_by_flags(sess: &Session, features: &mut Vec<String>) {
target_features::sanitizer_features_by_flags(sess, features);

// -Zfixed-x18
if sess.opts.unstable_opts.fixed_x18 {
if sess.opts.cg.fixed_x18 {
if sess.target.arch != Arch::AArch64 {
sess.dcx()
.emit_fatal(diagnostics::FixedX18InvalidArch { arch: sess.target.arch.desc() });
Expand Down Expand Up @@ -749,9 +749,9 @@ pub(crate) fn global_llvm_features(sess: &Session, for_cfg: bool) -> Vec<String>
// asm logic uses that to check which registers may be used).
llvm_features_by_flags(sess, &mut features);

// `-Zllvm-target-features`, all the way at the end to overwrite everything.
// `-Tllvm-target-features`, all the way at the end to overwrite everything.
// Should be picked up by `cfg` (e.g. if someone enables AVX this way).
for feature in sess.opts.unstable_opts.llvm_target_feature.split(',') {
for feature in sess.opts.cg.llvm_target_feature.split(',') {
if feature.is_empty() {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ pub fn codegen_crate<
&& tcx.sess.target.unsupported_cpus.contains(&target_cpu.into())
{
// The target cpu is explicitly listed as an unsupported cpu
tcx.dcx().emit_fatal(diagnostics::CpuUnsupported { target_cpu: target_cpu.clone() });
tcx.dcx().emit_fatal(diagnostics::CpuUnsupported { target_cpu: target_cpu.to_string() });
}

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ pub(crate) struct CheckInstalledVisualStudio;
pub(crate) struct InsufficientVSCodeProduct;

#[derive(Diagnostic)]
#[diag("target requires explicitly specifying a cpu with `-C target-cpu`")]
#[diag("target requires explicitly specifying a cpu with `-T target-cpu`")]
pub(crate) struct CpuRequired;

#[derive(Diagnostic)]
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,17 +489,17 @@ pub fn flag_to_backend_features<'a>(
/// Computes the backend target features to be added to account for retpoline flags.
/// Used by both LLVM and GCC since their target features are, conveniently, the same.
pub fn retpoline_features_by_flags(sess: &Session, features: &mut Vec<String>) {
// -Zretpoline without -Zretpoline-external-thunk enables
// -Tretpoline without -Tretpoline-external-thunk enables
// retpoline-indirect-branches and retpoline-indirect-calls target features
let unstable_opts = &sess.opts.unstable_opts;
if unstable_opts.retpoline && !unstable_opts.retpoline_external_thunk {
let cg = &sess.opts.cg;
if cg.retpoline && !cg.retpoline_external_thunk {
features.push("+retpoline-indirect-branches".into());
features.push("+retpoline-indirect-calls".into());
}
// -Zretpoline-external-thunk (maybe, with -Zretpoline too) enables
// -Tretpoline-external-thunk (maybe, with -Tretpoline too) enables
// retpoline-external-thunk, retpoline-indirect-branches and
// retpoline-indirect-calls target features
if unstable_opts.retpoline_external_thunk {
if cg.retpoline_external_thunk {
features.push("+retpoline-external-thunk".into());
features.push("+retpoline-indirect-branches".into());
features.push("+retpoline-indirect-calls".into());
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) {
safe_println!(
"{options}{at_path}\nAdditional help:
-C help Print codegen options
-T help Print target modifier options
-W help \
Print 'lint' options and default settings{nightly}{verbose}\n",
options = options.usage(message),
Expand Down
30 changes: 16 additions & 14 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,25 @@ fn test_codegen_options_tracking_hash() {

// Make sure that changing a [TRACKED] option changes the hash.
// tidy-alphabetical-start
tracked!(
branch_protection,
Some(BranchProtection {
bti: true,
pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B }),
gcs: true,
})
);
tracked!(code_model, Some(CodeModel::Large));
tracked!(collapse_macro_debuginfo, CollapseMacroDebuginfo::Yes);
tracked!(control_flow_guard, CFGuard::Checks);
tracked!(debug_assertions, Some(true));
tracked!(debuginfo, DebugInfo::Limited);
tracked!(dwarf_version, Some(5));
tracked!(embed_bitcode, false);
tracked!(fixed_x18, true);
tracked!(force_frame_pointers, FramePointer::Always);
tracked!(force_unwind_tables, Some(true));
tracked!(indirect_branch_cs_prefix, true);
tracked!(instrument_coverage, InstrumentCoverage::Yes);
tracked!(jump_tables, false);
tracked!(link_dead_code, Some(true));
Expand All @@ -658,8 +668,14 @@ fn test_codegen_options_tracking_hash() {
tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
tracked!(profile_use, Some(PathBuf::from("abc")));
tracked!(reg_struct_return, true);
tracked!(regparm, Some(3));
tracked!(relocation_model, Some(RelocModel::Pic));
tracked!(relro_level, Some(RelroLevel::Full));
tracked!(retpoline, true);
tracked!(retpoline_external_thunk, true);
tracked!(sanitizer, SanitizerSet::CFI);
tracked!(sanitizer_cfi_normalize_integers, Some(true));
tracked!(split_debuginfo, Some(SplitDebuginfo::Packed));
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
tracked!(target_cpu, Some(String::from("abc")));
Expand Down Expand Up @@ -790,14 +806,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(autodiff_post_passes, Some("function(mem2reg,instsimplify,simplifycfg)".to_string()));
tracked!(binary_dep_depinfo, true);
tracked!(box_noalias, false);
tracked!(
branch_protection,
Some(BranchProtection {
bti: true,
pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B }),
gcs: true,
})
);
tracked!(codegen_backend, Some("abc".to_string()));
tracked!(codegen_emit_retag, Some(CodegenRetagOptions::default()));
tracked!(
Expand All @@ -821,7 +829,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(embed_source, true);
tracked!(export_executable_symbols, true);
tracked!(fewer_names, Some(true));
tracked!(fixed_x18, true);
tracked!(flatten_format_args, false);
tracked!(fmt_debug, FmtDebug::Shallow);
tracked!(force_unstable_if_unmarked, true);
Expand All @@ -831,7 +838,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(human_readable_cgu_names, true);
tracked!(implicit_sysroot_deps, false);
tracked!(incremental_ignore_spans, true);
tracked!(indirect_branch_cs_prefix, true);
tracked!(inline_mir, Some(true));
tracked!(inline_mir_hint_threshold, Some(123));
tracked!(inline_mir_threshold, Some(123));
Expand Down Expand Up @@ -873,14 +879,10 @@ fn test_unstable_options_tracking_hash() {
tracked!(polonius, Polonius::Legacy);
tracked!(precise_enum_drop_elaboration, false);
tracked!(profiler_runtime, "abc".to_string());
tracked!(reg_struct_return, true);
tracked!(regparm, Some(3));
tracked!(relax_elf_relocations, Some(true));
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
tracked!(sanitizer, SanitizerSet::ADDRESS);
tracked!(sanitizer_cfi_canonical_jump_tables, None);
tracked!(sanitizer_cfi_generalize_pointers, Some(true));
tracked!(sanitizer_cfi_normalize_integers, Some(true));
tracked!(sanitizer_dataflow_abilist, vec![String::from("/rustc/abc")]);
tracked!(sanitizer_kcfi_arity, Some(true));
tracked!(sanitizer_memory_track_origins, 2);
Expand Down
130 changes: 11 additions & 119 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use rustc_middle::ty::data_structures::IndexSet;
use rustc_middle::ty::{TyCtxt, TyCtxtFeed};
use rustc_proc_macro::bridge::client::Client as ProcMacroClient;
use rustc_session::config::mitigation_coverage::DeniedPartialMitigationLevel;
use rustc_session::config::{
CrateType, ExtendedTargetModifierInfo, ExternLocation, Externs, OptionsTargetModifiers,
TargetModifier,
};
use rustc_session::config::{CrateType, ExternLocation, Externs};
use rustc_session::output::validate_crate_name;
use rustc_session::search_paths::PathKind;
use rustc_session::{Session, lint};
Expand All @@ -38,9 +35,7 @@ use tracing::{debug, info};

use crate::diagnostics;
use crate::locator::{CrateError, CrateLocator, CratePaths, CrateRejections};
use crate::rmeta::{
CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob, TargetModifiers,
};
use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob};

/// The backend's way to give the crate store access to the metadata in a library.
/// Note that it returns the raw metadata bytes stored in the library file, whether
Expand Down Expand Up @@ -342,111 +337,6 @@ impl CStore {
}
}

fn report_target_modifiers_extended(
tcx: TyCtxt<'_>,
mods: &TargetModifiers,
dep_mods: &TargetModifiers,
data: &CrateMetadata,
) {
let allowed_flag_mismatches = &tcx.sess.opts.cg.unsafe_allow_abi_mismatch;
let local_crate = tcx.crate_name(LOCAL_CRATE);
let tmod_extender = |tmod: &TargetModifier| (tmod.extend(), tmod.clone());
let report_diff = |prefix: &String,
opt_name: &String,
flag_local_value: Option<&String>,
flag_extern_value: Option<&String>| {
if allowed_flag_mismatches.contains(&opt_name) {
return;
}
let extern_crate = data.name();
let flag_name = opt_name.clone();
let flag_name_prefixed = format!("-{}{}", prefix, opt_name);

match (flag_local_value, flag_extern_value) {
(Some(local_value), Some(extern_value)) => {
tcx.dcx().emit_err(diagnostics::IncompatibleTargetModifiers {
extern_crate,
local_crate,
flag_name,
flag_name_prefixed,
local_value: local_value.to_string(),
extern_value: extern_value.to_string(),
})
}
(None, Some(extern_value)) => {
tcx.dcx().emit_err(diagnostics::IncompatibleTargetModifiersLMissed {
extern_crate,
local_crate,
flag_name,
flag_name_prefixed,
extern_value: extern_value.to_string(),
has_extern_value: !extern_value.is_empty(),
})
}
(Some(local_value), None) => {
tcx.dcx().emit_err(diagnostics::IncompatibleTargetModifiersRMissed {
extern_crate,
local_crate,
flag_name,
flag_name_prefixed,
local_value: local_value.to_string(),
has_local_value: !local_value.is_empty(),
})
}
(None, None) => panic!("Incorrect target modifiers report_diff(None, None)"),
};
};
let mut it1 = mods.iter().map(tmod_extender);
let mut it2 = dep_mods.iter().map(tmod_extender);
let mut left_name_val: Option<(ExtendedTargetModifierInfo, TargetModifier)> = None;
let mut right_name_val: Option<(ExtendedTargetModifierInfo, TargetModifier)> = None;
loop {
left_name_val = left_name_val.or_else(|| it1.next());
right_name_val = right_name_val.or_else(|| it2.next());
match (&left_name_val, &right_name_val) {
(Some(l), Some(r)) => match l.1.opt.cmp(&r.1.opt) {
cmp::Ordering::Equal => {
if !l.1.consistent(&tcx.sess, Some(&r.1)) {
report_diff(
&l.0.prefix,
&l.0.name,
Some(&l.1.value_name),
Some(&r.1.value_name),
);
}
left_name_val = None;
right_name_val = None;
}
cmp::Ordering::Greater => {
if !r.1.consistent(&tcx.sess, None) {
report_diff(&r.0.prefix, &r.0.name, None, Some(&r.1.value_name));
}
right_name_val = None;
}
cmp::Ordering::Less => {
if !l.1.consistent(&tcx.sess, None) {
report_diff(&l.0.prefix, &l.0.name, Some(&l.1.value_name), None);
}
left_name_val = None;
}
},
(Some(l), None) => {
if !l.1.consistent(&tcx.sess, None) {
report_diff(&l.0.prefix, &l.0.name, Some(&l.1.value_name), None);
}
left_name_val = None;
}
(None, Some(r)) => {
if !r.1.consistent(&tcx.sess, None) {
report_diff(&r.0.prefix, &r.0.name, None, Some(&r.1.value_name));
}
right_name_val = None;
}
(None, None) => break,
}
}
}

pub fn report_session_incompatibilities(&self, tcx: TyCtxt<'_>, krate: &Crate) {
self.report_incompatible_target_modifiers(tcx);
self.report_incompatible_partial_mitigations(tcx, krate);
Expand All @@ -455,21 +345,23 @@ impl CStore {

pub fn report_incompatible_target_modifiers(&self, tcx: TyCtxt<'_>) {
for flag_name in &tcx.sess.opts.cg.unsafe_allow_abi_mismatch {
if !OptionsTargetModifiers::is_target_modifier(flag_name) {
if !tcx.sess.opts.cg.is_target_modifier(flag_name) {
tcx.dcx().emit_err(diagnostics::UnknownTargetModifierUnsafeAllowed {
flag_name: flag_name.clone(),
});
}
}
let mods = tcx.sess.opts.gather_target_modifiers();
for (_cnum, data) in self.iter_crate_data() {

for (_, data) in self.iter_crate_data() {
if data.is_proc_macro_crate() {
continue;
}
let dep_mods = data.target_modifiers();
if mods != dep_mods {
Self::report_target_modifiers_extended(tcx, &mods, &dep_mods, data);
}
tcx.sess.opts.cg.report_mismatched_flags_with_dep(
tcx.sess,
tcx.crate_name(LOCAL_CRATE),
data.target_modifiers(),
data.name(),
);
}
}

Expand Down
Loading
Loading