1# RUN: ld64.lld -arch arm64 -r -print_atoms %s -o %t | FileCheck %s 2# RUN: ld64.lld -arch arm64 -r -print_atoms %t -o %t2 | FileCheck %s 3# 4# Test parsing and writing of arm64 data relocations. 5# 6# The first step tests if the supplied mach-o file is parsed into the correct 7# set of references. The second step verifies relocations can be round-tripped 8# by writing to a new .o file, then parsing that file which should result in 9# the same references. 10# 11#_test: 12 13 14--- !mach-o 15arch: arm64 16file-type: MH_OBJECT 17flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] 18sections: 19 - segment: __TEXT 20 section: __text 21 type: S_REGULAR 22 attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] 23 alignment: 4 24 address: 0x0000000000000000 25 content: [ 0xC0, 0x03, 0x5F, 0xD6 ] 26 - segment: __DATA 27 section: __data 28 type: S_REGULAR 29 attributes: [ ] 30 address: 0x0000000000000004 31 content: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 37 0xDC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 38 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 0xC0, 0xFF, 0xFF, 0xFF, 0xBE, 0xFF, 0xFF, 0xFF, 41 0xB0, 0xFF, 0xFF, 0xFF ] 42 relocations: 43 - offset: 0x00000050 44 type: ARM64_RELOC_POINTER_TO_GOT 45 length: 2 46 pc-rel: true 47 extern: true 48 symbol: 2 49 - offset: 0x0000004C 50 type: ARM64_RELOC_SUBTRACTOR 51 length: 2 52 pc-rel: false 53 extern: true 54 symbol: 2 55 - offset: 0x0000004C 56 type: ARM64_RELOC_UNSIGNED 57 length: 2 58 pc-rel: false 59 extern: true 60 symbol: 2 61 - offset: 0x00000048 62 type: ARM64_RELOC_SUBTRACTOR 63 length: 2 64 pc-rel: false 65 extern: true 66 symbol: 2 67 - offset: 0x00000048 68 type: ARM64_RELOC_UNSIGNED 69 length: 2 70 pc-rel: false 71 extern: true 72 symbol: 2 73 - offset: 0x00000040 74 type: ARM64_RELOC_UNSIGNED 75 length: 3 76 pc-rel: false 77 extern: true 78 symbol: 2 79 - offset: 0x00000038 80 type: ARM64_RELOC_UNSIGNED 81 length: 3 82 pc-rel: false 83 extern: false 84 symbol: 2 85 - offset: 0x00000030 86 type: ARM64_RELOC_SUBTRACTOR 87 length: 3 88 pc-rel: false 89 extern: true 90 symbol: 2 91 - offset: 0x00000030 92 type: ARM64_RELOC_UNSIGNED 93 length: 3 94 pc-rel: false 95 extern: true 96 symbol: 2 97 - offset: 0x00000028 98 type: ARM64_RELOC_SUBTRACTOR 99 length: 3 100 pc-rel: false 101 extern: true 102 symbol: 2 103 - offset: 0x00000028 104 type: ARM64_RELOC_UNSIGNED 105 length: 3 106 pc-rel: false 107 extern: true 108 symbol: 2 109 - offset: 0x00000020 110 type: ARM64_RELOC_SUBTRACTOR 111 length: 3 112 pc-rel: false 113 extern: true 114 symbol: 2 115 - offset: 0x00000020 116 type: ARM64_RELOC_UNSIGNED 117 length: 3 118 pc-rel: false 119 extern: true 120 symbol: 2 121 - offset: 0x00000018 122 type: ARM64_RELOC_POINTER_TO_GOT 123 length: 3 124 pc-rel: false 125 extern: true 126 symbol: 2 127 - offset: 0x00000010 128 type: ARM64_RELOC_UNSIGNED 129 length: 3 130 pc-rel: false 131 extern: true 132 symbol: 2 133 - offset: 0x00000008 134 type: ARM64_RELOC_UNSIGNED 135 length: 3 136 pc-rel: false 137 extern: true 138 symbol: 2 139local-symbols: 140 - name: _v1 141 type: N_SECT 142 sect: 2 143 value: 0x000000000000000C 144global-symbols: 145 - name: _bar 146 type: N_SECT 147 scope: [ N_EXT ] 148 sect: 1 149 value: 0x0000000000000000 150undefined-symbols: 151 - name: _foo 152 type: N_UNDF 153 scope: [ N_EXT ] 154 value: 0x0000000000000000 155page-size: 0x00000000 156... 157 158# CHECK: defined-atoms: 159# CHECK: - ref-name: L000 160# CHECK: type: data 161# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ] 162# CHECK: - name: _v1 163# CHECK: type: data 164# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00, 08, 00, 00, 00, 165# CHECK: 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 166# CHECK: 00, 00, 00, 00, 00, 00, 00, 00, E0, FF, FF, FF, 167# CHECK: FF, FF, FF, FF, DC, FF, FF, FF, FF, FF, FF, FF, 168# CHECK: {{..}}, {{..}}, 00, 00, 00, 00, 00, 00, 04, 00, 00, 00, 169# CHECK: 00, 00, 00, 00, C0, FF, FF, FF, BE, FF, FF, FF, 170# CHECK: {{B0|B8}}, {{..}}, FF, FF ] 171# CHECK: references: 172# CHECK: - kind: pointer64 173# CHECK: offset: 0 174# CHECK: target: _foo 175# CHECK-NOT: addend: 176# CHECK: - kind: pointer64 177# CHECK: offset: 8 178# CHECK: target: _foo 179# CHECK: addend: 8 180# CHECK: - kind: pointer64ToGOT 181# CHECK: offset: 16 182# CHECK: target: _foo 183# CHECK-NOT: addend: 184# CHECK: - kind: delta64 185# CHECK: offset: 24 186# CHECK: target: _foo 187# CHECK: addend: 24 188# CHECK: - kind: delta64 189# CHECK: offset: 32 190# CHECK: target: _foo 191# CHECK-NOT: addend: 192# CHECK: - kind: delta64 193# CHECK: offset: 40 194# CHECK: target: _foo 195# CHECK: addend: 4 196# CHECK: - kind: pointer64 197# CHECK: offset: 48 198# CHECK: target: L000 199# CHECK-NOT: addend: 200# CHECK: - kind: pointer64 201# CHECK: offset: 56 202# CHECK: target: _foo 203# CHECK: addend: 4 204# CHECK: - kind: delta32 205# CHECK: offset: 64 206# CHECK: target: _foo 207# CHECK-NOT: addend: 208# CHECK: - kind: delta32 209# CHECK: offset: 68 210# CHECK: target: _foo 211# CHECK: addend: 2 212# CHECK: - kind: delta32ToGOT 213# CHECK: offset: 72 214# CHECK: target: _foo 215# CHECK-NOT: addend: 216# CHECK: - name: _bar 217# CHECK: scope: global 218# CHECK: content: [ C0, 03, 5F, D6 ] 219# CHECK: alignment: 4 220# CHECK: undefined-atoms: 221# CHECK: - name: _foo 222 223# .subsections_via_symbols 224# .text 225# .globl_foo 226# .align2 227# _foo: 228# ret 229# .data 230#Lanon: 231# .quad 0 232#_v1: 233# .quad _foo 234# .quad _foo + 8 235# .quad _foo@GOT 236# .quad _foo + 24 - . 237# .quad _foo - . 238# .quad _foo + 4 - . 239# .quad Lanon 240# .quad Lanon + 4 241# .long _foo - . 242# .long _foo +2 - . 243# .long _foo@GOT - . 244 245