[PATCH] D14404: [RuntimeDyld] Add support for R_X86_64_PC8 relocation.

Maksim Panchenko via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 16:06:10 PST 2015


maksfb created this revision.
maksfb added reviewers: lhames, rafaelauler.
maksfb added a subscriber: llvm-commits.

http://reviews.llvm.org/D14404

Files:
  lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
  test/ExecutionEngine/RuntimeDyld/X86/ELF_x64-64_PC8_relocations.s

Index: test/ExecutionEngine/RuntimeDyld/X86/ELF_x64-64_PC8_relocations.s
===================================================================
--- /dev/null
+++ test/ExecutionEngine/RuntimeDyld/X86/ELF_x64-64_PC8_relocations.s
@@ -0,0 +1,26 @@
+# RUN: llvm-mc -triple=x86_64-pc-linux -relocation-model=pic -filetype=obj -o %T/test_ELF_x86-64_PC8.o %s
+# RUN: llvm-rtdyld -triple=x86_64-pc-linux -verify -map-section test_ELF_x86-64_PC8.o,.text.bar=0x10000 -map-section test_ELF_x86-64_PC8.o,.text.baz=0x10040 %T/test_ELF_x86-64_PC8.o
+# RUN: llvm-rtdyld -triple=x86_64-pc-linux -verify -map-section test_ELF_x86-64_PC8.o,.text.baz=0x10000 -map-section test_ELF_x86-64_PC8.o,.text.bar=0x10040 %T/test_ELF_x86-64_PC8.o
+
+# Test that R_X86_64_PC8 relocation works.
+
+  .section .text.bar,"ax"
+	.align	16, 0x90
+	.type	bar, at function
+bar:
+	retq
+.Ltmp1:
+	.size	bar, .Ltmp1-bar
+
+  .section .text.baz,"ax"
+	.align	16, 0x90
+	.type	baz, at function
+baz:
+  movq  %rdi, %rcx
+  jrcxz bar
+	retq
+.Ltmp2:
+	.size	baz, .Ltmp2-baz
+
+
+	.section	".note.GNU-stack","", at progbits
Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
===================================================================
--- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -249,6 +249,14 @@
                  << format("%p\n", Section.Address + Offset));
     break;
   }
+  case ELF::R_X86_64_PC8: {
+    uint64_t FinalAddress = Section.LoadAddress + Offset;
+    int64_t RealOffset = Value + Addend - FinalAddress;
+    assert(isInt<8>(RealOffset));
+    int8_t TruncOffset = (RealOffset & 0xFF);
+    Section.Address[Offset] = TruncOffset;
+    break;
+  }
   case ELF::R_X86_64_PC32: {
     uint64_t FinalAddress = Section.LoadAddress + Offset;
     int64_t RealOffset = Value + Addend - FinalAddress;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14404.39436.patch
Type: text/x-patch
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151106/1a90ee4f/attachment.bin>


More information about the llvm-commits mailing list