Compare commits

...

2 Commits

Author SHA1 Message Date
Rust timing bot
4b535ca2e2 Unrolled build for #149624
Some checks failed
CI / Calculate job matrix (push) Has been cancelled
CI / ${{ matrix.full_name }} (push) Has been cancelled
CI / publish toolstate (push) Has been cancelled
Rollup merge of #149624 - Flakebi:fix-lto, r=bjorn3

Fix requires_lto targets needing lto set in cargo

Targets that set `requires_lto = true` were not actually using lto when compiling with cargo by default. They needed an extra `lto = true` in `Cargo.toml` to work.

Fix this by letting lto take precedence over the `embed_bitcode` flag when lto is required by a target.

If both these flags would be supplied by the user, an error is generated. However, this did not happen when lto was requested by the target instead of the user.

Fixes rust-lang/rust#148514
Tracking issue: rust-lang/rust#135024
2026-04-27 07:57:45 +02:00
Flakebi
842c087427 Fix requires_lto targets needing lto set in cargo
Targets that set `requires_lto = true` were not actually using lto when
compiling with cargo by default. They needed an extra `lto = true` in
`Cargo.toml` to work.

Fix this by letting lto take precedence over the `embed_bitcode` flag
when lto is required by a target.

If both these flags would be supplied by the user, an error is
generated. However, this did not happen when lto was requested by the
target instead of the user.
2025-12-29 21:56:52 +01:00
5 changed files with 52 additions and 6 deletions

View File

@@ -153,7 +153,7 @@ impl ModuleConfig {
// `#![no_builtins]` is assumed to not participate in LTO and
// instead goes on to generate object code.
EmitObj::Bitcode
} else if need_bitcode_in_object(tcx) {
} else if need_bitcode_in_object(tcx) || sess.target.requires_lto {
EmitObj::ObjectCode(BitcodeSection::Full)
} else {
EmitObj::ObjectCode(BitcodeSection::None)

View File

@@ -59,11 +59,6 @@ Build the library as `cdylib`:
# Cargo.toml
[lib]
crate-type = ["cdylib"]
[profile.dev]
lto = true # LTO must be explicitly enabled for now
[profile.release]
lto = true
```
The target-cpu must be from the list [supported by LLVM] (or printed with `rustc --target amdgcn-amd-amdhsa --print target-cpus`).

View File

@@ -0,0 +1,8 @@
[package]
name = "amdgpu_lto"
version = "0.1.0"
edition = "2024"
[lib]
path = "lib.rs"
crate-type = ["cdylib"]

View File

@@ -0,0 +1,15 @@
#![feature(abi_gpu_kernel)]
#![no_std]
#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[unsafe(no_mangle)]
fn foo(a: i32, b: i32) -> i32 {
a + b
}
#[unsafe(no_mangle)]
extern "gpu-kernel" fn kernel() {}

View File

@@ -0,0 +1,28 @@
// Check that compiling for the amdgpu target which needs LTO works with a default
// cargo configuration.
//@ needs-llvm-components: amdgpu
//@ needs-rust-lld
#![deny(warnings)]
use run_make_support::{cargo, path};
fn main() {
let target_dir = path("target");
cargo()
.args(&[
"build",
"--release",
"--lib",
"--manifest-path",
"Cargo.toml",
"-Zbuild-std=core",
"--target",
"amdgcn-amd-amdhsa",
])
.env("RUSTFLAGS", "-Ctarget-cpu=gfx900")
.env("CARGO_TARGET_DIR", &target_dir)
.run();
}