[PATCH] D57799: Support R_X86_64_PC8 and R_X86_64_PC16.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 5 17:36:17 PST 2019


ruiu created this revision.
ruiu added reviewers: grimar, tmsriram.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.

We found that we need R_X86_64_PC8 and R_X86_64_PC16, so is the patch.
They are defined by the x86-64 ELF ABI standard.


https://reviews.llvm.org/D57799

Files:
  lld/ELF/Arch/X86_64.cpp
  lld/test/ELF/x86-64-pcrel.s


Index: lld/test/ELF/x86-64-pcrel.s
===================================================================
--- /dev/null
+++ lld/test/ELF/x86-64-pcrel.s
@@ -0,0 +1,21 @@
+// REQUIRES: x86
+
+// This is a test for R_X86_64_PC8 and R_X86_64_PC16.
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
+// RUN: echo '.globl foo; foo:' | llvm-mc -filetype=obj -triple=x86_64-pc-linux - -o %t2.o
+// RUN: ld.lld -o %t.exe %t1.o %t2.o
+// RUN: objdump -s %t.exe | FileCheck %s
+
+// CHECK: Contents of section .text:
+// CHECK: 2000cccc cccccccc cccccccc cccccccc
+// CHECK: 20cccccc cccccccc cccccccc cccccccc
+
+.globl _start
+_start:
+
+.word foo - _start
+.fill 14,1,0xcc
+
+.byte foo - _start
+.fill 15,1,0xcc
Index: lld/ELF/Arch/X86_64.cpp
===================================================================
--- lld/ELF/Arch/X86_64.cpp
+++ lld/ELF/Arch/X86_64.cpp
@@ -96,6 +96,8 @@
     return R_SIZE;
   case R_X86_64_PLT32:
     return R_PLT_PC;
+  case R_X86_64_PC8:
+  case R_X86_64_PC16:
   case R_X86_64_PC32:
   case R_X86_64_PC64:
     return R_PC;
@@ -314,10 +316,12 @@
 void X86_64<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
   switch (Type) {
   case R_X86_64_8:
+  case R_X86_64_PC8:
     checkUInt(Loc, Val, 8, Type);
     *Loc = Val;
     break;
   case R_X86_64_16:
+  case R_X86_64_PC16:
     checkUInt(Loc, Val, 16, Type);
     write16le(Loc, Val);
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57799.185456.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190206/663a2176/attachment.bin>


More information about the llvm-commits mailing list