[PATCH] D80856: [lld-macho] Support X86_64_RELOC_GOT
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 29 21:46:30 PDT 2020
int3 created this revision.
int3 added reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
int3 added a child revision: D80857: [lld-macho] Handle GOT relocations of non-dylib symbols.
As far as I can tell, it's identical to _GOT_LOAD. llvm-mc has the following
comment explaining why _GOT exists:
// x86_64 distinguishes movq foo at GOTPCREL so that the linker can
// rewrite the movq to an leaq at link time if the symbol ends up in
// the same linkage unit.
Depends on D80855 <https://reviews.llvm.org/D80855>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D80856
Files:
lld/MachO/Arch/X86_64.cpp
lld/test/MachO/dylink.s
Index: lld/test/MachO/dylink.s
===================================================================
--- lld/test/MachO/dylink.s
+++ 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 @@
movl $0x2000004, %eax # write() syscall
mov $1, %rdi # stdout
- movq _goodbye_world at GOTPCREL(%rip), %rsi
+ pushq _goodbye_world at GOTPCREL(%rip)
+ popq %rsi
mov $15, %rdx # length of str
syscall
mov $0, %rax
Index: lld/MachO/Arch/X86_64.cpp
===================================================================
--- lld/MachO/Arch/X86_64.cpp
+++ lld/MachO/Arch/X86_64.cpp
@@ -81,6 +81,7 @@
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");
@@ -119,6 +120,7 @@
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.
val -= 4;
@@ -207,13 +209,12 @@
void X86_64::prepareDylibSymbolRelocation(DylibSymbol &sym, uint8_t type) {
switch (type) {
case X86_64_RELOC_GOT_LOAD:
+ 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");
}
@@ -222,11 +223,10 @@
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");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80856.267431.patch
Type: text/x-patch
Size: 2934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200530/6e29cc3c/attachment.bin>
More information about the llvm-commits
mailing list