forked from OSchip/llvm-project
[ELF][X86_64] Handle R_X86_64_PC64 relocation
Differential Revision: D7820 Reviewed by: shankarke, ruiu llvm-svn: 230465
This commit is contained in:
parent
a75db66eee
commit
9793956644
|
@ -56,6 +56,14 @@ static void reloc16(uint8_t *location, uint64_t P, uint64_t S, int64_t A) {
|
||||||
// TODO: Check for overflow.
|
// 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(
|
std::error_code X86_64TargetRelocationHandler::applyRelocation(
|
||||||
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
|
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
|
||||||
const Reference &ref) const {
|
const Reference &ref) const {
|
||||||
|
@ -112,6 +120,9 @@ std::error_code X86_64TargetRelocationHandler::applyRelocation(
|
||||||
std::memcpy(location - 3, instr, sizeof(instr));
|
std::memcpy(location - 3, instr, sizeof(instr));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case R_X86_64_PC64:
|
||||||
|
relocPC64(location, relocVAddress, targetVAddress, ref.addend());
|
||||||
|
break;
|
||||||
case LLD_R_X86_64_GOTRELINDEX: {
|
case LLD_R_X86_64_GOTRELINDEX: {
|
||||||
const DefinedAtom *target = cast<const DefinedAtom>(ref.target());
|
const DefinedAtom *target = cast<const DefinedAtom>(ref.target());
|
||||||
for (const Reference *r : *target) {
|
for (const Reference *r : *target) {
|
||||||
|
|
|
@ -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
|
||||||
|
...
|
Loading…
Reference in New Issue