[lld] r292330 - ELF: Add support for relocation type R_X86_64_8.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 18:20:53 PST 2017


Author: pcc
Date: Tue Jan 17 20:20:53 2017
New Revision: 292330

URL: http://llvm.org/viewvc/llvm-project?rev=292330&view=rev
Log:
ELF: Add support for relocation type R_X86_64_8.

Although this relocation type is not part of the x86-64 psABI, I intend to
use it internally as part of the ThinLTO implementation.

Differential Revision: https://reviews.llvm.org/D28841

Added:
    lld/trunk/test/ELF/Inputs/x86-64-reloc-8-error.s
    lld/trunk/test/ELF/Inputs/x86-64-reloc-8.s
    lld/trunk/test/ELF/x86-64-reloc-8.s
Modified:
    lld/trunk/ELF/Target.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=292330&r1=292329&r2=292330&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Jan 17 20:20:53 2017
@@ -631,6 +631,7 @@ template <class ELFT>
 RelExpr X86_64TargetInfo<ELFT>::getRelExpr(uint32_t Type,
                                            const SymbolBody &S) const {
   switch (Type) {
+  case R_X86_64_8:
   case R_X86_64_32:
   case R_X86_64_32S:
   case R_X86_64_64:
@@ -857,6 +858,10 @@ template <class ELFT>
 void X86_64TargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type,
                                          uint64_t Val) const {
   switch (Type) {
+  case R_X86_64_8:
+    checkUInt<8>(Loc, Val, Type);
+    *Loc = Val;
+    break;
   case R_X86_64_32:
     checkUInt<32>(Loc, Val, Type);
     write32le(Loc, Val);

Added: lld/trunk/test/ELF/Inputs/x86-64-reloc-8-error.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/x86-64-reloc-8-error.s?rev=292330&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/x86-64-reloc-8-error.s (added)
+++ lld/trunk/test/ELF/Inputs/x86-64-reloc-8-error.s Tue Jan 17 20:20:53 2017
@@ -0,0 +1,3 @@
+.globl foo
+.hidden foo
+foo = 256

Added: lld/trunk/test/ELF/Inputs/x86-64-reloc-8.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/x86-64-reloc-8.s?rev=292330&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/x86-64-reloc-8.s (added)
+++ lld/trunk/test/ELF/Inputs/x86-64-reloc-8.s Tue Jan 17 20:20:53 2017
@@ -0,0 +1,3 @@
+.globl foo
+.hidden foo
+foo = 0x42

Added: lld/trunk/test/ELF/x86-64-reloc-8.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-8.s?rev=292330&view=auto
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-8.s (added)
+++ lld/trunk/test/ELF/x86-64-reloc-8.s Tue Jan 17 20:20:53 2017
@@ -0,0 +1,14 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-8.s -o %t1
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/x86-64-reloc-8-error.s -o %t2
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+// RUN: ld.lld -shared %t %t1 -o %t3
+
+// CHECK:      Contents of section .text:
+// CHECK-NEXT:   200000 42
+
+// RUN: not ld.lld -shared %t %t2 -o %t4 2>&1 | FileCheck --check-prefix=ERROR %s
+// ERROR: relocation R_X86_64_8 out of range
+
+.byte foo




More information about the llvm-commits mailing list