[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 08:41:32 PDT 2019


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365049: [ELF][RISCV] Error on R_RISCV_PCREL_LO12_[IS] that point to absolute symbols (authored by MaskRay, committed by ).

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63273

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


Index: lld/trunk/test/ELF/riscv-pcrel-hilo-error.s
===================================================================
--- lld/trunk/test/ELF/riscv-pcrel-hilo-error.s
+++ lld/trunk/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: lld/trunk/ELF/InputSection.cpp
===================================================================
--- lld/trunk/ELF/InputSection.cpp
+++ lld/trunk/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.207808.patch
Type: text/x-patch
Size: 1080 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190703/998b20a1/attachment.bin>


More information about the llvm-commits mailing list