Repository navigation
RISC-V: enable relax target feature by default - #164378
Conversation
|
Target features are being changed; ensure all ABI effects are being accounted for cc @RalfJung These commits modify compiler targets. |
|
I'm not sure whether it would make sense to enable this in |
|
I would suggest adding a check in |
|
Pinging riscv target maintainers. |
|
The |
|
Typo: Missing comma in RISC-V target features File: compiler/rustc_target/src/spec/targets/riscv64gc_unknown_redox.rs There seems to be a missing comma in the feature string: base.features = "+m,+a,+f,+d,+c+relax".into(); It should be: base.features = "+m,+a,+f,+d,+c,+relax".into(); Otherwise, +c+relax will be parsed as a single invalid feature instead of two separate features. |
a21143c to
3a08377
Compare
|
Target consistency checks are being changed cc @RalfJung |
This comment has been minimized.
This comment has been minimized.
|
@rustbot reroll |
|
@rustbot reroll |
| self.features.contains("+relax"), | ||
| "The `+relax` feature should be enabled for RISC-V targets" | ||
| ); | ||
| } |
There was a problem hiding this comment.
There are a bunch of C projects that use -mno-relax for riscv, so I'm a bit hesitant to actually refuse disabling linker relaxation. And besides the consistency check is used for actually nonsensical or invalid combinations of flags, not for something that is just an optimization.
There was a problem hiding this comment.
Do you think there are any built-in targets where we would want to have it disabled? I went with this PR instead of #163890 as that one was more contentious, but if yes, I would eventually want to return to that PR. If not, as @RalfJung suggested above, anyone needing relaxation off could make a custom target spec where the feature is disabled.
There was a problem hiding this comment.
Do these consistency checks no apply to custom targets?
There was a problem hiding this comment.
Not all of them, but this one in particular checks that the target kind is TargetKind::Builtin rather than TargetKind::Json.
There was a problem hiding this comment.
Yeah the point of this particular check is just to govern our built-in targets. We do hold those to a higher standard than custom targets in some cases, basically as an easy way to consistently enforce a policy for all our own targets.
|
@rustbot r? bjorn3 |
|
( |
3a08377 to
f99532a
Compare
|
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. |
|
Unlike @bors r+ |
…bjorn3 RISC-V: enable relax target feature by default This PR adds `+relax` to the default target features for all RISC-V targets to enable emission of linker relaxations by LLVM. It does not enable "global pointer" relaxations; see rust-lang#163890 for more context and discussion on how those relaxations work. `relax` is then marked as an internal-only target feature so that it can't be modified with `-Ctarget-feature=±relax` or used with `#[cfg(target_feature = "relax")]`, `#[target_feature = "relax"]`, none of which make sense. When building wild for `riscv64gc-unknown-linux-gnu`, it reduces binary size by 1.2%. When building my work project for `riscv32i-unknown-none-elf`, it reduces binary size by 1.9%, or by 2.1% if global pointer relaxations are enabled with `--relax-gp`. This is an alternative to rust-lang#163890 which will supersede that one if merged. cc @RalfJung, @romancardenas, @bjorn3 as participants on the previous thread. r? compiler
…uwer Rollup of 5 pull requests Successful merges: - #157721 (compiletest: Add testing for lint machinery at runtime) - #153746 (rustdoc: add emoji icons for unstable and deprecated to search results) - #164378 (RISC-V: enable relax target feature by default) - #166241 (view-types: better documentation for View variant) - #166246 (Add rustdoc-ui tests for (some) malformed doc attributes)
Rollup merge of #164378 - TechnoPorg:riscv-default-relax, r=bjorn3 RISC-V: enable relax target feature by default This PR adds `+relax` to the default target features for all RISC-V targets to enable emission of linker relaxations by LLVM. It does not enable "global pointer" relaxations; see #163890 for more context and discussion on how those relaxations work. `relax` is then marked as an internal-only target feature so that it can't be modified with `-Ctarget-feature=±relax` or used with `#[cfg(target_feature = "relax")]`, `#[target_feature = "relax"]`, none of which make sense. When building wild for `riscv64gc-unknown-linux-gnu`, it reduces binary size by 1.2%. When building my work project for `riscv32i-unknown-none-elf`, it reduces binary size by 1.9%, or by 2.1% if global pointer relaxations are enabled with `--relax-gp`. This is an alternative to #163890 which will supersede that one if merged. cc @RalfJung, @romancardenas, @bjorn3 as participants on the previous thread. r? compiler
…uwer Rollup of 5 pull requests Successful merges: - rust-lang/rust#157721 (compiletest: Add testing for lint machinery at runtime) - rust-lang/rust#153746 (rustdoc: add emoji icons for unstable and deprecated to search results) - rust-lang/rust#164378 (RISC-V: enable relax target feature by default) - rust-lang/rust#166241 (view-types: better documentation for View variant) - rust-lang/rust#166246 (Add rustdoc-ui tests for (some) malformed doc attributes)
View all comments
This PR adds
+relaxto the default target features for all RISC-V targets to enable emission of linker relaxations by LLVM. It does not enable "global pointer" relaxations; see #163890 for more context and discussion on how those relaxations work.relaxis then marked as an internal-only target feature so that it can't be modified with-Ctarget-feature=±relaxor used with#[cfg(target_feature = "relax")],#[target_feature = "relax"], none of which make sense.When building wild for
riscv64gc-unknown-linux-gnu, it reduces binary size by 1.2%. When building my work project forriscv32i-unknown-none-elf, it reduces binary size by 1.9%, or by 2.1% if global pointer relaxations are enabled with--relax-gp.This is an alternative to #163890 which will supersede that one if merged.
cc @RalfJung, @romancardenas, @bjorn3 as participants on the previous thread.
r? compiler