[PATCH] D63123: [ELF][RISCV] Add R_RISCV_PC_INDIRECT to isRelExpr()

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 00:00:10 PDT 2019


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

So that R_RISCV_PCREL_LO12_[IS] are considered as link-time constants in
-pie mode, otherwise there are bogus errors:

  ld.lld: error: can't create dynamic relocation R_RISCV_PCREL_LO12_I against symbol: .L0  in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D63123

Files:
  ELF/Relocations.cpp
  test/ELF/riscv-pcrel-hilo.s


Index: test/ELF/riscv-pcrel-hilo.s
===================================================================
--- test/ELF/riscv-pcrel-hilo.s
+++ test/ELF/riscv-pcrel-hilo.s
@@ -5,25 +5,29 @@
 
 # RUN: ld.lld %t.rv32.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv32
 # RUN: ld.lld %t.rv64.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv64
-# RUN: llvm-objdump -d %t.rv32 | FileCheck %s
-# RUN: llvm-objdump -d %t.rv64 | FileCheck %s
-# CHECK:      17 05 00 00     auipc   a0, 0
-# CHECK-NEXT: 13 05 c5 00     addi    a0, a0, 12
-# CHECK-NEXT: 23 26 05 00     sw      zero, 12(a0)
-# CHECK:      17 05 00 00     auipc   a0, 0
-# CHECK-NEXT: 13 05 45 ff     addi    a0, a0, -12
-# CHECK-NEXT: 23 2a 05 fe     sw      zero, -12(a0)
+# RUN: llvm-objdump -d --no-show-raw-insn %t.rv32 | FileCheck %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.rv64 | FileCheck %s
+# RUN: ld.lld -pie %t.rv32.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv32
+# RUN: ld.lld -pie %t.rv64.o --defsym foo=_start+12 --defsym bar=_start -o %t.rv64
+# RUN: llvm-objdump -d --no-show-raw-insn %t.rv32 | FileCheck %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.rv64 | FileCheck %s
+# CHECK:      auipc   a0, 0
+# CHECK-NEXT: addi    a0, a0, 12
+# CHECK-NEXT: sw      zero, 12(a0)
+# CHECK:      auipc   a0, 0
+# CHECK-NEXT: addi    a0, a0, -12
+# CHECK-NEXT: sw      zero, -12(a0)
 
 # RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+12-0x80000800 -o %t.rv32.limits
 # RUN: ld.lld %t.rv64.o --defsym foo=_start+0x7ffff7ff --defsym bar=_start+12-0x80000800 -o %t.rv64.limits
-# RUN: llvm-objdump -d %t.rv32.limits | FileCheck --check-prefix=LIMITS %s
-# RUN: llvm-objdump -d %t.rv64.limits | FileCheck --check-prefix=LIMITS %s
-# LIMITS:      17 f5 ff 7f     auipc   a0, 524287
-# LIMITS-NEXT: 13 05 f5 7f     addi    a0, a0, 2047
-# LIMITS-NEXT: a3 2f 05 7e     sw      zero, 2047(a0)
-# LIMITS:      17 05 00 80     auipc   a0, 524288
-# LIMITS-NEXT: 13 05 05 80     addi    a0, a0, -2048
-# LIMITS-NEXT: 23 20 05 80     sw      zero, -2048(a0)
+# RUN: llvm-objdump -d --no-show-raw-insn %t.rv32.limits | FileCheck --check-prefix=LIMITS %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.rv64.limits | FileCheck --check-prefix=LIMITS %s
+# LIMITS:      auipc   a0, 524287
+# LIMITS-NEXT: addi    a0, a0, 2047
+# LIMITS-NEXT: sw      zero, 2047(a0)
+# LIMITS:      auipc   a0, 524288
+# LIMITS-NEXT: addi    a0, a0, -2048
+# LIMITS-NEXT: sw      zero, -2048(a0)
 
 # RUN: ld.lld %t.rv32.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+12-0x80000801 -o %t
 # RUN: not ld.lld %t.rv64.o --defsym foo=_start+0x7ffff800 --defsym bar=_start+12-0x80000801 -o %t 2>&1 | FileCheck --check-prefix=ERROR %s
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -380,7 +380,8 @@
 // file (PC, or GOT for example).
 static bool isRelExpr(RelExpr Expr) {
   return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC64_CALL,
-               R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC, R_RELAX_GOT_PC>(Expr);
+               R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC, R_RELAX_GOT_PC,
+               R_RISCV_PC_INDIRECT>(Expr);
 }
 
 // Returns true if a given relocation can be computed at link-time.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63123.203982.patch
Type: text/x-patch
Size: 3286 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190611/db4849c8/attachment.bin>


More information about the llvm-commits mailing list