[PATCH] D71820: [lld][RISCV] Print error when encountering R_RISCV_ALIGN

James Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 15:58:09 PST 2019


jrtc27 created this revision.
jrtc27 added reviewers: ruiu, MaskRay.
Herald added subscribers: llvm-commits, luismarques, apazos, sameer.abuasal, pzheng, s.egerton, lenary, benna, psnobl, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Unlike R_RISCV_RELAX, which is a linker hint, R_RISCV_ALIGN requires the
support of the linker even when ignoring all R_RISCV_RELAX relocations.
This is because the compiler emits as many NOPs as may be required for
the requested alignment, more than may be required pre-relaxation, to
allow for the target becoming more unaligned after relaxing earlier
sequences. This means that the target is often not initially aligned in
the object files, and so the R_RISCV_ALIGN relocations cannot just be
ignored. Since we do not support linker relaxation, we must turn these
into errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71820

Files:
  lld/ELF/Arch/RISCV.cpp
  lld/test/ELF/riscv-reloc-align.s


Index: lld/test/ELF/riscv-reloc-align.s
===================================================================
--- /dev/null
+++ lld/test/ELF/riscv-reloc-align.s
@@ -0,0 +1,12 @@
+# REQUIRES: riscv
+
+# RUN: llvm-mc -filetype=obj -triple=riscv32-unknown-elf -mattr=+relax %s -o %t.o
+# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
+
+# CHECK: relocation R_RISCV_ALIGN requires unimplemented linker relaxation
+
+.global _start
+_start:
+    nop
+    .balign 8
+    nop
Index: lld/ELF/Arch/RISCV.cpp
===================================================================
--- lld/ELF/Arch/RISCV.cpp
+++ lld/ELF/Arch/RISCV.cpp
@@ -227,9 +227,16 @@
   case R_RISCV_TPREL_LO12_S:
     return R_TLS;
   case R_RISCV_RELAX:
-  case R_RISCV_ALIGN:
   case R_RISCV_TPREL_ADD:
     return R_HINT;
+  case R_RISCV_ALIGN:
+    // Not just a hint; always padded to the worst-case number of NOPs, so may
+    // not currently be aligned, and without linker relaxation support we can't
+    // delete NOPs to realign.
+    error(getErrorLocation(loc) +
+          "relocation R_RISCV_ALIGN requires unimplemented linker relaxation"
+          "; recompile with -mno-relax");
+    return R_NONE;
   default:
     return R_ABS;
   }
@@ -420,7 +427,6 @@
     write64le(loc, val - dtpOffset);
     break;
 
-  case R_RISCV_ALIGN:
   case R_RISCV_RELAX:
     return; // Ignored (for now)
   case R_RISCV_NONE:
@@ -430,6 +436,8 @@
   case R_RISCV_RELATIVE:
   case R_RISCV_COPY:
   case R_RISCV_JUMP_SLOT:
+  // Should have already given an error in getRelExpr
+  case R_RISCV_ALIGN:
   // GP-relative relocations are only produced after relaxation, which
   // we don't support for now
   case R_RISCV_GPREL_I:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71820.235080.patch
Type: text/x-patch
Size: 1687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191222/1bedfe4d/attachment-0001.bin>


More information about the llvm-commits mailing list