From 9e67ac6e7e9e9ee34bb9869b6de2b75d23e31e16 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:07:23 +0200 Subject: [PATCH 1/8] compiler: fix bug and span_bug imports --- src/abi.rs | 2 +- src/allocator.rs | 2 +- src/asm.rs | 3 +-- src/builder.rs | 3 +-- src/consts.rs | 2 +- src/intrinsic/mod.rs | 3 +-- src/mono_item.rs | 2 +- src/type_.rs | 3 ++- src/type_of.rs | 2 +- 9 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/abi.rs b/src/abi.rs index 2901eb8b1a6..6a05f1cbbee 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -6,11 +6,11 @@ use rustc_abi::{ArmCall, CanonAbi, InterruptKind, X86Call}; use rustc_abi::{Reg, RegKind}; use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeCodegenMethods}; use rustc_data_structures::fx::FxHashSet; -use rustc_middle::bug; use rustc_middle::ty::Ty; use rustc_middle::ty::layout::LayoutOf; #[cfg(feature = "master")] use rustc_session::{Session, config}; +use rustc_span::bug; use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode}; #[cfg(feature = "master")] use rustc_target::spec::Arch; diff --git a/src/allocator.rs b/src/allocator.rs index 6b92174ddf1..dc69bfad57b 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -4,8 +4,8 @@ use gccjit::{Context, FunctionType, ToRValue, Type}; use rustc_ast::expand::allocator::{ AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name, }; -use rustc_middle::bug; use rustc_middle::ty::TyCtxt; +use rustc_span::bug; use rustc_symbol_mangling::mangle_internal_symbol; use crate::GccContext; diff --git a/src/asm.rs b/src/asm.rs index 8fd438d847d..420bf1e7a31 100644 --- a/src/asm.rs +++ b/src/asm.rs @@ -12,11 +12,10 @@ use rustc_codegen_ssa::traits::{ AsmBuilderMethods, AsmCodegenMethods, BaseTypeCodegenMethods, BuilderMethods, GlobalAsmOperandRef, InlineAsmOperandRef, }; -use rustc_middle::bug; use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar}; use rustc_middle::ty::Instance; use rustc_middle::ty::layout::LayoutOf; -use rustc_span::{DUMMY_SP, Span}; +use rustc_span::{DUMMY_SP, Span, bug}; use rustc_target::asm::*; use crate::builder::Builder; diff --git a/src/builder.rs b/src/builder.rs index 83f2bcdd395..0a88085960e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -21,15 +21,14 @@ use rustc_codegen_ssa::traits::{ LayoutTypeCodegenMethods, OverflowOp, ReturnSlot, StaticBuilderMethods, }; use rustc_data_structures::fx::FxHashSet; -use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers, TyAndLayout, }; use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt}; -use rustc_span::Span; use rustc_span::def_id::DefId; +use rustc_span::{Span, bug}; use rustc_target::callconv::FnAbi; use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi}; diff --git a/src/consts.rs b/src/consts.rs index 42ff9309685..6c3b404547c 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -15,8 +15,8 @@ use rustc_middle::mir::interpret::{ }; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Instance}; -use rustc_middle::{bug, span_bug}; use rustc_span::def_id::DefId; +use rustc_span::{bug, span_bug}; use crate::base; use crate::context::CodegenCx; diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index 06713016ced..624cd2dcb73 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -24,8 +24,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Instance, Ty}; -use rustc_middle::{bug, span_bug}; -use rustc_span::{Span, Symbol, sym}; +use rustc_span::{Span, Symbol, bug, span_bug, sym}; use rustc_target::callconv::{ArgAbi, PassMode}; #[cfg(feature = "master")] diff --git a/src/mono_item.rs b/src/mono_item.rs index d5874779021..fc92cc3d5c7 100644 --- a/src/mono_item.rs +++ b/src/mono_item.rs @@ -4,11 +4,11 @@ use rustc_codegen_ssa::traits::PreDefineCodegenMethods; use rustc_hir::attrs::Linkage; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; -use rustc_middle::bug; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mono::Visibility; use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf}; use rustc_middle::ty::{self, Instance, TypeVisitableExt}; +use rustc_span::bug; use crate::context::CodegenCx; use crate::type_of::LayoutGccExt; diff --git a/src/type_.rs b/src/type_.rs index 5252f93a92e..27b0d2079e6 100644 --- a/src/type_.rs +++ b/src/type_.rs @@ -9,8 +9,9 @@ use rustc_codegen_ssa::common::TypeKind; use rustc_codegen_ssa::traits::{ BaseTypeCodegenMethods, DerivedTypeCodegenMethods, TypeMembershipCodegenMethods, }; +use rustc_middle::ty; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::{bug, ty}; +use rustc_span::bug; use crate::common::TypeReflection; use crate::context::{CodegenCx, new_array_type}; diff --git a/src/type_of.rs b/src/type_of.rs index 53192c0a087..31654d0e6be 100644 --- a/src/type_of.rs +++ b/src/type_of.rs @@ -9,10 +9,10 @@ use rustc_abi::{ use rustc_codegen_ssa::traits::{ BaseTypeCodegenMethods, DerivedTypeCodegenMethods, LayoutTypeCodegenMethods, }; -use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, CoroutineArgsExt, Ty, TypeVisitableExt}; +use rustc_span::bug; use rustc_target::callconv::{CastTarget, FnAbi}; use crate::abi::{FnAbiGcc, FnAbiGccExt, GccType}; From aa95ad8a2753a03e98ceedc243b7cfc883adf592 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 28 Aug 2026 13:45:54 +1000 Subject: [PATCH 2/8] Split `build_session` Session creation is currently awkward: we build a mostly-initialized session, then use it to initialize a codegen backend, and then use the codegen backend to finish initializing the session. And it's not just awkward: within the Cranelift backend's `init` method `sess.lto()` is called, which consults `sess.thin_lto_supported`, *before* that field has been properly set! In practice it had no effect but it's worth fixing. This commit cleans up this mess. It introduces `EarlySession`, which contains just four `Session` fields, the ones that are needed for codegen backend initialization. It is now a field within `Session`, and `Session` derefs to `EarlySession` to avoid changing a zillion `sess.target`/`sess.opts`/etc. occurrences. `EarlySession` is passed to `init`, which returns a `CodegenBackendInit` that contains the backend-specific information needed to build a `Session`. (It replaces the `replaced_intrinsics`, `fallback_intrinsics`, and `thin_lto_supported` methods.) The `Session` can then be built in a single step. No more `Session`/`CodegenBackend` initialization intermingling. A few functions that previously took a `Session` now take something else, e.g. a `Target`. Some `Session` methods are now `EarlySession` methods. And a new `early_lto` method is used for Cranelift's LTO check. --- src/attributes.rs | 2 +- src/context.rs | 4 ++-- src/gcc_util.rs | 18 +++++++++--------- src/intrinsic/mod.rs | 2 +- src/lib.rs | 24 +++++++++++------------- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/attributes.rs b/src/attributes.rs index ce1877b308e..321e150a156 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -124,7 +124,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>( .target_features .iter() .map(|features| features.name.as_str()) - .flat_map(|feat| to_gcc_features(cx.tcx.sess, feat).into_iter()) + .flat_map(|feat| to_gcc_features(&cx.tcx.sess.target, feat).into_iter()) .chain(codegen_fn_attrs.instruction_set.iter().map(|x| match *x { InstructionSetAttr::ArmA32 => "-thumb-mode", // FIXME(antoyo): support removing feature. InstructionSetAttr::ArmT32 => "thumb-mode", diff --git a/src/context.rs b/src/context.rs index 64f9982ac7d..38e0e5f329f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -450,7 +450,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { } let tcx = self.tcx; let func = match tcx.lang_items().eh_personality() { - Some(def_id) if !wants_msvc_seh(self.sess()) => { + Some(def_id) if !wants_msvc_seh(&self.sess().target) => { let instance = ty::Instance::expect_resolve( tcx, self.typing_env(), @@ -465,7 +465,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> { self.declare_fn(symbol_name, fn_abi) } _ => { - let name = if wants_msvc_seh(self.sess()) { + let name = if wants_msvc_seh(&self.sess().target) { "__CxxFrameHandler3" } else { "rust_eh_personality" diff --git a/src/gcc_util.rs b/src/gcc_util.rs index a95b4da28eb..24f552fed32 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -2,18 +2,18 @@ use gccjit::Context; use rustc_codegen_ssa::target_features; use rustc_data_structures::smallvec::{SmallVec, smallvec}; -use rustc_session::Session; +use rustc_session::EarlySession; use rustc_session::config::NATIVE_CPU; -use rustc_target::spec::Arch; +use rustc_target::spec::{Arch, Target}; -fn gcc_features_by_flags(sess: &Session, features: &mut Vec) { +fn gcc_features_by_flags(sess: &EarlySession, features: &mut Vec) { target_features::retpoline_features_by_flags(sess, features); // FIXME: LLVM also sets +reserve-x18 here under some conditions. } /// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`, /// `--target` and similar). -pub(crate) fn global_gcc_features(sess: &Session) -> Vec { +pub(crate) fn global_gcc_features(sess: &EarlySession) -> Vec { // Features that come earlier are overridden by conflicting features later in the string. // Typically we'll want more explicit settings to override the implicit ones, so: // @@ -40,9 +40,9 @@ pub(crate) fn global_gcc_features(sess: &Session) -> Vec { // features also work on the command line instead of having two // different names when the GCC name and the Rust name differ. features.extend( - to_gcc_features(sess, feature) + to_gcc_features(&sess.target, feature) .iter() - .flat_map(|feat| to_gcc_features(sess, feat).into_iter()) + .flat_map(|feat| to_gcc_features(&sess.target, feat).into_iter()) .map(|feature| if !enable { format!("-{}", feature) } else { feature.to_string() }), ); }; @@ -59,9 +59,9 @@ pub(crate) fn global_gcc_features(sess: &Session) -> Vec { } // To find a list of GCC's names, check https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html -pub fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> { +pub fn to_gcc_features<'a>(target: &Target, s: &'a str) -> SmallVec<[&'a str; 2]> { // cSpell:disable - match (&sess.target.arch, s) { + match (&target.arch, s) { // FIXME: seems like x87 does not exist? (&Arch::X86 | &Arch::X86_64, "x87") => smallvec![], (&Arch::X86 | &Arch::X86_64, "sse4.2") => smallvec!["sse4.2", "crc32"], @@ -130,7 +130,7 @@ fn handle_native(name: &str) -> &str { unimplemented!(); } -pub fn target_cpu(sess: &Session) -> &str { +pub fn target_cpu(sess: &EarlySession) -> &str { match sess.opts.cg.target_cpu { Some(ref name) => handle_native(name), None => handle_native(sess.target.cpu.as_ref()), diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index 624cd2dcb73..41fa7b3f9f1 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -1352,7 +1352,7 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>( // we can never unwind. OperandValue::Immediate(bx.const_bool(false)).store(bx, dest); } else { - if wants_msvc_seh(bx.sess()) { + if wants_msvc_seh(&bx.sess().target) { unimplemented!(); } #[cfg(feature = "master")] diff --git a/src/lib.rs b/src/lib.rs index 2fb5459a202..6e40827c484 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,7 +95,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductMap}; use rustc_middle::ty::TyCtxt; use rustc_middle::util::Providers; use rustc_session::config::{OptLevel, OutputFilenames}; -use rustc_session::{IncrCompSession, Session}; +use rustc_session::{CodegenBackendInit, EarlySession, IncrCompSession, Session}; use rustc_span::{Symbol, sym}; use rustc_target::spec::{Arch, RelocModel}; use tempfile::TempDir; @@ -195,8 +195,8 @@ impl CodegenBackend for GccCodegenBackend { "gcc" } - fn init(&self, sess: &Session) { - fn file_path(sysroot_path: &Path, sess: &Session) -> PathBuf { + fn init(&self, sess: &EarlySession) -> CodegenBackendInit { + fn file_path(sysroot_path: &Path, sess: &EarlySession) -> PathBuf { let rustlib_path = rustc_target::relative_target_rustlib_path(sysroot_path, &sess.host.llvm_target); sysroot_path @@ -274,10 +274,12 @@ impl CodegenBackend for GccCodegenBackend { .supports_128bit_integers .store(check_context.get_last_error() == Ok(None), Ordering::SeqCst); } - } - fn thin_lto_supported(&self) -> bool { - false + CodegenBackendInit { + replaced_intrinsics: vec![], + fallback_intrinsics: vec![sym::type_id_eq], + thin_lto_supported: false, + } } fn provide(&self, providers: &mut Providers) { @@ -307,13 +309,9 @@ impl CodegenBackend for GccCodegenBackend { .join(sess, incr_comp_session, crate_info) } - fn target_config(&self, sess: &Session) -> TargetConfig { + fn target_config(&self, sess: &EarlySession) -> TargetConfig { target_config(sess, &self.target_info) } - - fn fallback_intrinsics(&self) -> Vec { - vec![sym::type_id_eq] - } } fn new_context<'gcc, 'tcx>(tcx: TyCtxt<'tcx>) -> Context<'gcc> { @@ -532,10 +530,10 @@ fn to_gcc_opt_level(optlevel: Option) -> OptimizationLevel { } /// Returns the features that should be set in `cfg(target_feature)`. -fn target_config(sess: &Session, target_info: &LockedTargetInfo) -> TargetConfig { +fn target_config(sess: &EarlySession, target_info: &LockedTargetInfo) -> TargetConfig { let internal_target_features = internal_target_features( sess, - |feature| to_gcc_features(sess, feature), + |feature| to_gcc_features(&sess.target, feature), |feature| { // FIXME: we disable Neon for now since we don't support the LLVM intrinsics for it. if feature == "neon" { From 68b945d587a455a781c701de146e6f5085833810 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 28 Aug 2026 16:12:32 +1000 Subject: [PATCH 3/8] Change `CodegenBackend::init` to take `&mut self` It currently takes `&self`, which is a bit strange for an `init` method. As a result, the Cranelift and GCC backends have to use types with interior mutability. This commit changes it to `&mut self`. Benefits: - The Cranelift backend can use `Option` instead of `OnceCell` to indicate uninit vs. init. - The GCC backend can avoid `Mutex`, and use `bool` instead of `AtomicBool`, which makes things much simpler. The commit also restructures `GccCodegenBackend` to mirror `CraneliftCodegenBackend`: just contain an `Option`, which makes the uninit vs. init distinction foolproof. (E.g. no need to set `lto_supported` to false and then later overwrite it with the real value.) As part of this the `LockedTargetInfo` type is renamed `SharedTargetInfo` because that better matches its new internals. (All this compiles both with and without the "master" feature set.) --- src/base.rs | 6 +-- src/lib.rs | 109 +++++++++++++++------------------------------------- 2 files changed, 35 insertions(+), 80 deletions(-) diff --git a/src/base.rs b/src/base.rs index 7a25fc46fd3..101af0bb0bf 100644 --- a/src/base.rs +++ b/src/base.rs @@ -21,7 +21,7 @@ use rustc_target::spec::{Arch, RelocModel}; use crate::builder::Builder; use crate::context::CodegenCx; -use crate::{GccContext, LockedTargetInfo, LtoMode, SyncContext, gcc_util, new_context}; +use crate::{GccContext, LtoMode, SharedTargetInfo, SyncContext, gcc_util, new_context}; #[cfg(feature = "master")] pub fn visibility_to_gcc(visibility: Visibility) -> gccjit::Visibility { @@ -73,7 +73,7 @@ pub fn linkage_to_gcc(linkage: Linkage) -> FunctionType { pub fn compile_codegen_unit( tcx: TyCtxt<'_>, cgu_name: Symbol, - target_info: LockedTargetInfo, + target_info: SharedTargetInfo, lto_supported: bool, ) -> (ModuleCodegen, u64) { let prof_timer = tcx.prof.generic_activity("codegen_module"); @@ -96,7 +96,7 @@ pub fn compile_codegen_unit( fn module_codegen( tcx: TyCtxt<'_>, cgu_name: Symbol, - target_info: LockedTargetInfo, + target_info: SharedTargetInfo, lto_supported: bool, ) -> ModuleCodegen { let cgu = tcx.codegen_unit(cgu_name); diff --git a/src/lib.rs b/src/lib.rs index 6e40827c484..52d732924c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,12 +69,10 @@ mod type_of; use std::any::Any; use std::ffi::CString; -use std::fmt::Debug; use std::fs; use std::ops::Deref; use std::path::{Path, PathBuf}; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use gccjit::{CType, Context, OptimizationLevel}; #[cfg(feature = "master")] @@ -116,7 +114,7 @@ impl String> Drop for PrintOnPanic { #[cfg(not(feature = "master"))] #[derive(Debug)] pub struct TargetInfo { - supports_128bit_integers: AtomicBool, + supports_128bit_integers: bool, } #[cfg(not(feature = "master"))] @@ -128,7 +126,7 @@ impl TargetInfo { fn supports_target_dependent_type(&self, typ: CType) -> bool { match typ { CType::UInt128t | CType::Int128t => { - if self.supports_128bit_integers.load(Ordering::SeqCst) { + if self.supports_128bit_integers { return true; } } @@ -138,43 +136,26 @@ impl TargetInfo { } } +type SharedTargetInfo = Arc>; + #[derive(Clone)] -pub struct LockedTargetInfo { - info: Arc>>>, +pub struct BackendConfig { + target_info: SharedTargetInfo, + lto_supported: bool, } -impl Debug for LockedTargetInfo { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.info.lock().expect("lock").fmt(formatter) - } +#[derive(Clone)] +pub struct GccCodegenBackend { + // `None` before `init`, `Some` after. + pub config: Option, } -impl LockedTargetInfo { - fn cpu_supports(&self, feature: &str) -> bool { - self.info - .lock() - .expect("lock") - .as_ref() - .expect("target info not initialized") - .cpu_supports(feature) - } - - fn supports_target_dependent_type(&self, typ: CType) -> bool { - self.info - .lock() - .expect("lock") - .as_ref() - .expect("target info not initialized") - .supports_target_dependent_type(typ) +impl GccCodegenBackend { + fn config(&self) -> &BackendConfig { + self.config.as_ref().expect("target info not initialized") } } -#[derive(Clone)] -pub struct GccCodegenBackend { - target_info: LockedTargetInfo, - lto_supported: Arc, -} - fn load_libgccjit_if_needed(libgccjit_target_lib_file: &Path) { if gccjit::is_loaded() { // Do not load a libgccjit second time. @@ -195,7 +176,7 @@ impl CodegenBackend for GccCodegenBackend { "gcc" } - fn init(&self, sess: &EarlySession) -> CodegenBackendInit { + fn init(&mut self, sess: &EarlySession) -> CodegenBackendInit { fn file_path(sysroot_path: &Path, sess: &EarlySession) -> PathBuf { let rustlib_path = rustc_target::relative_target_rustlib_path(sysroot_path, &sess.host.llvm_target); @@ -240,14 +221,10 @@ impl CodegenBackend for GccCodegenBackend { context.add_command_line_option(format!("-march={}", target_cpu)); } - *self.target_info.info.lock().expect("lock") = - IntoDynSyncSend(Some(context.get_target_info())); - } - - #[cfg(feature = "master")] - { - let lto_supported = gccjit::is_lto_supported(); - self.lto_supported.store(lto_supported, Ordering::SeqCst); + self.config = Some(BackendConfig { + target_info: Arc::new(IntoDynSyncSend(context.get_target_info())), + lto_supported: gccjit::is_lto_supported(), + }); gccjit::set_global_personality_function_name(b"rust_eh_personality\0"); } @@ -264,15 +241,12 @@ impl CodegenBackend for GccCodegenBackend { gccjit::OutputKind::Assembler, temp_file.to_str().expect("path to str"), ); - self.target_info - .info - .lock() - .expect("lock") - .0 - .as_ref() - .expect("target info not initialized") - .supports_128bit_integers - .store(check_context.get_last_error() == Ok(None), Ordering::SeqCst); + let target_info = + TargetInfo { supports_128bit_integers: check_context.get_last_error() == Ok(None) }; + self.config = Some(BackendConfig { + target_info: Arc::new(IntoDynSyncSend(target_info)), + lto_supported: false, + }); } CodegenBackendInit { @@ -310,7 +284,7 @@ impl CodegenBackend for GccCodegenBackend { } fn target_config(&self, sess: &EarlySession) -> TargetConfig { - target_config(sess, &self.target_info) + target_config(sess, &self.config().target_info) } } @@ -344,12 +318,11 @@ impl ExtraBackendMethods for GccCodegenBackend { module_name: &str, methods: &[AllocatorMethod], ) -> Self::Module { - let lto_supported = self.lto_supported.load(Ordering::SeqCst); let mut mods = GccContext { context: Arc::new(SyncContext::new(new_context(tcx))), relocation_model: tcx.sess.relocation_model(), lto_mode: LtoMode::None, - lto_supported, + lto_supported: self.config().lto_supported, temp_dir: None, }; @@ -365,12 +338,8 @@ impl ExtraBackendMethods for GccCodegenBackend { cgu_name: Symbol, _bitcode_needed: bool, ) -> (ModuleCodegen, u64) { - base::compile_codegen_unit( - tcx, - cgu_name, - self.target_info.clone(), - self.lto_supported.load(Ordering::SeqCst), - ) + let config = self.config(); + base::compile_codegen_unit(tcx, cgu_name, config.target_info.clone(), config.lto_supported) } } @@ -499,21 +468,7 @@ impl WriteBackendMethods for GccCodegenBackend { /// This is the entrypoint for a hot plugged rustc_codegen_gccjit #[unsafe(no_mangle)] pub fn __rustc_codegen_backend() -> Box { - #[cfg(feature = "master")] - let info = { - // Check whether the target supports 128-bit integers, and sized floating point types (like - // Float16). - Arc::new(Mutex::new(IntoDynSyncSend(None))) - }; - #[cfg(not(feature = "master"))] - let info = Arc::new(Mutex::new(IntoDynSyncSend(Some(TargetInfo { - supports_128bit_integers: AtomicBool::new(false), - })))); - - Box::new(GccCodegenBackend { - lto_supported: Arc::new(AtomicBool::new(false)), - target_info: LockedTargetInfo { info }, - }) + Box::new(GccCodegenBackend { config: None }) } fn to_gcc_opt_level(optlevel: Option) -> OptimizationLevel { @@ -530,7 +485,7 @@ fn to_gcc_opt_level(optlevel: Option) -> OptimizationLevel { } /// Returns the features that should be set in `cfg(target_feature)`. -fn target_config(sess: &EarlySession, target_info: &LockedTargetInfo) -> TargetConfig { +fn target_config(sess: &EarlySession, target_info: &SharedTargetInfo) -> TargetConfig { let internal_target_features = internal_target_features( sess, |feature| to_gcc_features(&sess.target, feature), From c2cd957dd39b536e63742896c6c696a19ec5938d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 28 Aug 2026 16:37:48 +1000 Subject: [PATCH 4/8] Remove `global_backend_features` query It's now possible to get the backend features (a `Vec`) when the codegen backend is started, pass it back through `CodegenBackendInit`, and just store it in the `Session`. This removes the need for the query. Also: - `WriteBackendMethods::target_machine_factory` no longer needs the `target_features` parameter, because it's now available through the `sess` parameter. - `CodegenContext` no longer needs the `backend_features` field because we can use `sess.global_backend_features` instead. - `CodegenBackend::provide` is now a no-op for all the in-tree backends. I haven't removed it because out-of-tree backends still rely on it. --- src/attributes.rs | 2 +- src/lib.rs | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/attributes.rs b/src/attributes.rs index 321e150a156..a5cc44a46e1 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -133,7 +133,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>( // FIXME(antoyo): cg_llvm adds global features to each function so that LTO keep them. // Check if GCC requires the same. - let mut global_features = cx.tcx.global_backend_features(()).iter().map(|s| s.as_str()); + let mut global_features = cx.tcx.sess.global_backend_features.iter().map(|s| s.as_str()); function_features.extend(&mut global_features); let target_features = function_features .iter() diff --git a/src/lib.rs b/src/lib.rs index 52d732924c8..d7a3ef3b4a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,6 @@ use rustc_data_structures::sync::IntoDynSyncSend; use rustc_errors::{DiagCtxt, DiagCtxtHandle}; use rustc_middle::dep_graph::{WorkProduct, WorkProductMap}; use rustc_middle::ty::TyCtxt; -use rustc_middle::util::Providers; use rustc_session::config::{OptLevel, OutputFilenames}; use rustc_session::{CodegenBackendInit, EarlySession, IncrCompSession, Session}; use rustc_span::{Symbol, sym}; @@ -188,6 +187,8 @@ impl CodegenBackend for GccCodegenBackend { .join("libgccjit.so") } + let global_backend_features = gcc_util::global_gcc_features(sess); + // We use all_paths() instead of only path() in case the path specified by --sysroot is // invalid. // This is the case for instance in Rust for Linux where they specify --sysroot=/dev/null. @@ -250,17 +251,13 @@ impl CodegenBackend for GccCodegenBackend { } CodegenBackendInit { + global_backend_features, replaced_intrinsics: vec![], fallback_intrinsics: vec![sym::type_id_eq], thin_lto_supported: false, } } - fn provide(&self, providers: &mut Providers) { - providers.queries.global_backend_features = - |tcx, ()| gcc_util::global_gcc_features(tcx.sess) - } - fn target_cpu(&self, sess: &Session) -> String { target_cpu(sess).to_owned() } @@ -397,7 +394,6 @@ impl WriteBackendMethods for GccCodegenBackend { &self, _sess: &Session, _opt_level: OptLevel, - _features: &[String], ) -> TargetMachineFactoryFn { // FIXME(antoyo): set opt level. Arc::new(|_, _| ()) From 9e0ad85cccfe49049a11e083dd98cbaa864cb252 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Fri, 18 Sep 2026 09:44:25 -0400 Subject: [PATCH 5/8] Update to nightly-2026-09-18 --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index 4e47a84698e..0c81f7c7c73 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2026-09-14" +channel = "nightly-2026-09-18" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] From 5cc5408cc36537003444de501f8d6274480db93e Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Fri, 18 Sep 2026 09:44:30 -0400 Subject: [PATCH 6/8] Fix compilation --- src/gcc_util.rs | 2 +- src/intrinsic/simd.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/gcc_util.rs b/src/gcc_util.rs index 32467286edb..7112e9b5e74 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -7,7 +7,7 @@ use gccjit::Context; use gccjit::Version; use rustc_codegen_ssa::target_features; use rustc_data_structures::smallvec::{SmallVec, smallvec}; -use rustc_session::EarlySession; +use rustc_session::{EarlySession, Session}; use rustc_session::config::NATIVE_CPU; use rustc_target::spec::{Arch, RelocModel, StackProbeType, StackProtector, Target}; diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs index 02f1f7efd9c..bb32a85f193 100644 --- a/src/intrinsic/simd.rs +++ b/src/intrinsic/simd.rs @@ -15,10 +15,9 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods, LayoutTy #[cfg(feature = "master")] use rustc_hir as hir; use rustc_middle::mir::BinOp; -use rustc_middle::span_bug; use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf}; use rustc_middle::ty::{self, Ty}; -use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; +use rustc_span::{ErrorGuaranteed, Span, Symbol, span_bug, sym}; use crate::builder::Builder; #[cfg(not(feature = "master"))] From 461b54148c06d538992dd824e5cc4737e65ad2a6 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Fri, 18 Sep 2026 09:44:46 -0400 Subject: [PATCH 7/8] Fix formatting --- src/gcc_util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gcc_util.rs b/src/gcc_util.rs index 7112e9b5e74..0628171e488 100644 --- a/src/gcc_util.rs +++ b/src/gcc_util.rs @@ -7,8 +7,8 @@ use gccjit::Context; use gccjit::Version; use rustc_codegen_ssa::target_features; use rustc_data_structures::smallvec::{SmallVec, smallvec}; -use rustc_session::{EarlySession, Session}; use rustc_session::config::NATIVE_CPU; +use rustc_session::{EarlySession, Session}; use rustc_target::spec::{Arch, RelocModel, StackProbeType, StackProtector, Target}; fn gcc_features_by_flags(sess: &EarlySession, features: &mut Vec) { From addf907be33eb8adb9d15ff85d074b978d66f01f Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Fri, 18 Sep 2026 10:16:07 -0400 Subject: [PATCH 8/8] Add failing ICE tests --- tests/failing-ice-tests.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/failing-ice-tests.txt b/tests/failing-ice-tests.txt index ca685eb2af7..f9d6f99e7b4 100644 --- a/tests/failing-ice-tests.txt +++ b/tests/failing-ice-tests.txt @@ -41,3 +41,7 @@ tests/ui/codegen/incorrect-arch-intrinsic.rs tests/ui/codegen/custom-target-invalid-llvm-target.rs tests/ui/asm/x86_64/naked_asm_escape.rs tests/ui/lto/debuginfo-lto-alloc.rs +tests/ui/codegen/normalization-overflow/recursion-issue-118590.rs +tests/ui/codegen/normalization-overflow/recursion-issue-122823.rs +tests/ui/codegen/normalization-overflow/recursion-issue-131342.rs +tests/ui/codegen/normalization-overflow/recursion-issue-92004.rs