[PATCH] [ELF][X86_64] Handle R_X86_64_PC64 relocation
Davide Italiano
davide at freebsd.org
Sun Feb 22 17:49:48 PST 2015
Hi shankarke,
First of a series of relocation patches.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D7820
Files:
lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
test/elf/X86_64/reloc_r_x86_64_pc64.test
Index: lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
===================================================================
--- lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
+++ lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
@@ -56,6 +56,14 @@
// TODO: Check for overflow.
}
+/// \brief R_X86_64_PC64 - word64: S + A - P
+static void relocPC64(uint8_t *location, uint64_t P, uint64_t S, uint64_t A) {
+ int64_t result = (uint64_t)((S + A) - P);
+ *reinterpret_cast<llvm::support::ulittle64_t *>(location) =
+ result |
+ (uint64_t) * reinterpret_cast<llvm::support::ulittle64_t *>(location);
+}
+
std::error_code X86_64TargetRelocationHandler::applyRelocation(
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
const Reference &ref) const {
@@ -112,6 +120,9 @@
std::memcpy(location - 3, instr, sizeof(instr));
break;
}
+ case R_X86_64_PC64:
+ relocPC64(location, relocVAddress, targetVAddress, ref.addend());
+ break;
case LLD_R_X86_64_GOTRELINDEX: {
const DefinedAtom *target = cast<const DefinedAtom>(ref.target());
for (const Reference *r : *target) {
Index: test/elf/X86_64/reloc_r_x86_64_pc64.test
===================================================================
--- test/elf/X86_64/reloc_r_x86_64_pc64.test
+++ test/elf/X86_64/reloc_r_x86_64_pc64.test
@@ -0,0 +1,61 @@
+# Tests that lld can handle relocations of type R_X86_64_PC64
+#RUN: yaml2obj -format=elf -docnum 1 %s -o %t1.o
+#RUN: lld -flavor gnu -target x86_64 %t1.o --noinhibit-exec -o %t2.out -static
+#RUN: llvm-objdump -s %t2.out | FileCheck %s
+#CHECK: Contents of section .data:
+#CHECK: 401000 0a00
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000004
+ Content: ''
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000008
+ Content: '0000'
+ - Name: .rela.data
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 0x0000000000000008
+ Info: .data
+ Relocations:
+ - Offset: 0x0000000000000000
+ Symbol: foo
+ Type: R_X86_64_PC64
+ Addend: 8
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000004
+ Content: ''
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ - Name: .bss
+ Type: STT_SECTION
+ Section: .bss
+ Global:
+ - Name: bar
+ Type: STT_OBJECT
+ Section: .data
+ Size: 0x0000000000000008
+ - Name: foo
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0x0000000000000002
+ Size: 0x0000000000000002
+...
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7820.20483.patch
Type: text/x-patch
Size: 3364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150223/b75af368/attachment.bin>
More information about the llvm-commits
mailing list