[lld] e82c5e1 - [lld-macho] Support X86_64_RELOC_BRANCH
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 15:52:38 PDT 2020
Author: Jez Ng
Date: 2020-04-29T15:45:01-07:00
New Revision: e82c5e17b58fdbb096fa408092d7629b2b6e26f9
URL: https://github.com/llvm/llvm-project/commit/e82c5e17b58fdbb096fa408092d7629b2b6e26f9
DIFF: https://github.com/llvm/llvm-project/commit/e82c5e17b58fdbb096fa408092d7629b2b6e26f9.diff
LOG: [lld-macho] Support X86_64_RELOC_BRANCH
Relatively straightforward diff, to set the stage for calling functions
in dylibs.
Differential Revision: https://reviews.llvm.org/D78269
Added:
Modified:
lld/MachO/Arch/X86_64.cpp
lld/test/MachO/relocations.s
Removed:
################################################################################
diff --git a/lld/MachO/Arch/X86_64.cpp b/lld/MachO/Arch/X86_64.cpp
index 39dd644d5d1c..2fcfab5df28c 100644
--- a/lld/MachO/Arch/X86_64.cpp
+++ b/lld/MachO/Arch/X86_64.cpp
@@ -31,6 +31,7 @@ X86_64::X86_64() {
uint64_t X86_64::getImplicitAddend(const uint8_t *loc, uint8_t type) const {
switch (type) {
+ case X86_64_RELOC_BRANCH:
case X86_64_RELOC_SIGNED:
case X86_64_RELOC_GOT_LOAD:
return read32le(loc);
@@ -42,6 +43,7 @@ uint64_t X86_64::getImplicitAddend(const uint8_t *loc, uint8_t type) const {
void X86_64::relocateOne(uint8_t *loc, uint8_t type, uint64_t val) const {
switch (type) {
+ case X86_64_RELOC_BRANCH:
case X86_64_RELOC_SIGNED:
case X86_64_RELOC_GOT_LOAD:
// These types are only used for pc-relative relocations, so offset by 4
diff --git a/lld/test/MachO/relocations.s b/lld/test/MachO/relocations.s
index cf38f96d0177..7f41a6c93283 100644
--- a/lld/test/MachO/relocations.s
+++ b/lld/test/MachO/relocations.s
@@ -1,19 +1,34 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
-# RUN: llvm-objdump -d %t | FileCheck %s
+# RUN: llvm-objdump --section-headers --syms -d %t | FileCheck %s
-# CHECK: leaq 17(%rip), %rsi
+# CHECK-LABEL: Sections:
+# CHECK: __cstring {{[0-9a-z]+}} [[#%x, CSTRING_ADDR:]]
+
+# CHECK-LABEL: SYMBOL TABLE:
+# CHECK: [[#%x, F_ADDR:]] {{.*}} _f
+
+# CHECK-LABEL: <_main>:
+## Test X86_64_RELOC_BRANCH
+# CHECK: callq 0x[[#%x, F_ADDR]] <_f>
+## Test X86_64_RELOC_SIGNED
+# CHECK: leaq [[#%u, STR_OFF:]](%rip), %rsi
+# CHECK-NEXT: [[#%x, CSTRING_ADDR - STR_OFF]]
.section __TEXT,__text
-.globl _main
+.globl _main, _f
_main:
+ callq _f
+ mov $0, %rax
+ ret
+
+_f:
movl $0x2000004, %eax # write() syscall
mov $1, %rdi # stdout
leaq str(%rip), %rsi
mov $13, %rdx # length of str
syscall
- mov $0, %rax
ret
.section __TEXT,__cstring
More information about the llvm-commits
mailing list