Fix requires_lto targets needing lto set in cargo#149624
Fix requires_lto targets needing lto set in cargo#149624rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
|
Some changes occurred in src/doc/rustc/src/platform-support cc @Noratrieb |
This comment has been minimized.
This comment has been minimized.
|
Hm, not entirely sure of the implications. |
|
The CI/tidy complain seems like a false-positive, the test uses |
Yes, I probably forgot to extend the tidy exception to |
This comment has been minimized.
This comment has been minimized.
…lathar Skip tidy target-specific check for `run-make-cargo` too I forgot to change this when implementing the run-make fission. Noticed in rust-lang#149624 (comment).
Rollup merge of #150237 - jieyouxu:tidy-run-make-cargo, r=Zalathar Skip tidy target-specific check for `run-make-cargo` too I forgot to change this when implementing the run-make fission. Noticed in #149624 (comment).
|
☔ The latest upstream changes (presumably #150240) made this pull request unmergeable. Please resolve the merge conflicts. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Rebased to fix conflicts with #150237, no other changes |
|
I was too early claiming that it works, I tested some more (compiling amdgpu-rs examples) and it broke some of them (somehow it ignored CARGO_BUILD_RUSTFLAGS for obj_is_bitcode and EmitObj::Bitcode completely or in parts). |
|
What error did you get when emitting raw bitcode files? |
|
Here are the errors I get for two changes I tested. Either of the below changes fails to compile Click to see detailed error$ cd examples/vector_copy
$ CARGO_BUILD_RUSTFLAGS='-Ctarget-cpu=gfx1010 -Ctarget-feature=-xnack-support' cargo +stage1 build --release
Compiling compiler_builtins v0.1.160 (/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/compiler-builtins/compiler-builtins)
Compiling core v0.0.0 (/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
Compiling vector_copy v0.1.0 (/rusttest/amdgpu-rs/examples/vector_copy)
warning: unknown and unstable feature specified for `-Ctarget-feature`: `xnack-support`
|
= note: it is still passed through to the codegen backend, but use of this feature might be unsound and the behavior of this feature can change in the future
= help: consider filing a feature request
error: linking with `rust-lld` failed: exit status: 1
|
= note: "rust-lld" "-flavor" "gnu" "--version-script=/tmp/nix-shell.cewhbS/rustc2xMArM/list" "--no-undefined-version" "<1 object files omitted>" "--as-needed" "-L" "/tmp/nix-shell.cewhbS/rustc2xMArM/raw-dylibs" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-o" "/rusttest/amdgpu-rs/examples/vector_copy/target/amdgcn-amd-amdhsa/release/deps/vector_copy.elf" "--gc-sections" "-shared" "-O1" "--strip-debug"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: rust-lld: error: version script assignment of 'global' to symbol 'kernel.kd' failed: symbol not defined
warning: `vector_copy` (lib) generated 1 warning
error: could not compile `vector_copy` (lib) due to 1 previous error; 1 warning emittedI’m fixing this by removing the Change 1Using The vector_copy example compiles successfully but trying to run fails because it compiled for the wrong target (requested gfx1010 but got gfx700). $ cd examples/vector_copy
$ CARGO_BUILD_RUSTFLAGS='-Ctarget-cpu=gfx1010 -Ctarget-feature=-xnack-support -Clink-arg=--undefined-version -Clink-arg=--no-gc-sections' cargo +stage1 build --release
$ llvm-readelf -a target/amdgcn-amd-amdhsa/release/vector_copy.elf | rg target
amdhsa.target: amdgcn-amd-amdhsa--gfx700The println example fails to compile somewhat similar, apparently xnack flags are not consistent between compiled objects. Click to see detailed error$ cd examples/println
$ CARGO_BUILD_RUSTFLAGS='-Ctarget-cpu=gfx1010 -Ctarget-feature=-xnack-support' cargo +stage1 build --release
Compiling compiler_builtins v0.1.160 (/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/compiler-builtins/compiler-builtins)
Compiling core v0.0.0 (/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
Compiling rustflags v0.1.6
Compiling amdgpu-device-libs-build v0.1.0 (/rusttest/amdgpu-rs/amdgpu-device-libs-build)
Compiling println v0.1.0 (/rusttest/amdgpu-rs/examples/println)
Compiling alloc v0.0.0 (/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/alloc)
Compiling amdgpu-device-libs v0.1.0 (/rusttest/amdgpu-rs/amdgpu-device-libs)
warning: unknown and unstable feature specified for `-Ctarget-feature`: `xnack-support`
|
= note: it is still passed through to the codegen backend, but use of this feature might be unsound and the behavior of this feature can change in the future
= help: consider filing a feature request
warning: `amdgpu-device-libs` (lib) generated 1 warning
error: linking with `rust-lld` failed: exit status: 1
|
= note: "rust-lld" "-flavor" "gnu" "--version-script=/tmp/nix-shell.YJcp1H/rustcRBUJWw/list" "--no-undefined-version" "<2 object files omitted>" "--as-needed" "-Bstatic" "/rusttest/amdgpu-rs/examples/println/target/amdgcn-amd-amdhsa/release/deps/{libamdgpu_device_libs-b3e559c59352d88b,liballoc-cc2fa346781d4ed5,libcore-595a027f1d29f784,libcompiler_builtins-4c3afce4ad3c6e2b}.rlib" "-L" "/tmp/nix-shell.YJcp1H/rustcRBUJWw/raw-dylibs" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-plugin-opt=O3" "-plugin-opt=mcpu=gfx1010" "-o" "/rusttest/amdgpu-rs/examples/println/target/amdgcn-amd-amdhsa/release/deps/println.elf" "--gc-sections" "-shared" "-O1" "--strip-debug" "/nix/store/4srmqmw5y2zff1h41cwz35yq64fmbb63-rocm-device-libs-19.0.0-rocm/amdgcn/bitcode/ockl.bc" "/nix/store/4srmqmw5y2zff1h41cwz35yq64fmbb63-rocm-device-libs-19.0.0-rocm/amdgcn/bitcode/oclc_isa_version_1010.bc" "/nix/store/4srmqmw5y2zff1h41cwz35yq64fmbb63-rocm-device-libs-19.0.0-rocm/amdgcn/bitcode/oclc_abi_version_600.bc" "/nix/store/4srmqmw5y2zff1h41cwz35yq64fmbb63-rocm-device-libs-19.0.0-rocm/amdgcn/bitcode/oclc_wavefrontsize64_off.bc" "/rusttest/amdgpu-rs/amdgpu-device-libs-build/util32.bc" "--undefined-version" "--no-gc-sections"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: rust-lld: warning: /rusttest/amdgpu-rs/examples/println/target/amdgcn-amd-amdhsa/release/deps/libamdgpu_device_libs-b3e559c59352d88b.rlib: archive member 'lib.rmeta' is neither ET_REL nor LLVM bitcode
rust-lld: warning: /rusttest/amdgpu-rs/examples/println/target/amdgcn-amd-amdhsa/release/deps/liballoc-cc2fa346781d4ed5.rlib: archive member 'lib.rmeta' is neither ET_REL nor LLVM bitcode
rust-lld: warning: /rusttest/amdgpu-rs/examples/println/target/amdgcn-amd-amdhsa/release/deps/libcore-595a027f1d29f784.rlib: archive member 'lib.rmeta' is neither ET_REL nor LLVM bitcode
rust-lld: warning: /rusttest/amdgpu-rs/examples/println/target/amdgcn-amd-amdhsa/release/deps/libcompiler_builtins-4c3afce4ad3c6e2b.rlib: archive member 'lib.rmeta' is neither ET_REL nor LLVM bitcode
rust-lld: error: incompatible xnack: /rusttest/amdgpu-rs/examples/println/target/amdgcn-amd-amdhsa/release/deps/println.elf.lto.liballoc-cc2fa346781d4ed5.rlib(alloc-cc2fa346781d4ed5.alloc.11bdb97dbc2d79b2-cgu.5.rcgu.o at 181598).o
warning: `println` (lib) generated 1 warning (1 duplicate)
error: could not compile `println` (lib) due to 1 previous error; 1 warning emittedChange 2Emitting raw bitcode files with The vector_copy example compiles successfully but trying to run fails because it compiled for the wrong target (requested gfx1010 but got gfx700). $ cd examples/vector_copy
$ CARGO_BUILD_RUSTFLAGS='-Ctarget-cpu=gfx1010 -Ctarget-feature=-xnack-support -Clink-arg=--undefined-version -Clink-arg=--no-gc-sections' cargo +stage1 build --release
$ llvm-readelf -a target/amdgcn-amd-amdhsa/release/vector_copy.elf | rg target
amdhsa.target: amdgcn-amd-amdhsa--gfx700examples/println works with this change. Click to see detailed output$ cd examples/println
$ CARGO_BUILD_RUSTFLAGS='-Ctarget-cpu=gfx1010 -Ctarget-feature=-xnack-support' cargo +stage1 build --release
$ llvm-readelf -a target/amdgcn-amd-amdhsa/release/vector_copy.elf | rg target
amdhsa.target: amdgcn-amd-amdhsa--gfx1010
$ ../default-cpu/target/debug/default-cpu target/amdgcn-amd-amdhsa/release/println.elf
# Default output of running the example
PASSED!
Free
Finished |
|
I see.
This kinda makes sense. I'm guessing currently the linker sees the .kd symbol in the object file and links it, while with bitcode only files, the linker doesn't know about the .kd symbol until after LTO is done, which is after determining which symbols to export.
The LTO linker plugin should know the correct target cpu thanks to
The LLVM docs seem to suggest that xnack must be consistent between all object files, which would include the standard library. |
Yeah, there’s an open LLVM issue for that, it’s linked somewhere in the amdgpu tracking issue.
The amdgpu target forces |
|
Friendly ping for review |
|
@bjorn3, is this fix something you could get merged? Would it be worth to have another rust-timer run before? (I see this is currently labelled with perf-regression but that comes from an earlier version of this PR.) |
|
I figured @Mark-Simulacrum would approve given that they are assigned. I strongly doubt the current state will cause a perf regression. @bors r+ |
|
For the future, I don't look at waiting-on-author PRs at all today, so I wouldn't have seen this. I'd recommend updating labels (e.g., |
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#148514 Tracking issue: rust-lang#135024
|
Ups, I didn’t see the label was pointing to me, sorry. Thanks for approving! |
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#148514 Tracking issue: rust-lang#135024
…uwer Rollup of 9 pull requests Successful merges: - #149624 (Fix requires_lto targets needing lto set in cargo) - #152443 (NVPTX: Drop support for old architectures and old ISAs) - #155317 (`std::io::Take`: Clarify & optimize `BorrowedBuf::set_init` usage.) - #155588 (Implement more traits for FRTs) - #155682 (Add boxing suggestions for `impl Trait` return type mismatches) - #155770 (Avoid misleading closure return type note) - #155818 (Convert attribute `FinalizeFn` to fn pointer) - #155829 (rustc_attr_parsing: use a `try {}` in `or_malformed`) - #155835 (couple of `crate_name` cleanups)
Rollup of 12 pull requests Successful merges: - #149624 (Fix requires_lto targets needing lto set in cargo) - #155317 (`std::io::Take`: Clarify & optimize `BorrowedBuf::set_init` usage.) - #155579 (Make Rcs and Arcs use pointer comparison for unsized types) - #155588 (Implement more traits for FRTs) - #155708 (Fix heap overflow in slice::join caused by misbehaving Borrow) - #155778 (Avoid Vec allocation in TyCtxt::mk_place_elem) - #151014 (std: sys: process: uefi: Add program searching) - #155682 (Add boxing suggestions for `impl Trait` return type mismatches) - #155770 (Avoid misleading closure return type note) - #155818 (Convert attribute `FinalizeFn` to fn pointer) - #155829 (rustc_attr_parsing: use a `try {}` in `or_malformed`) - #155835 (couple of `crate_name` cleanups)
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 #148514 Tracking issue: #135024
View all comments
Targets that set
requires_lto = truewere not actually using lto when compiling with cargo by default. They needed an extralto = trueinCargo.tomlto work.Fix this by letting lto take precedence over the
embed_bitcodeflag 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 #148514
Tracking issue: #135024