[PATCH] D97104: [lld-macho] Add test for a variety of arm64 relocations

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 19:11:13 PST 2021


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a subscriber: kristof.beyls.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97104

Files:
  lld/test/MachO/arm64-relocs.s


Index: lld/test/MachO/arm64-relocs.s
===================================================================
--- /dev/null
+++ lld/test/MachO/arm64-relocs.s
@@ -0,0 +1,53 @@
+# REQUIRES: arm
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o
+# RUN: %lld -dylib -arch arm64 -lSystem -o %t %t.o
+# RUN: (llvm-objdump --syms %t; llvm-objdump --macho -d --section=__const %t) | FileCheck %s
+
+# CHECK-LABEL: SYMBOL TABLE:
+# CHECK-DAG:   [[#%x,PTR_1:]] l     O __DATA_CONST,__const _ptr_1
+# CHECK-DAG:   [[#%x,PTR_2:]] l     O __DATA_CONST,__const _ptr_2
+# CHECK-DAG:   [[#%x,BAR:]]   g     F __TEXT,__text _bar
+# CHECK-DAG:   [[#%x,BAZ:]]   g     O __DATA,__data _baz
+
+# CHECK-LABEL: _foo:
+# CHECK-NEXT:  bl	0x[[#BAR+120]]
+# CHECK-NEXT:  adrp	x2, [[#]] ; 0x[[#BAZ+4096-128]]
+# CHECK-NEXT:  ldr	x2, [x2, #128]
+# CHECK-NEXT:  ret
+
+# CHECK-LABEL: Contents of (__DATA_CONST,__const) section
+# CHECK:       [[#PTR_1]]	{{0*}}[[#BAZ]] 00000000 00000000 00000000
+# CHECK:       [[#PTR_2]]	{{0*}}[[#BAZ]] 00000000 00000000 00000000
+
+.text
+.globl _foo, _bar, _baz
+.p2align 2
+_foo:
+  ## Generates ARM64_RELOC_BRANCH26 and ARM64_RELOC_ADDEND
+  bl _bar + 123
+  ## Generates ARM64_RELOC_PAGE21 and ADDEND
+  adrp x2, _baz at PAGE + 4097
+  ## Generates ARM64_RELOC_PAGEOFF12
+  ldr x2, [x2, _baz at PAGEOFF]
+  ret
+
+.p2align 2
+_bar:
+  ret
+
+.data
+.space 128
+_baz:
+.space 1
+
+.section __DATA_CONST,__const
+## These generate ARM64_RELOC_UNSIGNED symbol relocations
+## XXX: how to generate UNSIGNED section relocations?
+_ptr_1:
+  .quad _baz
+  .space 8
+_ptr_2:
+  .quad _baz
+  .space 8
+
+.subsections_via_symbols


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97104.325139.patch
Type: text/x-patch
Size: 1639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210220/d47cb82b/attachment.bin>


More information about the llvm-commits mailing list