1// RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - | elf-dump | FileCheck  %s
2
3// Test that we produce the correct relocation types and that the relocations
4// correctly point to the section or the symbol.
5
6// CHECK:      # Relocation 0
7// CHECK-NEXT: (('r_offset', 0x00000002)
8// CHECK-NEXT:  ('r_sym', 0x000001)
9// CHECK-NEXT:  ('r_type', 0x09)
10// CHECK-NEXT: ),
11// CHECK-NEXT:  # Relocation 1
12// CHECK-NEXT: (('r_offset',
13// CHECK-NEXT:  ('r_sym',
14// CHECK-NEXT:  ('r_type', 0x04)
15// CHECK-NEXT: ),
16// CHECK-NEXT:  # Relocation 2
17// CHECK-NEXT: (('r_offset',
18// CHECK-NEXT:  ('r_sym',
19// CHECK-NEXT:  ('r_type', 0x0a)
20// CHECK-NEXT: ),
21
22// Relocation 3 (bar3@GOTOFF) is done with symbol 7 (bss)
23// CHECK-NEXT:  # Relocation 3
24// CHECK-NEXT: (('r_offset',
25// CHECK-NEXT:  ('r_sym', 0x000007
26// CHECK-NEXT:  ('r_type',
27// CHECK-NEXT: ),
28
29// Relocation 4 (bar2@GOT) is of type R_386_GOT32
30// CHECK-NEXT:  # Relocation 4
31// CHECK-NEXT: (('r_offset',
32// CHECK-NEXT:  ('r_sym',
33// CHECK-NEXT:  ('r_type', 0x03
34// CHECK-NEXT: ),
35
36// Relocation 5 (foo@TLSGD) is of type R_386_TLS_GD
37// CHECK-NEXT: # Relocation 5
38// CHECK-NEXT: (('r_offset', 0x00000020)
39// CHECK-NEXT:  ('r_sym', 0x00000d)
40// CHECK-NEXT:  ('r_type', 0x12)
41// CHECK-NEXT: ),
42
43// Relocation 6 ($foo@TPOFF) is of type R_386_TLS_LE_32
44// CHECK-NEXT: # Relocation 6
45// CHECK-NEXT: (('r_offset', 0x00000025)
46// CHECK-NEXT:  ('r_sym', 0x00000d)
47// CHECK-NEXT:  ('r_type', 0x22)
48// CHECK-NEXT: ),
49
50// Relocation 7 (foo@INDNTPOFF) is of type R_386_TLS_IE
51// CHECK-NEXT: # Relocation 7
52// CHECK-NEXT: (('r_offset', 0x0000002b)
53// CHECK-NEXT:  ('r_sym', 0x00000d)
54// CHECK-NEXT:  ('r_type', 0x0f)
55// CHECK-NEXT: ),
56
57// Relocation 8 (foo@NTPOFF) is of type R_386_TLS_LE
58// CHECK-NEXT: # Relocation 8
59// CHECK-NEXT: (('r_offset', 0x00000031)
60// CHECK-NEXT:  ('r_sym', 0x00000d)
61// CHECK-NEXT:  ('r_type', 0x11)
62// CHECK-NEXT: ),
63
64// Relocation 9 (foo@GOTNTPOFF) is of type R_386_TLS_GOTIE
65// CHECK-NEXT: # Relocation 9
66// CHECK-NEXT: (('r_offset', 0x00000037)
67// CHECK-NEXT:  ('r_sym', 0x00000d)
68// CHECK-NEXT:  ('r_type', 0x10)
69// CHECK-NEXT: ),
70
71// Relocation 10 (foo@TLSLDM) is of type R_386_TLS_LDM
72// CHECK-NEXT: # Relocation 10
73// CHECK-NEXT: (('r_offset', 0x0000003d)
74// CHECK-NEXT:  ('r_sym', 0x00000d)
75// CHECK-NEXT:  ('r_type', 0x13)
76// CHECK-NEXT: ),
77
78// Relocation 11 (foo@DTPOFF) is of type R_386_TLS_LDO_32
79// CHECK-NEXT: # Relocation 11
80// CHECK-NEXT: (('r_offset', 0x00000043)
81// CHECK-NEXT:  ('r_sym', 0x00000d)
82// CHECK-NEXT:  ('r_type', 0x20)
83// CHECK-NEXT: ),
84// Relocation 12 (calll 4096) is of type R_386_PC32
85// CHECK-NEXT: # Relocation 12
86// CHECK-NEXT: (('r_offset', 0x00000048)
87// CHECK-NEXT:  ('r_sym', 0x000000)
88// CHECK-NEXT:  ('r_type', 0x02)
89// CHECK-NEXT: ),
90// Relocation 13 (zed@GOT) is of type R_386_GOT32 and uses the symbol
91// CHECK-NEXT: # Relocation 13
92// CHECK-NEXT: (('r_offset', 0x0000004e)
93// CHECK-NEXT:  ('r_sym', 0x000004)
94// CHECK-NEXT:  ('r_type', 0x03)
95// CHECK-NEXT: ),
96// Relocation 14 (zed@GOTOFF) is of type R_386_GOTOFF and uses the symbol
97// CHECK-NEXT: # Relocation 14
98// CHECK-NEXT: (('r_offset', 0x00000054)
99// CHECK-NEXT:  ('r_sym', 0x000004)
100// CHECK-NEXT:  ('r_type', 0x09)
101// CHECK-NEXT: ),
102// Relocation 15 (zed@INDNTPOFF) is of type R_386_TLS_IE and uses the symbol
103// CHECK-NEXT: # Relocation 15
104// CHECK-NEXT: (('r_offset', 0x0000005a)
105// CHECK-NEXT:  ('r_sym', 0x000004)
106// CHECK-NEXT:  ('r_type', 0x0f)
107// CHECK-NEXT: ),
108// Relocation 16 (zed@NTPOFF) is of type R_386_TLS_LE and uses the symbol
109// CHECK-NEXT: # Relocation 16
110// CHECK-NEXT: (('r_offset', 0x00000060)
111// CHECK-NEXT:  ('r_sym', 0x000004)
112// CHECK-NEXT:  ('r_type', 0x11)
113// CHECK-NEXT: ),
114// Relocation 17 (zed@GOTNTPOFF) is of type R_386_TLS_GOTIE and uses the symbol
115// CHECK-NEXT: # Relocation 17
116// CHECK-NEXT: (('r_offset', 0x00000066)
117// CHECK-NEXT:  ('r_sym', 0x000004)
118// CHECK-NEXT:  ('r_type', 0x10)
119// CHECK-NEXT: ),
120// Relocation 18 (zed@PLT) is of type R_386_PLT32 and uses the symbol
121// CHECK-NEXT: # Relocation 18
122// CHECK-NEXT: (('r_offset', 0x0000006b)
123// CHECK-NEXT:  ('r_sym', 0x000004)
124// CHECK-NEXT:  ('r_type', 0x04)
125// CHECK-NEXT: ),
126// Relocation 19 (zed@TLSGD) is of type R_386_TLS_GD and uses the symbol
127// CHECK-NEXT: # Relocation 19
128// CHECK-NEXT: (('r_offset', 0x00000071)
129// CHECK-NEXT:  ('r_sym', 0x000004)
130// CHECK-NEXT:  ('r_type', 0x12)
131// CHECK-NEXT: ),
132// Relocation 20 (zed@TLSLDM) is of type R_386_TLS_LDM and uses the symbol
133// CHECK-NEXT: # Relocation 20
134// CHECK-NEXT: (('r_offset', 0x00000077)
135// CHECK-NEXT:  ('r_sym', 0x000004)
136// CHECK-NEXT:  ('r_type', 0x13)
137// CHECK-NEXT: ),
138// Relocation 21 (zed@TPOFF) is of type R_386_TLS_LE_32 and uses the symbol
139// CHECK-NEXT:# Relocation 21
140// CHECK-NEXT: (('r_offset', 0x0000007d)
141// CHECK-NEXT:  ('r_sym', 0x000004)
142// CHECK-NEXT:  ('r_type', 0x22)
143// CHECK-NEXT: ),
144// Relocation 22 (zed@DTPOFF) is of type R_386_TLS_LDO_32 and uses the symbol
145// CHECK-NEXT: Relocation 22
146// CHECK-NEXT: (('r_offset', 0x00000083)
147// CHECK-NEXT:  ('r_sym', 0x000004)
148// CHECK-NEXT:  ('r_type', 0x20)
149// CHECK-NEXT: ),
150// Relocation 23 ($bar) is of type R_386_32 and uses the section
151// CHECK-NEXT: Relocation 23
152// CHECK-NEXT: (('r_offset',
153// CHECK-NEXT:  ('r_sym',
154// CHECK-NEXT:  ('r_type', 0x01)
155// CHECK-NEXT: ),
156// Relocation 24 (foo@GOTTPOFF(%edx)) is of type R_386_TLS_IE_32 and uses the
157// symbol
158// CHECK-NEXT: Relocation 24
159// CHECK-NEXT: (('r_offset', 0x0000008e)
160// CHECK-NEXT:  ('r_sym', 0x00000d)
161// CHECK-NEXT:  ('r_type', 0x21)
162// CHECK-NEXT: ),
163// Relocation 25 (_GLOBAL_OFFSET_TABLE_-bar2) is of type R_386_GOTPC.
164// CHECK-NEXT: Relocation 25
165// CHECK-NEXT: (('r_offset', 0x00000094)
166// CHECK-NEXT:  ('r_sym', 0x00000b)
167// CHECK-NEXT:  ('r_type', 0x0a)
168// CHECK-NEXT: ),
169// Relocation 26 (und_symbol-bar2) is of type R_386_PC32
170// CHECK-NEXT: Relocation 26
171// CHECK-NEXT: (('r_offset', 0x0000009a)
172// CHECK-NEXT:  ('r_sym', 0x00000e)
173// CHECK-NEXT:  ('r_type', 0x02)
174// CHECK-NEXT: ),
175
176// Section 4 is bss
177// CHECK:      # Section 4
178// CHECK-NEXT: (('sh_name', 0x0000000b) # '.bss'
179
180// CHECK:      # Symbol 1
181// CHECK-NEXT: (('st_name', 0x00000005) # '.Lfoo'
182
183// Symbol 4 is zed
184// CHECK:      # Symbol 4
185// CHECK-NEXT: (('st_name', 0x00000035) # 'zed'
186// CHECK-NEXT:  ('st_value', 0x00000000)
187// CHECK-NEXT:  ('st_size', 0x00000000)
188// CHECK-NEXT:  ('st_bind', 0x0)
189// CHECK-NEXT:  ('st_type', 0x6)
190// CHECK-NEXT:  ('st_other', 0x00)
191// CHECK-NEXT:  ('st_shndx', 0x0005)
192
193// Symbol 7 is section 4
194// CHECK:      # Symbol 7
195// CHECK-NEXT: (('st_name', 0x00000000) # ''
196// CHECK-NEXT:  ('st_value', 0x00000000)
197// CHECK-NEXT:  ('st_size', 0x00000000)
198// CHECK-NEXT:  ('st_bind', 0x0)
199// CHECK-NEXT:  ('st_type', 0x3)
200// CHECK-NEXT:  ('st_other', 0x00)
201// CHECK-NEXT:  ('st_shndx', 0x0004)
202
203
204        .text
205bar:
206	leal	.Lfoo@GOTOFF(%ebx), %eax
207
208        .global bar2
209bar2:
210	calll	bar2@PLT
211	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
212	movb	bar3@GOTOFF(%ebx), %al
213
214	.type	bar3,@object
215	.local	bar3
216	.comm	bar3,1,1
217
218        movl	bar2j@GOT(%eax), %eax
219
220        leal foo@TLSGD(, %ebx,1), %eax
221        movl $foo@TPOFF, %edx
222        movl foo@INDNTPOFF, %ecx
223        addl foo@NTPOFF(%eax), %eax
224        addl foo@GOTNTPOFF(%ebx), %ecx
225        leal foo@TLSLDM(%ebx), %eax
226        leal foo@DTPOFF(%eax), %edx
227        calll 4096
228        movl zed@GOT(%eax), %eax
229        movl zed@GOTOFF(%eax), %eax
230        movl zed@INDNTPOFF(%eax), %eax
231        movl zed@NTPOFF(%eax), %eax
232        movl zed@GOTNTPOFF(%eax), %eax
233        call zed@PLT
234        movl zed@TLSGD(%eax), %eax
235        movl zed@TLSLDM(%eax), %eax
236        movl zed@TPOFF(%eax), %eax
237        movl zed@DTPOFF(%eax), %eax
238        pushl $bar
239        addl foo@GOTTPOFF(%edx), %eax
240        subl    _GLOBAL_OFFSET_TABLE_-bar2, %ebx
241        leal und_symbol-bar2(%edx),%ecx
242
243        .section        zedsec,"awT",@progbits
244zed:
245        .long 0
246
247        .section	.rodata.str1.16,"aMS",@progbits,1
248.Lfoo:
249	.asciz	 "bool llvm::llvm_start_multithreaded()"
250