Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f283869
sess: remove target modifier implementation
davidtwco Jun 25, 2026
1f5aba5
sess: rename some `options!` metavars
davidtwco Jun 25, 2026
3b95e08
sess: option metadata
davidtwco Jun 26, 2026
c53919a
sess: re-implement target modifiers
davidtwco Jun 26, 2026
7c46814
sess: mark target modifier options are unstable
davidtwco Jul 21, 2026
b65a139
sess: control printing of target modifier values
davidtwco Jun 29, 2026
1f6b531
sess: `-Tbranch-protection`
davidtwco Jun 29, 2026
bf4ec20
sess: `-Tregparm`
davidtwco Jun 29, 2026
13be04d
sess: `-Tindirect-branch-cs-prefix`
davidtwco Jun 29, 2026
abf6ad7
sess: `-Tfixed-x18`
davidtwco Jun 29, 2026
baf6549
sess: `-Tretpoline{,-external-thunk}`
davidtwco Jun 29, 2026
460ea33
sess: `-Treg-struct-return`
davidtwco Jun 29, 2026
9bdebc5
sess: `-Tsanitizers{,-cfi-normalize-integers}`
davidtwco Jun 29, 2026
94b008f
sess: `-Tpointer-authentication`
davidtwco Jul 29, 2026
208adfc
sess: `-Ttarget-cpu`
davidtwco Jul 29, 2026
090db9c
sess: add `is_target_modifier` option to setters
davidtwco Jul 24, 2026
a7e7845
sess: flags are both `-T` and `-C`
davidtwco Jul 24, 2026
5eeba99
sess: reimplement `is_set` using `$key_name`
davidtwco Jul 27, 2026
cd76711
sess: `-Tsanitizer{,-cfi-normalize-integers}` (again)
davidtwco Jul 24, 2026
d2fd6c8
sess: `-Tbranch-protection` (again)
davidtwco Jul 24, 2026
dfef486
sess: `-Tregparm` (again)
davidtwco Jul 24, 2026
c2926a2
sess: `-Tindirect-branch-cs-prefix` (again)
davidtwco Jul 24, 2026
35287b6
sess: `-Tfixed-x18` (again)
davidtwco Jul 24, 2026
4530682
sess: `-Tretpoline{,-external-thunk}` (again)
davidtwco Jul 24, 2026
8ce4cc8
sess: `-Treg-struct-return` (again)
davidtwco Jul 24, 2026
5a13e40
sess: `-Ttarget-cpu` (again)
davidtwco Jul 29, 2026
c87f767
sess: `-Tpointer-authentication` (again)
davidtwco Jul 29, 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: 1 addition & 3 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
to_add.extend(sanitize_attrs(cx, tcx, codegen_fn_attrs.sanitizers));

// For non-naked functions, set branch protection attributes on aarch64.
if let Some(BranchProtection { bti, pac_ret, gcs }) =
sess.opts.unstable_opts.branch_protection
{
if let Some(BranchProtection { bti, pac_ret, gcs }) = sess.opts.cg.branch_protection {
assert!(sess.target.arch == Arch::AArch64);
if bti {
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
Expand Down
7 changes: 3 additions & 4 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 All @@ -405,8 +405,7 @@ pub(crate) unsafe fn create_module<'ll>(
);
}

if let Some(BranchProtection { bti, pac_ret, gcs }) = sess.opts.unstable_opts.branch_protection
{
if let Some(BranchProtection { bti, pac_ret, gcs }) = sess.opts.cg.branch_protection {
if sess.target.arch == Arch::AArch64 {
llvm::add_module_flag_u32(
llmod,
Expand Down Expand Up @@ -511,7 +510,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/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,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(errors::FixedX18InvalidArch { arch: sess.target.arch.desc() });
} else {
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 @@ -537,7 +537,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 @@ -484,17 +484,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 @@ -939,6 +939,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 @@ -657,8 +667,14 @@ fn test_codegen_options_tracking_hash() {
tracked!(prefer_dynamic, true);
tracked!(profile_generate, SwitchWithOptPath::Enabled(None));
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 @@ -789,14 +805,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 @@ -820,7 +828,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 @@ -829,7 +836,6 @@ fn test_unstable_options_tracking_hash() {
tracked!(hint_mostly_unused, true);
tracked!(human_readable_cgu_names, true);
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 @@ -872,14 +878,10 @@ fn test_unstable_options_tracking_hash() {
tracked!(precise_enum_drop_elaboration, false);
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
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
136 changes: 12 additions & 124 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,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::cstore::{CrateDepKind, CrateSource, ExternCrate, ExternCrateSource};
use rustc_session::output::validate_crate_name;
use rustc_session::search_paths::PathKind;
Expand All @@ -38,9 +35,7 @@ use tracing::{debug, info, trace};

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 @@ -338,116 +333,6 @@ impl CStore {
}
}

fn report_target_modifiers_extended(
tcx: TyCtxt<'_>,
krate: &Crate,
mods: &TargetModifiers,
dep_mods: &TargetModifiers,
data: &CrateMetadata,
) {
let span = krate.spans.inner_span.shrink_to_lo();
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 {
span,
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 {
span,
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 {
span,
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, krate);
self.report_incompatible_partial_mitigations(tcx, krate);
Expand All @@ -456,22 +341,25 @@ impl CStore {

pub fn report_incompatible_target_modifiers(&self, tcx: TyCtxt<'_>, krate: &Crate) {
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 {
span: krate.spans.inner_span.shrink_to_lo(),
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, krate, &mods, &dep_mods, data);
}
tcx.sess.opts.cg.report_mismatched_flags_with_dep(
tcx.sess,
krate.spans.inner_span.shrink_to_lo(),
tcx.crate_name(LOCAL_CRATE),
data.target_modifiers(),
data.name(),
);
}
}

Expand Down
Loading
Loading