From cacf74a00d451557fc2b2c75dd1b21953e027426 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Fri, 20 Mar 2026 10:48:36 -0400 Subject: [PATCH 1/6] Attempt to fix Thin LTO --- src/back/write.rs | 25 ++----------------------- src/lib.rs | 1 + 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/back/write.rs b/src/back/write.rs index 24ea2b66ba7..4026edaa78f 100644 --- a/src/back/write.rs +++ b/src/back/write.rs @@ -1,6 +1,6 @@ use std::{env, fs}; -use gccjit::{Context, OutputKind}; +use gccjit::OutputKind; use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig}; use rustc_codegen_ssa::{CompiledModule, ModuleCodegen}; @@ -11,7 +11,6 @@ use rustc_log::tracing::debug; use rustc_session::config::OutputType; use rustc_target::spec::SplitDebuginfo; -use crate::base::add_pic_option; use crate::errors::CopyBitcode; use crate::{GccContext, LtoMode}; @@ -148,7 +147,6 @@ pub(crate) fn codegen( let path = obj_out.to_str().expect("path to str"); if fat_lto { - let lto_path = format!("{}.lto", path); // cSpell:disable // FIXME(antoyo): The LTO frontend generates the following warning: // ../build_sysroot/sysroot_src/library/core/src/num/dec2flt/lemire.rs:150:15: warning: type of ā€˜_ZN4core3num7dec2flt5table17POWER_OF_FIVE_12817ha449a68fb31379e4E’ does not match original declaration [-Wlto-type-mismatch] @@ -159,26 +157,7 @@ pub(crate) fn codegen( // This option is to mute it to make the UI tests pass with LTO enabled. // cSpell:enable context.add_driver_option("-Wno-lto-type-mismatch"); - // NOTE: this doesn't actually generate an executable. With the above - // flags, it combines the .o files together in another .o. - context.compile_to_file(OutputKind::Executable, <o_path); - - let context = Context::default(); - if cgcx.target_arch == "x86" || cgcx.target_arch == "x86_64" { - // NOTE: it seems we need to use add_driver_option instead of - // add_command_line_option here because we use the LTO frontend via gcc. - context.add_driver_option("-masm=intel"); - } - - // NOTE: these two options are needed to invoke LTO to produce an object file. - // We need to initiate a second compilation because the arguments "-x lto" - // needs to be at the very beginning. - context.add_driver_option("-x"); - context.add_driver_option("lto"); - add_pic_option(&context, module.module_llvm.relocation_model); - context.add_driver_option(lto_path); - - context.compile_to_file(OutputKind::ObjectFile, path); + context.compile_to_file(OutputKind::Executable, path); } else { // NOTE: this doesn't actually generate an executable. With the above // flags, it combines the .o files together in another .o. diff --git a/src/lib.rs b/src/lib.rs index 592eb68ce27..1740ee8914c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -384,6 +384,7 @@ pub struct GccContext { context: Arc, /// This field is needed in order to be able to set the flag -fPIC when necessary when doing /// LTO. + #[allow(dead_code)] relocation_model: RelocModel, lto_mode: LtoMode, lto_supported: bool, From 8ede342b5c9d486631d8a8a05f3e9917b9705ca2 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Mar 2026 10:49:23 +0100 Subject: [PATCH 2/6] Revert "Attempt to fix Thin LTO" This reverts commit cacf74a00d451557fc2b2c75dd1b21953e027426. --- src/back/write.rs | 25 +++++++++++++++++++++++-- src/lib.rs | 1 - 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/back/write.rs b/src/back/write.rs index 4026edaa78f..24ea2b66ba7 100644 --- a/src/back/write.rs +++ b/src/back/write.rs @@ -1,6 +1,6 @@ use std::{env, fs}; -use gccjit::OutputKind; +use gccjit::{Context, OutputKind}; use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig}; use rustc_codegen_ssa::{CompiledModule, ModuleCodegen}; @@ -11,6 +11,7 @@ use rustc_log::tracing::debug; use rustc_session::config::OutputType; use rustc_target::spec::SplitDebuginfo; +use crate::base::add_pic_option; use crate::errors::CopyBitcode; use crate::{GccContext, LtoMode}; @@ -147,6 +148,7 @@ pub(crate) fn codegen( let path = obj_out.to_str().expect("path to str"); if fat_lto { + let lto_path = format!("{}.lto", path); // cSpell:disable // FIXME(antoyo): The LTO frontend generates the following warning: // ../build_sysroot/sysroot_src/library/core/src/num/dec2flt/lemire.rs:150:15: warning: type of ā€˜_ZN4core3num7dec2flt5table17POWER_OF_FIVE_12817ha449a68fb31379e4E’ does not match original declaration [-Wlto-type-mismatch] @@ -157,7 +159,26 @@ pub(crate) fn codegen( // This option is to mute it to make the UI tests pass with LTO enabled. // cSpell:enable context.add_driver_option("-Wno-lto-type-mismatch"); - context.compile_to_file(OutputKind::Executable, path); + // NOTE: this doesn't actually generate an executable. With the above + // flags, it combines the .o files together in another .o. + context.compile_to_file(OutputKind::Executable, <o_path); + + let context = Context::default(); + if cgcx.target_arch == "x86" || cgcx.target_arch == "x86_64" { + // NOTE: it seems we need to use add_driver_option instead of + // add_command_line_option here because we use the LTO frontend via gcc. + context.add_driver_option("-masm=intel"); + } + + // NOTE: these two options are needed to invoke LTO to produce an object file. + // We need to initiate a second compilation because the arguments "-x lto" + // needs to be at the very beginning. + context.add_driver_option("-x"); + context.add_driver_option("lto"); + add_pic_option(&context, module.module_llvm.relocation_model); + context.add_driver_option(lto_path); + + context.compile_to_file(OutputKind::ObjectFile, path); } else { // NOTE: this doesn't actually generate an executable. With the above // flags, it combines the .o files together in another .o. diff --git a/src/lib.rs b/src/lib.rs index 1740ee8914c..592eb68ce27 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -384,7 +384,6 @@ pub struct GccContext { context: Arc, /// This field is needed in order to be able to set the flag -fPIC when necessary when doing /// LTO. - #[allow(dead_code)] relocation_model: RelocModel, lto_mode: LtoMode, lto_supported: bool, From 1e6139cdb781744a6d6ff2bb955fcedeefcaaf8b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Mar 2026 10:32:25 +0100 Subject: [PATCH 3/6] Disable ThinLTO on jobs that don't support LTO --- .github/workflows/ci.yml | 2 +- .github/workflows/m68k.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 840c09409bb..2b4a5db5433 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,7 +101,7 @@ jobs: - name: Run y.sh cargo build run: | - ./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml + CARGO_PROFILE_DEV_LTO=no ./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml - name: Clean run: | diff --git a/.github/workflows/m68k.yml b/.github/workflows/m68k.yml index 11bc88e67d2..8882830f669 100644 --- a/.github/workflows/m68k.yml +++ b/.github/workflows/m68k.yml @@ -83,7 +83,7 @@ jobs: run: | ./y.sh prepare --only-libcore --cross ./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json - CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ./y.sh cargo build -Zjson-target-spec --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json + CARGO_PROFILE_DEV_LTO=no CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ./y.sh cargo build -Zjson-target-spec --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json ./y.sh clean all - name: Build @@ -110,7 +110,7 @@ jobs: vm_dir=$(pwd)/vm cd tests/hello-world - CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ../../y.sh cargo build --target m68k-unknown-linux-gnu + CARGO_PROFILE_DEV_LTO=no CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ../../y.sh cargo build --target m68k-unknown-linux-gnu sudo cp target/m68k-unknown-linux-gnu/debug/hello_world $vm_dir/home/ sudo chroot $vm_dir qemu-m68k-static /home/hello_world > hello_world_stdout expected_output="40" From 1ecbe35cac82fec488d940fa1f391604f6ab758b Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Mar 2026 10:32:59 +0100 Subject: [PATCH 4/6] Add patch for testing sysroot --- patches/0030-Add-missing-feature-gate.patch | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 patches/0030-Add-missing-feature-gate.patch diff --git a/patches/0030-Add-missing-feature-gate.patch b/patches/0030-Add-missing-feature-gate.patch new file mode 100644 index 00000000000..a27ed4ea816 --- /dev/null +++ b/patches/0030-Add-missing-feature-gate.patch @@ -0,0 +1,37 @@ +From baa9c656ba61633f2e5785fc47bc8f88ed2f738e Mon Sep 17 00:00:00 2001 +From: bjorn3 <17426603+bjorn3@users.noreply.github.com> +Date: Wed, 11 Mar 2026 12:34:47 +0000 +Subject: [PATCH] Add missing feature gate + +--- + coretests/benches/lib.rs | 1 + + coretests/tests/lib.rs | 1 + + 2 file changed, 2 insertion(+) + +diff --git a/library/coretests/benches/lib.rs b/library/coretests/benches/lib.rs +index 150b9b3..281aa75 100644 +--- a/library/coretests/benches/lib.rs ++++ b/library/coretests/benches/lib.rs +@@ -8,6 +8,7 @@ + #![feature(iter_array_chunks)] + #![feature(iter_next_chunk)] + #![feature(iter_advance_by)] ++#![feature(num_internals)] + #![feature(uint_gather_scatter_bits)] + + extern crate test; +diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs +index ecdb687..ab2cf77 100644 +--- a/library/coretests/tests/lib.rs ++++ b/library/coretests/tests/lib.rs +@@ -88,6 +88,7 @@ + #![feature(non_exhaustive_omitted_patterns_lint)] + #![feature(nonzero_from_str_radix)] + #![feature(numfmt)] ++#![feature(num_internals)] + #![feature(one_sided_range)] + #![feature(panic_internals)] + #![feature(pattern)] +-- +2.43.0 + From f2e46920c41a02b0a0fabfc2a6c8332fac799050 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Mar 2026 10:41:51 +0100 Subject: [PATCH 5/6] Temporarily disable f16 and f128 support There are a bunch of intrinsics not yet implemented. --- src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 592eb68ce27..a7e0972ccf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -547,8 +547,9 @@ fn target_config(sess: &Session, target_info: &LockedTargetInfo) -> TargetConfig }, ); - let has_reliable_f16 = target_info.supports_target_dependent_type(CType::Float16); - let has_reliable_f128 = target_info.supports_target_dependent_type(CType::Float128); + // FIXME re-enable once the necessary intrinsics are implemented + let has_reliable_f16 = false; //target_info.supports_target_dependent_type(CType::Float16); + let has_reliable_f128 = false; //target_info.supports_target_dependent_type(CType::Float128); TargetConfig { target_features, From 4ca5b1e19ece79239f1a2a5bf41104dc9bdca735 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 23 Mar 2026 11:35:07 +0100 Subject: [PATCH 6/6] Update list of failing tests --- tests/failing-lto-tests.txt | 1 - tests/failing-ui-tests.txt | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/failing-lto-tests.txt b/tests/failing-lto-tests.txt index c45fc077658..4c62c35a512 100644 --- a/tests/failing-lto-tests.txt +++ b/tests/failing-lto-tests.txt @@ -1,4 +1,3 @@ -tests/ui/lto/all-crates.rs tests/ui/lto/debuginfo-lto-alloc.rs tests/ui/panic-runtime/lto-unwind.rs tests/ui/uninhabited/uninhabited-transparent-return-abi.rs diff --git a/tests/failing-ui-tests.txt b/tests/failing-ui-tests.txt index 8589929d2fb..5739b2cbd5d 100644 --- a/tests/failing-ui-tests.txt +++ b/tests/failing-ui-tests.txt @@ -99,3 +99,7 @@ tests/ui/eii/privacy1.rs tests/ui/eii/default/call_impl.rs tests/ui/c-variadic/copy.rs tests/ui/asm/x86_64/global_asm_escape.rs +tests/ui/lto/all-crates.rs +tests/ui/consts/const-eval/c-variadic.rs +tests/ui/eii/default/call_default_panics.rs +tests/ui/explicit-tail-calls/indirect.rs