[PATCH] D63273: [ELF][RISCV] Error on R_RISCV_PCREL_LO12_[IS] that point to absolute symbols

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 3 05:41:49 PDT 2019


MaskRay updated this revision to Diff 207768.
MaskRay marked an inline comment as done.
MaskRay added a comment.

Print symbol name


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D63273

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


Index: test/ELF/riscv-pcrel-hilo-error.s
===================================================================
--- /dev/null
+++ test/ELF/riscv-pcrel-hilo-error.s
@@ -0,0 +1,7 @@
+# REQUIRES: riscv
+# RUN: llvm-mc -filetype=obj -triple=riscv64 %s -o %t.o
+# RUN: not ld.lld %t.o --defsym external=0 2>&1 | FileCheck %s
+
+# CHECK: error: R_RISCV_PCREL_LO12 relocation points to an absolute symbol: external
+
+addi sp,sp,%pcrel_lo(external)
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -570,6 +570,11 @@
 // R_RISCV_PCREL_LO12's symbol and addend.
 static Relocation *getRISCVPCRelHi20(const Symbol *Sym, uint64_t Addend) {
   const Defined *D = cast<Defined>(Sym);
+  if (!D->Section) {
+    error("R_RISCV_PCREL_LO12 relocation points to an absolute symbol: " +
+          Sym->getName());
+    return nullptr;
+  }
   InputSection *IS = cast<InputSection>(D->Section);
 
   if (Addend != 0)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63273.207768.patch
Type: text/x-patch
Size: 996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190703/093ffc46/attachment.bin>


More information about the llvm-commits mailing list