[lld] r231057 - [ELF] Implement R_X86_64_PC16 relocation.
Davide Italiano
davide at freebsd.org
Mon Mar 2 23:38:21 PST 2015
Author: davide
Date: Tue Mar 3 01:38:20 2015
New Revision: 231057
URL: http://llvm.org/viewvc/llvm-project?rev=231057&view=rev
Log:
[ELF] Implement R_X86_64_PC16 relocation.
Yet another chapter in the story. We're getting there, finally.
Note for the future: the tests for relocation have a lot of duplication
and probably can be unified in a single file. Let's reevaluate this once
the support will be complete (hopefully, soon).
Added:
lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc16.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/X86_64/TODO.rst
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/TODO.rst
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/TODO.rst?rev=231057&r1=231056&r2=231057&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/TODO.rst (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/TODO.rst Tue Mar 3 01:38:20 2015
@@ -19,7 +19,6 @@ Trivial Relocs
These are very simple relocation calculations to implement.
See lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp
-* R_X86_64_PC16
* R_X86_64_8
* R_X86_64_PC8
* R_X86_64_SIZE32
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=231057&r1=231056&r2=231057&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp Tue Mar 3 01:38:20 2015
@@ -48,6 +48,13 @@ static void reloc16(uint8_t *location, u
// TODO: Check for overflow.
}
+/// \brief R_X86_64_PC16 - word16: S + A - P
+static void relocPC16(uint8_t *location, uint64_t P, uint64_t S, int64_t A) {
+ uint16_t result = (uint16_t)((S + A) - P);
+ write16le(location, result | read16le(location));
+ // 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);
@@ -84,6 +91,9 @@ std::error_code X86_64TargetRelocationHa
case R_X86_64_16:
reloc16(location, relocVAddress, targetVAddress, ref.addend());
break;
+ case R_X86_64_PC16:
+ relocPC16(location, relocVAddress, targetVAddress, ref.addend());
+ break;
case R_X86_64_TPOFF64:
case R_X86_64_DTPOFF32:
case R_X86_64_TPOFF32: {
Modified: lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp?rev=231057&r1=231056&r2=231057&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp Tue Mar 3 01:38:20 2015
@@ -116,6 +116,7 @@ template <class Derived> class Relocatio
case R_X86_64_32:
case R_X86_64_32S:
case R_X86_64_64:
+ case R_X86_64_PC16:
case R_X86_64_PC32:
case R_X86_64_PC64:
static_cast<Derived *>(this)->handlePlain(ref);
Added: lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc16.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc16.test?rev=231057&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc16.test (added)
+++ lld/trunk/test/elf/X86_64/reloc_r_x86_64_pc16.test Tue Mar 3 01:38:20 2015
@@ -0,0 +1,61 @@
+# Tests that lld can handle relocations of type R_X86_64_PC16
+#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 0700
+---
+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_PC16
+ Addend: 5
+ - 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