[clang] [RISCV] Enable GP relaxation for Linux (PR #201265)

Pengcheng Wang via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 3 00:09:30 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");
+  }
----------------
wangpc-pp wrote:

I don't know if we can just check if `-static`/`-shared` exists.

https://github.com/llvm/llvm-project/pull/201265


More information about the cfe-commits mailing list