1// RUN: llvm-mc -triple x86_64-apple-darwin %s -filetype=obj -o - | llvm-readobj -file-headers -s -sd -r -t -macho-segment -macho-dysymtab -macho-indirect-symbols | FileCheck %s
2
3.tdata
4_a$tlv$init:
5	.long 4
6
7
8.tlv
9	.globl _a
10_a:
11	.quad __tlv_bootstrap
12	.quad 0
13	.quad _a$tlv$init
14
15.text
16	.globl _foo
17	.align 4, 0x90
18
19_foo:
20	 movq   _a@TLVP(%rip), %rdi
21	 call	*(%rdi) # returns &a in %rax
22	 ret
23
24// CHECK: File: <stdin>
25// CHECK: Format: Mach-O 64-bit x86-64
26// CHECK: Arch: x86_64
27// CHECK: AddressSize: 64bit
28// CHECK: MachHeader {
29// CHECK:   Magic: Magic64 (0xFEEDFACF)
30// CHECK:   CpuType: X86-64 (0x1000007)
31// CHECK:   CpuSubType: CPU_SUBTYPE_X86_64_ALL (0x3)
32// CHECK:   FileType: Relocatable (0x1)
33// CHECK:   NumOfLoadCommands: 3
34// CHECK:   SizeOfLoadCommands: 416
35// CHECK:   Flags [ (0x0)
36// CHECK:   ]
37// CHECK:   Reserved: 0x0
38// CHECK: }
39// CHECK: Sections [
40// CHECK:   Section {
41// CHECK:     Index: 0
42// CHECK:     Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
43// CHECK:     Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
44// CHECK:     Address: 0x0
45// CHECK:     Size: 0xA
46// CHECK:     Offset: 448
47// CHECK:     Alignment: 4
48// CHECK:     RelocationOffset: 0x1E8
49// CHECK:     RelocationCount: 1
50// CHECK:     Type: 0x0
51// CHECK:     Attributes [ (0x800004)
52// CHECK:       PureInstructions (0x800000)
53// CHECK:       SomeInstructions (0x4)
54// CHECK:     ]
55// CHECK:     Reserved1: 0x0
56// CHECK:     Reserved2: 0x0
57// CHECK:     Reserved3: 0x0
58// CHECK:     SectionData (
59// CHECK:       0000: 488B3D00 000000FF 17C3               |H.=.......|
60// CHECK:     )
61// CHECK:   }
62// CHECK:   Section {
63// CHECK:     Index: 1
64// CHECK:     Name: __thread_data (5F 5F 74 68 72 65 61 64 5F 64 61 74 61 00 00 00)
65// CHECK:     Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
66// CHECK:     Address: 0xA
67// CHECK:     Size: 0x4
68// CHECK:     Offset: 458
69// CHECK:     Alignment: 0
70// CHECK:     RelocationOffset: 0x0
71// CHECK:     RelocationCount: 0
72// CHECK:     Type: 0x11
73// CHECK:     Attributes [ (0x0)
74// CHECK:     ]
75// CHECK:     Reserved1: 0x0
76// CHECK:     Reserved2: 0x0
77// CHECK:     Reserved3: 0x0
78// CHECK:     SectionData (
79// CHECK:       0000: 04000000                             |....|
80// CHECK:     )
81// CHECK:   }
82// CHECK:   Section {
83// CHECK:     Index: 2
84// CHECK:     Name: __thread_vars (5F 5F 74 68 72 65 61 64 5F 76 61 72 73 00 00 00)
85// CHECK:     Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
86// CHECK:     Address: 0xE
87// CHECK:     Size: 0x18
88// CHECK:     Offset: 462
89// CHECK:     Alignment: 0
90// CHECK:     RelocationOffset: 0x1F0
91// CHECK:     RelocationCount: 2
92// CHECK:     Type: 0x13
93// CHECK:     Attributes [ (0x0)
94// CHECK:     ]
95// CHECK:     Reserved1: 0x0
96// CHECK:     Reserved2: 0x0
97// CHECK:     Reserved3: 0x0
98// CHECK:     SectionData (
99// CHECK:       0000: 00000000 00000000 00000000 00000000  |................|
100// CHECK:       0010: 00000000 00000000                    |........|
101// CHECK:     )
102// CHECK:   }
103// CHECK: ]
104// CHECK: Relocations [
105// CHECK:   Section __text {
106// CHECK:     0x3 1 2 1 X86_64_RELOC_TLV 0 _a
107// CHECK:   }
108// CHECK:   Section __thread_vars {
109// CHECK:     0x10 0 3 1 X86_64_RELOC_UNSIGNED 0 _a$tlv$init
110// CHECK:     0x0 0 3 1 X86_64_RELOC_UNSIGNED 0 __tlv_bootstrap
111// CHECK:   }
112// CHECK: ]
113// CHECK: Symbols [
114// CHECK:   Symbol {
115// CHECK:     Name: _a$tlv$init (1)
116// CHECK:     Type: Section (0xE)
117// CHECK:     Section: __thread_data (0x2)
118// CHECK:     RefType: UndefinedNonLazy (0x0)
119// CHECK:     Flags [ (0x0)
120// CHECK:     ]
121// CHECK:     Value: 0xA
122// CHECK:   }
123// CHECK:   Symbol {
124// CHECK:     Name: _a (34)
125// CHECK:     Extern
126// CHECK:     Type: Section (0xE)
127// CHECK:     Section: __thread_vars (0x3)
128// CHECK:     RefType: UndefinedNonLazy (0x0)
129// CHECK:     Flags [ (0x0)
130// CHECK:     ]
131// CHECK:     Value: 0xE
132// CHECK:   }
133// CHECK:   Symbol {
134// CHECK:     Name: _foo (29)
135// CHECK:     Extern
136// CHECK:     Type: Section (0xE)
137// CHECK:     Section: __text (0x1)
138// CHECK:     RefType: UndefinedNonLazy (0x0)
139// CHECK:     Flags [ (0x0)
140// CHECK:     ]
141// CHECK:     Value: 0x0
142// CHECK:   }
143// CHECK:   Symbol {
144// CHECK:     Name: __tlv_bootstrap (13)
145// CHECK:     Extern
146// CHECK:     Type: Undef (0x0)
147// CHECK:     Section:  (0x0)
148// CHECK:     RefType: UndefinedNonLazy (0x0)
149// CHECK:     Flags [ (0x0)
150// CHECK:     ]
151// CHECK:     Value: 0x0
152// CHECK:   }
153// CHECK: ]
154// CHECK: Indirect Symbols {
155// CHECK:   Number: 0
156// CHECK:   Symbols [
157// CHECK:   ]
158// CHECK: }
159// CHECK: Segment {
160// CHECK:   Cmd: LC_SEGMENT_64
161// CHECK:   Name:
162// CHECK:   Size: 312
163// CHECK:   vmaddr: 0x0
164// CHECK:   vmsize: 0x26
165// CHECK:   fileoff: 448
166// CHECK:   filesize: 38
167// CHECK:   maxprot: rwx
168// CHECK:   initprot: rwx
169// CHECK:   nsects: 3
170// CHECK:   flags: 0x0
171// CHECK: }
172// CHECK: Dysymtab {
173// CHECK:   ilocalsym: 0
174// CHECK:   nlocalsym: 1
175// CHECK:   iextdefsym: 1
176// CHECK:   nextdefsym: 2
177// CHECK:   iundefsym: 3
178// CHECK:   nundefsym: 1
179// CHECK:   tocoff: 0
180// CHECK:   ntoc: 0
181// CHECK:   modtaboff: 0
182// CHECK:   nmodtab: 0
183// CHECK:   extrefsymoff: 0
184// CHECK:   nextrefsyms: 0
185// CHECK:   indirectsymoff: 0
186// CHECK:   nindirectsyms: 0
187// CHECK:   extreloff: 0
188// CHECK:   nextrel: 0
189// CHECK:   locreloff: 0
190// CHECK:   nlocrel: 0
191// CHECK: }
192