[lld] r230189 - [ELF][X86_64] R_X86_64_16 relocation support
Shankar Easwaran
shankare at codeaurora.org
Sun Feb 22 15:32:34 PST 2015
Author: shankare
Date: Sun Feb 22 17:32:34 2015
New Revision: 230189
URL: http://llvm.org/viewvc/llvm-project?rev=230189&view=rev
Log:
[ELF][X86_64] R_X86_64_16 relocation support
Added:
lld/trunk/test/elf/X86_64/reloc_r_x86_64_16.test
Modified:
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/X86_64RelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp?rev=230189&r1=230188&r2=230189&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationHandler.cpp Sun Feb 22 17:32:34 2015
@@ -47,6 +47,15 @@ static void reloc32S(uint8_t *location,
// TODO: Make sure that the result sign extends to the 64bit value.
}
+/// \brief R_X86_64_16 - word16: S + A
+static void reloc16(uint8_t *location, uint64_t P, uint64_t S, int64_t A) {
+ uint16_t result = (uint16_t)(S + A);
+ *reinterpret_cast<llvm::support::ulittle16_t *>(location) =
+ result |
+ (uint16_t) * reinterpret_cast<llvm::support::ulittle16_t *>(location);
+ // TODO: Check for overflow.
+}
+
std::error_code X86_64TargetRelocationHandler::applyRelocation(
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
const Reference &ref) const {
@@ -74,6 +83,9 @@ std::error_code X86_64TargetRelocationHa
case R_X86_64_32S:
reloc32S(location, relocVAddress, targetVAddress, ref.addend());
break;
+ case R_X86_64_16:
+ reloc16(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=230189&r1=230188&r2=230189&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/X86_64/X86_64RelocationPass.cpp Sun Feb 22 17:32:34 2015
@@ -111,6 +111,7 @@ template <class Derived> class Relocatio
return;
assert(ref.kindArch() == Reference::KindArch::x86_64);
switch (ref.kindValue()) {
+ case R_X86_64_16:
case R_X86_64_32:
case R_X86_64_32S:
case R_X86_64_64:
Added: lld/trunk/test/elf/X86_64/reloc_r_x86_64_16.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/reloc_r_x86_64_16.test?rev=230189&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/reloc_r_x86_64_16.test (added)
+++ lld/trunk/test/elf/X86_64/reloc_r_x86_64_16.test Sun Feb 22 17:32:34 2015
@@ -0,0 +1,60 @@
+# Tests that lld can handle relocations of type R_X86_64_16
+#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 0210
+---
+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_16
+ - 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