[PATCH] D147983: [lld][driver] Add `--relax-gp`/`no-relax-gp` flags for GNU compatibility

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 17:26:23 PDT 2023

paulkirth created this revision.
paulkirth added reviewers: MaskRay, phosek, mcgrathr, peter.smith.
Herald added subscribers: luismarques, s.egerton, PkmX, simoncook, arichardson, emaste.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

GNU LD accepts `--relax-gp/--no-relax-gp` to control GP relaxation.

Since `gp` (`x3`) is being defined as the platform register in the
RISC-V psABI, LLD needs to be able to handle flags that disable gp
relaxation. The use of `gp` as the shadow call stack register is a prime
example of when a compiler aught to set such a flag for the linker, so
that linker relaxation won't conflict with the platform's usage of the

This patch only adds the flag for compatibility, since LLD does not yet
implement GP relaxation, which will not conflict with a platform's usage
of the RISC-V GP register.

  rG LLVM Github Monorepo



Index: lld/test/ELF/ignore-relax-gp.test
--- /dev/null
+++ lld/test/ELF/ignore-relax-gp.test
@@ -0,0 +1,3 @@
+RUN: not ld.lld --relax-gp 2>&1 | FileCheck %s
+RUN: not ld.lld --no-relax-gp 2>&1 | FileCheck %s
+CHECK: no input files
Index: lld/ELF/Options.td
--- lld/ELF/Options.td
+++ lld/ELF/Options.td
@@ -355,6 +355,11 @@
   "Enable target-specific relaxations if supported (default)",
   "Disable target-specific relaxations">;
+// It is likely that we will eventually need to implement these
+defm relax_gp: BB<"relax-gp",
+  "Ignored for compatibility with GNU linkers",
+  "Ignored for compatibility with GNU linkers">;
 defm reproduce:
      "Write tar file containing inputs and command to reproduce link">;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147983.512292.patch
Type: text/x-patch
Size: 876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230411/c5de2a60/attachment-0001.bin>

More information about the llvm-commits mailing list