[PATCH] D143673: [lld][RISCV] Implement GP relaxation for R_RISCV_HI20/R_RISCV_LO12_I/R_RISCV_LO12_S.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 11 16:40:50 PDT 2023


MaskRay added inline comments.


================
Comment at: lld/ELF/Arch/RISCV.cpp:450
+    checkInt(loc, displace, 12, rel);
+    uint32_t insn = read32le(loc);
+    insn = (insn & ~(31 << 15)) | (X_GP << 15);
----------------
`uint32_t insn = (read32le(loc) & ~(31 << 15)) | (X_GP << 15)`


================
Comment at: lld/ELF/Arch/RISCV.cpp:640
+                          Relocation &r, uint32_t &remove) {
+  Defined *gp = ElfSym::riscvGlobalPointer;
+  if (!gp)
----------------
`const Defined *gp = ElfSym::riscvGlobalPointer;`


================
Comment at: lld/ELF/Writer.cpp:1881
+            "__global_pointer$", sec ? sec : Out::elfHeader, 0x800, STV_DEFAULT);
+        // Save the globalPointer for use by GP relaxation if enabled.
+        if (config->relaxGP) {
----------------



================
Comment at: lld/test/ELF/riscv-relax-hi20-lo12-pie.s:1
+# REQUIRES: riscv
+# RUN: rm -rf %t && split-file %s %t && cd %t
----------------
Merge the tests into `riscv-relax-hi20-lo12.s`. If the `-no-pie` test has exercised many cases, the `-pie` case can just check a few lines if you feel duplicating all `-no-pie` CHECK lines looks too verbose.

Also, add a `-shared` test. Note, it's not necessary to test all `riscv{32,64} x {-pie,-shared}` combinations.
`riscv32 -pie` and `riscv64 -shared` may suffice.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143673/new/

https://reviews.llvm.org/D143673



More information about the llvm-commits mailing list