[PATCH] D63259: [ELF][RISCV] Allow R_RISCV_ADD in relocateNonAlloc()

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 06:14:35 PDT 2019


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

gcc may generate .debug_info/.debug_aranges/.debug_line/etc that are
relocated by R_RISCV_ADD*/R_RISCV_SUB* pairs.
Allow R_RISCV_ADD in non-SHF_ALLOC section to fix link errors like:

  ld.lld: error: print.c:(.debug_frame+0x60): has non-ABS relocation R_RISCV_ADD64 against symbol '.L0 '


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D63259

Files:
  ELF/InputSection.cpp
  test/ELF/riscv-reloc-add.s


Index: test/ELF/riscv-reloc-add.s
===================================================================
--- test/ELF/riscv-reloc-add.s
+++ test/ELF/riscv-reloc-add.s
@@ -24,3 +24,9 @@
 .word .L1 - .L0
 .half .L1 - .L0
 .byte .L1 - .L0
+
+## Debug section may use R_RISCV_ADD64/R_RISCV_SUB64 pairs to measure lengths
+## of code ranges (e.g. DW_AT_high_pc). Check we allow R_RISCV_ADD*/R_RISCV_SUB*
+## in such non-SHF_ALLOC sections in -pie/-shared mode.
+.section .debug_info
+.quad .L1 - .L0
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -835,7 +835,7 @@
     if (Expr == R_NONE)
       continue;
 
-    if (Expr != R_ABS && Expr != R_DTPREL) {
+    if (Expr != R_ABS && Expr != R_DTPREL && Expr != R_RISCV_ADD) {
       std::string Msg = getLocation<ELFT>(Offset) +
                         ": has non-ABS relocation " + toString(Type) +
                         " against symbol '" + toString(Sym) + "'";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63259.204508.patch
Type: text/x-patch
Size: 1010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190613/7745ad83/attachment-0001.bin>


More information about the llvm-commits mailing list