[PATCH] D63183: [ELF][RISCV] Treat R_RISCV_{ADD,SET,SUB}* as link-time constants

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 00:50:02 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL363128: [ELF][RISCV] Treat R_RISCV_{ADD,SET,SUB}* as link-time constants (authored by MaskRay, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63183?vs=204218&id=204225#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63183

Files:
  lld/trunk/ELF/Arch/RISCV.cpp
  lld/trunk/ELF/InputSection.cpp
  lld/trunk/ELF/Relocations.cpp
  lld/trunk/ELF/Relocations.h
  lld/trunk/test/ELF/riscv-reloc-add.s


Index: lld/trunk/ELF/Arch/RISCV.cpp
===================================================================
--- lld/trunk/ELF/Arch/RISCV.cpp
+++ lld/trunk/ELF/Arch/RISCV.cpp
@@ -62,6 +62,20 @@
 RelExpr RISCV::getRelExpr(const RelType Type, const Symbol &S,
                           const uint8_t *Loc) const {
   switch (Type) {
+  case R_RISCV_ADD8:
+  case R_RISCV_ADD16:
+  case R_RISCV_ADD32:
+  case R_RISCV_ADD64:
+  case R_RISCV_SET6:
+  case R_RISCV_SET8:
+  case R_RISCV_SET16:
+  case R_RISCV_SET32:
+  case R_RISCV_SUB6:
+  case R_RISCV_SUB8:
+  case R_RISCV_SUB16:
+  case R_RISCV_SUB32:
+  case R_RISCV_SUB64:
+    return R_RISCV_ADD;
   case R_RISCV_JAL:
   case R_RISCV_BRANCH:
   case R_RISCV_CALL:
Index: lld/trunk/ELF/InputSection.cpp
===================================================================
--- lld/trunk/ELF/InputSection.cpp
+++ lld/trunk/ELF/InputSection.cpp
@@ -632,6 +632,7 @@
   case R_DTPREL:
   case R_RELAX_TLS_LD_TO_LE_ABS:
   case R_RELAX_GOT_PC_NOPIC:
+  case R_RISCV_ADD:
     return Sym.getVA(A);
   case R_ADDEND:
     return A;
Index: lld/trunk/ELF/Relocations.cpp
===================================================================
--- lld/trunk/ELF/Relocations.cpp
+++ lld/trunk/ELF/Relocations.cpp
@@ -401,8 +401,9 @@
             R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC, R_MIPS_TLSGD,
             R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC, R_GOTPLTONLY_PC,
             R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC, R_PPC32_PLTREL,
-            R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, R_TLSDESC_CALL, R_TLSDESC_PC,
-            R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT, R_TLSIE_HINT>(E))
+            R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, R_RISCV_ADD, R_TLSDESC_CALL,
+            R_TLSDESC_PC, R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT,
+            R_TLSIE_HINT>(E))
     return true;
 
   // These never do, except if the entire file is position dependent or if
Index: lld/trunk/ELF/Relocations.h
===================================================================
--- lld/trunk/ELF/Relocations.h
+++ lld/trunk/ELF/Relocations.h
@@ -96,6 +96,7 @@
   R_PPC64_CALL_PLT,
   R_PPC64_RELAX_TOC,
   R_PPC64_TOCBASE,
+  R_RISCV_ADD,
   R_RISCV_PC_INDIRECT,
 };
 
Index: lld/trunk/test/ELF/riscv-reloc-add.s
===================================================================
--- lld/trunk/test/ELF/riscv-reloc-add.s
+++ lld/trunk/test/ELF/riscv-reloc-add.s
@@ -0,0 +1,26 @@
+# REQUIRES: riscv
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax %s -o %t.32.o
+# RUN: ld.lld -pie %t.32.o -o %t.32
+# RUN: llvm-readelf -x .rodata %t.32 | FileCheck --check-prefix=HEX %s
+
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax %s -o %t.64.o
+# RUN: ld.lld -shared %t.64.o -o %t.64
+# RUN: llvm-readelf -x .rodata %t.64 | FileCheck --check-prefix=HEX %s
+
+# HEX:      section '.rodata':
+# HEX-NEXT: 0x{{[0-9a-f]+}} 04000000 00000000 04000000 040004
+
+## R_RISCV_ADD* and R_RISCV_SUB* are link-time constants, otherwise they are
+## not allowed in -pie/-shared mode.
+
+.global _start
+_start:
+.L0:
+  ret
+.L1:
+
+.rodata
+.dword .L1 - .L0
+.word .L1 - .L0
+.half .L1 - .L0
+.byte .L1 - .L0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63183.204225.patch
Type: text/x-patch
Size: 3156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190612/42051f52/attachment.bin>


More information about the llvm-commits mailing list