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(location) = + result | + (uint64_t) * reinterpret_cast(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(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 +...