[PATCH] D79311: [lld-macho] Support X86_64_RELOC_SIGNED_{1,2,4}
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 21:44:28 PDT 2020
MaskRay created this revision.
MaskRay added reviewers: int3, Ktwu, smeenai, alexshap, christylee, ruiu, pcc, gkm.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`X86_64_RELOC_SIGNED_{1,2,4}` are like X86_64_RELOC_SIGNED, but with the
implicit addend fixed to 1, 2, and 4, respectively.
See the comment in `lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp RecordX86_64Relocation`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79311
Files:
lld/MachO/Arch/X86_64.cpp
lld/test/MachO/x86-64-reloc-signed.s
Index: lld/test/MachO/x86-64-reloc-signed.s
===================================================================
--- /dev/null
+++ lld/test/MachO/x86-64-reloc-signed.s
@@ -0,0 +1,27 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
+# RUN: lld -flavor darwinnew -o %t %t.o
+
+.section __TEXT,__text
+.globl _main
+_main:
+ movl $0x434241, _s(%rip) # X86_64_RELOC_SIGNED4
+ call _f
+ movl $0x44, _s+2(%rip) # X86_64_RELOC_SIGNED2
+ call _f
+ movb $0x45, _s(%rip) # X86_64_RELOC_SIGNED1
+ call _f
+ xor %rax, %rax
+ ret
+
+_f:
+ movl $0x2000004, %eax # write() syscall
+ mov $1, %rdi # stdout
+ leaq _s(%rip), %rsi
+ mov $3, %rdx # length
+ syscall
+ ret
+
+.section __DATA,__data
+_s:
+ .space 5
Index: lld/MachO/Arch/X86_64.cpp
===================================================================
--- lld/MachO/Arch/X86_64.cpp
+++ lld/MachO/Arch/X86_64.cpp
@@ -33,6 +33,9 @@
switch (type) {
case X86_64_RELOC_BRANCH:
case X86_64_RELOC_SIGNED:
+ case X86_64_RELOC_SIGNED_1:
+ case X86_64_RELOC_SIGNED_2:
+ case X86_64_RELOC_SIGNED_4:
case X86_64_RELOC_GOT_LOAD:
return read32le(loc);
default:
@@ -45,6 +48,9 @@
switch (type) {
case X86_64_RELOC_BRANCH:
case X86_64_RELOC_SIGNED:
+ case X86_64_RELOC_SIGNED_1:
+ case X86_64_RELOC_SIGNED_2:
+ case X86_64_RELOC_SIGNED_4:
case X86_64_RELOC_GOT_LOAD:
// These types are only used for pc-relative relocations, so offset by 4
// since the RIP has advanced by 4 at this point.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79311.261737.patch
Type: text/x-patch
Size: 1528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200504/5e287ef1/attachment.bin>
More information about the llvm-commits
mailing list