Skip to content

Commit 5af6385

Browse files
authored
Rollup merge of #109860 - zyedidia:riscv-relax, r=petrochenkov
Add support for RISC-V relax target feature This adds `relax` as an allowed RISC-V target feature. The relax feature in LLVM enables [linker relaxation](https://www.sifive.com/blog/all-aboard-part-3-linker-relaxation-in-riscv-toolchain), an optimization specific to RISC-V that allows global variable accesses to be resolved by the linker by using the global pointer (`gp`) register (rather than constructing the addresses from scratch for each access). Enabling `relax` will cause LLVM to emit relocations in the object file that support this. The feature can be enabled in rustc with `-C target-feature=+relax`. Currently this feature is disabled by default, but maybe it should be enabled by default since it is an easy performance improvement (but requires the `gp` register to be set up properly). GCC/Clang enable this feature by default (for both hosted/bare-metal targets), and include the `-mno-relax` flag to disable it (see [here](https://github.com/llvm/llvm-project/blob/466d554dcab39c3d42fe0c5b588b795e0e4b9d0d/clang/lib/Driver/ToolChains/Arch/RISCV.cpp#L145) for the code that enables it in Clang). I think it would make sense to enable by default, at least for all hosted targets since the `gp` register should be automatically set up by the runtime. For bare-metal targets, `gp` must be set up manually, so it is probably best to leave off by default to avoid breaking existing applications that do not set up `gp`. Leaving it disabled by default for all targets is also reasonable though. Let me know your thoughts. Thanks! Fixes #109426.
2 parents a69cc45 + 48be303 commit 5af6385

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

compiler/rustc_codegen_ssa/src/target_features.rs

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
251251
("e", Some(sym::riscv_target_feature)),
252252
("f", Some(sym::riscv_target_feature)),
253253
("m", Some(sym::riscv_target_feature)),
254+
("relax", Some(sym::riscv_target_feature)),
254255
("v", Some(sym::riscv_target_feature)),
255256
("zba", Some(sym::riscv_target_feature)),
256257
("zbb", Some(sym::riscv_target_feature)),

0 commit comments

Comments
 (0)