Skip to content

Commit fa030b3

Browse files
committed
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.
1 parent 66812a3 commit fa030b3

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ struct CompiledModules {
410410

411411
fn need_bitcode_in_object(tcx: TyCtxt<'_>) -> bool {
412412
let sess = tcx.sess;
413-
sess.opts.cg.embed_bitcode
413+
(sess.lto() != config::Lto::No || sess.opts.cg.embed_bitcode)
414414
&& tcx.crate_types().contains(&CrateType::Rlib)
415415
&& sess.opts.output_types.contains_key(&OutputType::Exe)
416416
}

src/doc/rustc/src/platform-support/amdgcn-amd-amdhsa.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ Build the library as `cdylib`:
5656
# Cargo.toml
5757
[lib]
5858
crate-type = ["cdylib"]
59-
60-
[profile.dev]
61-
lto = true # LTO must be explicitly enabled for now
62-
[profile.release]
63-
lto = true
6459
```
6560

6661
The target-cpu must be from the list [supported by LLVM] (or printed with `rustc --target amdgcn-amd-amdhsa --print target-cpus`).
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "amdgpu_lto"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lib]
7+
path = "lib.rs"
8+
crate-type = ["cdylib"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![no_std]
2+
3+
#[panic_handler]
4+
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
5+
loop {}
6+
}
7+
8+
#[unsafe(no_mangle)]
9+
fn foo() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Check that compiling for the amdgpu target which has requires_lto=true works with a default
2+
// cargo configuration.
3+
4+
//@ needs-llvm-components: amdgpu
5+
6+
#![deny(warnings)]
7+
8+
use run_make_support::{cargo, path};
9+
10+
fn main() {
11+
let target_dir = path("target");
12+
13+
cargo()
14+
.args(&[
15+
"build",
16+
"--release",
17+
"--lib",
18+
"--manifest-path",
19+
"Cargo.toml",
20+
"-Zbuild-std=core",
21+
"--target",
22+
"amdgcn-amd-amdhsa",
23+
])
24+
.env("RUSTFLAGS", "-Ctarget-cpu=gfx900")
25+
.env("CARGO_TARGET_DIR", &target_dir)
26+
.run();
27+
}

0 commit comments

Comments
 (0)