[clang] [RISCV] Enable GP relaxation for Linux (PR #201265)
Kito Cheng via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 3 00:38:37 PDT 2026
================
@@ -343,6 +343,16 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("--no-relax");
}
+ // Default-enable LLD's --relax-gp for RISC-V on Linux when LLD is used and
+ // linker relaxation is not disabled by -mno-relax.
+ if (Triple.isRISCV() && Triple.isOSLinux()) {
+ bool IsLLD = false;
+ ToolChain.GetLinkerPath(&IsLLD);
+ if (IsLLD &&
+ Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
+ CmdArgs.push_back("--relax-gp");
+ }
----------------
kito-cheng wrote:
Passing the `gp relax` flag and sending it to `-shared` shouldn't cause any problems, since the linker mainly checks whether the `__global_pointer$` symbol is defined and whether relocation is supported.
So I would incline just pass without checking it's -shared/-static/-fPIE/&$%^$^, that may just complicate the condition here.
https://github.com/llvm/llvm-project/pull/201265
More information about the cfe-commits
mailing list