[lld] r230465 - [ELF][X86_64] Handle R_X86_64_PC64 relocation
Davide Italiano
davide at freebsd.org
Tue Feb 24 21:56:06 PST 2015
Author: davide
Date: Tue Feb 24 23:56:05 2015
New Revision: 230465
URL: http://llvm.org/viewvc/llvm-project?rev=230465&view=rev
Log:
[ELF][X86_64] Handle R_X86_64_PC64 relocation
Differential Revision: D7820
Reviewed by: shankarke, ruiu
Added:
lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc64.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp?rev=230465&r1=230464&r2=230465&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp Tue Feb 24 23:56:05 2015
@@ -56,6 +56,14 @@ static void reloc16(uint8_t *location, u
// 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::error_code X86_64TargetRelocationHa
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) {
Added: lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc64.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc64.test?rev=230465&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc64.test (added)
+++ lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc64.test Tue Feb 24 23:56:05 2015
@@ -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
+...
More information about the llvm-commits
mailing list