diff --git a/lld/MachO/Arch/X86_64.cpp b/lld/MachO/Arch/X86_64.cpp index 5c49664383065..6353cc2410148 100644 --- a/lld/MachO/Arch/X86_64.cpp +++ b/lld/MachO/Arch/X86_64.cpp @@ -82,6 +82,7 @@ uint64_t X86_64::getImplicitAddend(MemoryBufferRef mb, const section_64 &sec, case X86_64_RELOC_SIGNED_2: case X86_64_RELOC_SIGNED_4: case X86_64_RELOC_GOT_LOAD: + case X86_64_RELOC_GOT: if (!rel.r_pcrel) fatal(getErrorLocation(mb, sec, rel) + ": relocations of type " + std::to_string(rel.r_type) + " must be pcrel"); @@ -120,6 +121,7 @@ void X86_64::relocateOne(uint8_t *loc, const Reloc &r, uint64_t val) const { case X86_64_RELOC_SIGNED_2: case X86_64_RELOC_SIGNED_4: case X86_64_RELOC_GOT_LOAD: + case X86_64_RELOC_GOT: // These types are only used for pc-relative relocations, so offset by 4 // since the RIP has advanced by 4 at this point. This is only valid when // r_length = 2, which is enforced by validateLength(). @@ -209,13 +211,13 @@ void X86_64::writeStubHelperEntry(uint8_t *buf, const DylibSymbol &sym, void X86_64::prepareDylibSymbolRelocation(DylibSymbol &sym, uint8_t type) { switch (type) { case X86_64_RELOC_GOT_LOAD: + // TODO: implement mov -> lea relaxation for non-dynamic symbols + case X86_64_RELOC_GOT: in.got->addEntry(sym); break; case X86_64_RELOC_BRANCH: in.stubs->addEntry(sym); break; - case X86_64_RELOC_GOT: - fatal("TODO: Unhandled dylib symbol relocation X86_64_RELOC_GOT"); default: llvm_unreachable("Unexpected dylib relocation type"); } @@ -224,11 +226,10 @@ void X86_64::prepareDylibSymbolRelocation(DylibSymbol &sym, uint8_t type) { uint64_t X86_64::getDylibSymbolVA(const DylibSymbol &sym, uint8_t type) const { switch (type) { case X86_64_RELOC_GOT_LOAD: + case X86_64_RELOC_GOT: return in.got->addr + sym.gotIndex * WordSize; case X86_64_RELOC_BRANCH: return in.stubs->addr + sym.stubsIndex * sizeof(stub); - case X86_64_RELOC_GOT: - fatal("TODO: Unhandled dylib symbol relocation X86_64_RELOC_GOT"); default: llvm_unreachable("Unexpected dylib relocation type"); } diff --git a/lld/test/MachO/dylink.s b/lld/test/MachO/dylink.s index e47d9ef8f271a..1909e380fc6ad 100644 --- a/lld/test/MachO/dylink.s +++ b/lld/test/MachO/dylink.s @@ -19,7 +19,7 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/dylink.o # RUN: lld -flavor darwinnew -o %t/dylink -Z -L%t -lhello -lgoodbye %t/dylink.o -# RUN: llvm-objdump --bind -d %t/dylink | FileCheck %s +# RUN: llvm-objdump --bind -d --no-show-raw-insn %t/dylink | FileCheck %s # CHECK: movq [[#%u, HELLO_OFF:]](%rip), %rsi # CHECK-NEXT: [[#%x, HELLO_RIP:]]: @@ -27,8 +27,8 @@ # CHECK: movq [[#%u, HELLO_ITS_ME_OFF:]](%rip), %rsi # CHECK-NEXT: [[#%x, HELLO_ITS_ME_RIP:]]: -# CHECK: movq [[#%u, GOODBYE_OFF:]](%rip), %rsi -# CHECK-NEXT: [[#%x, GOODBYE_RIP:]]: +# CHECK: pushq [[#%u, GOODBYE_OFF:]](%rip) +# CHECK-NEXT: [[#%x, GOODBYE_RIP:]]: popq %rsi # CHECK-LABEL: Bind table: # CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, HELLO_RIP + HELLO_OFF]] pointer 0 libhello _hello_world @@ -53,7 +53,8 @@ _main: movl $0x2000004, %eax # write() syscall mov $1, %rdi # stdout - movq _goodbye_world@GOTPCREL(%rip), %rsi + pushq _goodbye_world@GOTPCREL(%rip) + popq %rsi mov $15, %rdx # length of str syscall mov $0, %rax