OLD | NEW |
1 ; Tests that we generate an ELF container with fields that make sense, | 1 ; Tests that we generate an ELF container with fields that make sense, |
2 ; cross-validating against llvm-mc. | 2 ; cross-validating against llvm-mc. |
3 | 3 |
4 ; For the integrated ELF writer, we can't pipe the output because we need | 4 ; For the integrated ELF writer, we can't pipe the output because we need |
5 ; to seek backward and patch up the file headers. So, use a temporary file. | 5 ; to seek backward and patch up the file headers. So, use a temporary file. |
6 ; RUN: %p2i -i %s --args -O2 --verbose none -elf-writer -o %t \ | 6 ; RUN: %p2i -i %s --args -O2 --verbose none -elf-writer -o %t \ |
7 ; RUN: && llvm-readobj -file-headers -sections -section-data \ | 7 ; RUN: && llvm-readobj -file-headers -sections -section-data \ |
8 ; RUN: -relocations -symbols %t | FileCheck %s | 8 ; RUN: -relocations -symbols %t | FileCheck %s |
9 | 9 |
10 ; RUN: %p2i -i %s --args -O2 --verbose none \ | 10 ; RUN: %p2i -i %s --args -O2 --verbose none \ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 ret float %f | 42 ret float %f |
43 } | 43 } |
44 | 44 |
45 define internal double @returnDoubleConst() { | 45 define internal double @returnDoubleConst() { |
46 entry: | 46 entry: |
47 %d = fadd double 0x7FFFFFFFFFFFFFFFF, 0xFFF7FFFFFFFFFFFF | 47 %d = fadd double 0x7FFFFFFFFFFFFFFFF, 0xFFF7FFFFFFFFFFFF |
48 %d2 = fadd double %d, 0xFFF8000000000003 | 48 %d2 = fadd double %d, 0xFFF8000000000003 |
49 ret double %d2 | 49 ret double %d2 |
50 } | 50 } |
51 | 51 |
| 52 ; Test intrinsics that call out to external functions. |
52 define internal void @test_memcpy(i32 %iptr_dst, i32 %len) { | 53 define internal void @test_memcpy(i32 %iptr_dst, i32 %len) { |
53 entry: | 54 entry: |
54 %dst = inttoptr i32 %iptr_dst to i8* | 55 %dst = inttoptr i32 %iptr_dst to i8* |
55 %src = bitcast [7 x i8]* @bytes to i8* | 56 %src = bitcast [7 x i8]* @bytes to i8* |
56 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, | 57 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src, |
57 i32 %len, i32 1, i1 false) | 58 i32 %len, i32 1, i1 false) |
58 ret void | 59 ret void |
59 } | 60 } |
60 | 61 |
61 define internal void @test_memset(i32 %iptr_dst, i32 %wide_val, i32 %len) { | 62 define internal void @test_memset(i32 %iptr_dst, i32 %wide_val, i32 %len) { |
62 entry: | 63 entry: |
63 %val = trunc i32 %wide_val to i8 | 64 %val = trunc i32 %wide_val to i8 |
64 %dst = inttoptr i32 %iptr_dst to i8* | 65 %dst = inttoptr i32 %iptr_dst to i8* |
65 call void @llvm.memset.p0i8.i32(i8* %dst, i8 %val, | 66 call void @llvm.memset.p0i8.i32(i8* %dst, i8 %val, |
66 i32 %len, i32 1, i1 false) | 67 i32 %len, i32 1, i1 false) |
67 ret void | 68 ret void |
68 } | 69 } |
69 | 70 |
70 ; Test non-internal functions too. | 71 ; Test calling internal functions (may be able to do the fixup, |
| 72 ; without emitting a relocation). |
| 73 define internal float @test_call_internal() { |
| 74 %f = call float @returnFloatConst() |
| 75 ret float %f |
| 76 } |
| 77 |
| 78 ; Test copying a function pointer, or a global data pointer. |
| 79 define internal i32 @test_ret_fp() { |
| 80 %r = ptrtoint float ()* @returnFloatConst to i32 |
| 81 ret i32 %r |
| 82 } |
| 83 |
| 84 define internal i32 @test_ret_global_pointer() { |
| 85 %r = ptrtoint [7 x i8]* @bytes to i32 |
| 86 ret i32 %r |
| 87 } |
| 88 |
| 89 ; Test defining a non-internal function. |
71 define void @_start(i32) { | 90 define void @_start(i32) { |
72 %f = call float @returnFloatConst() | 91 %f = call float @returnFloatConst() |
73 %d = call double @returnDoubleConst() | 92 %d = call double @returnDoubleConst() |
74 call void @test_memcpy(i32 0, i32 99) | 93 call void @test_memcpy(i32 0, i32 99) |
75 call void @test_memset(i32 0, i32 0, i32 99) | 94 call void @test_memset(i32 0, i32 0, i32 99) |
| 95 %f2 = call float @test_call_internal() |
| 96 %p1 = call i32 @test_ret_fp() |
| 97 %p2 = call i32 @test_ret_global_pointer() |
76 ret void | 98 ret void |
77 } | 99 } |
78 | 100 |
79 | |
80 ; CHECK: ElfHeader { | 101 ; CHECK: ElfHeader { |
81 ; CHECK: Ident { | 102 ; CHECK: Ident { |
82 ; CHECK: Magic: (7F 45 4C 46) | 103 ; CHECK: Magic: (7F 45 4C 46) |
83 ; CHECK: Class: 32-bit | 104 ; CHECK: Class: 32-bit |
84 ; CHECK: DataEncoding: LittleEndian | 105 ; CHECK: DataEncoding: LittleEndian |
85 ; CHECK: OS/ABI: SystemV (0x0) | 106 ; CHECK: OS/ABI: SystemV (0x0) |
86 ; CHECK: ABIVersion: 0 | 107 ; CHECK: ABIVersion: 0 |
87 ; CHECK: Unused: (00 00 00 00 00 00 00) | 108 ; CHECK: Unused: (00 00 00 00 00 00 00) |
88 ; CHECK: } | 109 ; CHECK: } |
89 ; CHECK: Type: Relocatable (0x1) | 110 ; CHECK: Type: Relocatable (0x1) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 ; CHECK: Info: 0 | 156 ; CHECK: Info: 0 |
136 ; CHECK: AddressAlignment: 32 | 157 ; CHECK: AddressAlignment: 32 |
137 ; CHECK: EntrySize: 0 | 158 ; CHECK: EntrySize: 0 |
138 ; CHECK: SectionData ( | 159 ; CHECK: SectionData ( |
139 ; There's probably halt padding (0xF4) in there somewhere. | 160 ; There's probably halt padding (0xF4) in there somewhere. |
140 ; CHECK: {{.*}}F4 | 161 ; CHECK: {{.*}}F4 |
141 ; CHECK: ) | 162 ; CHECK: ) |
142 ; CHECK: } | 163 ; CHECK: } |
143 ; CHECK: Section { | 164 ; CHECK: Section { |
144 ; CHECK: Index: {{[1-9][0-9]*}} | 165 ; CHECK: Index: {{[1-9][0-9]*}} |
| 166 ; CHECK: Name: .rel.text |
| 167 ; CHECK: Type: SHT_REL |
| 168 ; CHECK: Flags [ (0x0) |
| 169 ; CHECK: ] |
| 170 ; CHECK: Address: 0x0 |
| 171 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}} |
| 172 ; CHECK: Size: {{[1-9][0-9]*}} |
| 173 ; CHECK: Link: [[SYMTAB_INDEX:[1-9][0-9]*]] |
| 174 ; CHECK: Info: {{[1-9][0-9]*}} |
| 175 ; CHECK: AddressAlignment: 4 |
| 176 ; CHECK: EntrySize: 8 |
| 177 ; CHECK: SectionData ( |
| 178 ; CHECK: ) |
| 179 ; CHECK: } |
| 180 ; CHECK: Section { |
| 181 ; CHECK: Index: {{[1-9][0-9]*}} |
145 ; CHECK: Name: .rodata.cst4 | 182 ; CHECK: Name: .rodata.cst4 |
146 ; CHECK: Type: SHT_PROGBITS | 183 ; CHECK: Type: SHT_PROGBITS |
147 ; CHECK: Flags [ (0x12) | 184 ; CHECK: Flags [ (0x12) |
148 ; CHECK: SHF_ALLOC | 185 ; CHECK: SHF_ALLOC |
149 ; CHECK: SHF_MERGE | 186 ; CHECK: SHF_MERGE |
150 ; CHECK: ] | 187 ; CHECK: ] |
151 ; CHECK: Address: 0x0 | 188 ; CHECK: Address: 0x0 |
152 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}} | 189 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}} |
153 ; CHECK: Size: 8 | 190 ; CHECK: Size: 8 |
154 ; CHECK: Link: 0 | 191 ; CHECK: Link: 0 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 ; CHECK: Size: {{[1-9][0-9]*}} | 227 ; CHECK: Size: {{[1-9][0-9]*}} |
191 ; CHECK: Link: 0 | 228 ; CHECK: Link: 0 |
192 ; CHECK: Info: 0 | 229 ; CHECK: Info: 0 |
193 ; CHECK: AddressAlignment: 1 | 230 ; CHECK: AddressAlignment: 1 |
194 ; CHECK: EntrySize: 0 | 231 ; CHECK: EntrySize: 0 |
195 ; CHECK: SectionData ( | 232 ; CHECK: SectionData ( |
196 ; CHECK: {{.*}}.text{{.*}} | 233 ; CHECK: {{.*}}.text{{.*}} |
197 ; CHECK: ) | 234 ; CHECK: ) |
198 ; CHECK: } | 235 ; CHECK: } |
199 ; CHECK: Section { | 236 ; CHECK: Section { |
200 ; CHECK: Index: {{[1-9][0-9]*}} | 237 ; CHECK: Index: [[SYMTAB_INDEX]] |
201 ; CHECK: Name: .symtab | 238 ; CHECK-NEXT: Name: .symtab |
202 ; CHECK: Type: SHT_SYMTAB | 239 ; CHECK: Type: SHT_SYMTAB |
203 ; CHECK: Flags [ (0x0) | 240 ; CHECK: Flags [ (0x0) |
204 ; CHECK: ] | 241 ; CHECK: ] |
205 ; CHECK: Address: 0x0 | 242 ; CHECK: Address: 0x0 |
206 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}} | 243 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}} |
207 ; CHECK: Size: {{[1-9][0-9]*}} | 244 ; CHECK: Size: {{[1-9][0-9]*}} |
208 ; CHECK: Link: [[STRTAB_INDEX:[1-9][0-9]*]] | 245 ; CHECK: Link: [[STRTAB_INDEX:[1-9][0-9]*]] |
209 ; CHECK: Info: [[GLOBAL_START_INDEX:[1-9][0-9]*]] | 246 ; CHECK: Info: [[GLOBAL_START_INDEX:[1-9][0-9]*]] |
210 ; CHECK: AddressAlignment: 4 | 247 ; CHECK: AddressAlignment: 4 |
211 ; CHECK: EntrySize: 16 | 248 ; CHECK: EntrySize: 16 |
212 ; CHECK: } | 249 ; CHECK: } |
213 ; CHECK: Section { | 250 ; CHECK: Section { |
214 ; CHECK: Index: [[STRTAB_INDEX]] | 251 ; CHECK: Index: [[STRTAB_INDEX]] |
215 ; CHECK: Name: .strtab | 252 ; CHECK-NEXT: Name: .strtab |
216 ; CHECK: Type: SHT_STRTAB | 253 ; CHECK: Type: SHT_STRTAB |
217 ; CHECK: Flags [ (0x0) | 254 ; CHECK: Flags [ (0x0) |
218 ; CHECK: ] | 255 ; CHECK: ] |
219 ; CHECK: Address: 0x0 | 256 ; CHECK: Address: 0x0 |
220 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}} | 257 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}} |
221 ; CHECK: Size: {{[1-9][0-9]*}} | 258 ; CHECK: Size: {{[1-9][0-9]*}} |
222 ; CHECK: Link: 0 | 259 ; CHECK: Link: 0 |
223 ; CHECK: Info: 0 | 260 ; CHECK: Info: 0 |
224 ; CHECK: AddressAlignment: 1 | 261 ; CHECK: AddressAlignment: 1 |
225 ; CHECK: EntrySize: 0 | 262 ; CHECK: EntrySize: 0 |
226 ; CHECK: } | 263 ; CHECK: } |
227 | 264 |
228 | 265 |
229 ; CHECK: Relocations [ | 266 ; CHECK: Relocations [ |
230 ; TODO: fill it out. | 267 ; CHECK: Section ({{[0-9]+}}) .rel.text { |
| 268 ; CHECK: 0x4 R_386_32 .L$float$0 0x0 |
| 269 ; CHECK: 0xC R_386_32 .L$float$1 0x0 |
| 270 ; CHECK: 0x24 R_386_32 .L$double$0 0x0 |
| 271 ; CHECK: 0x2C R_386_32 .L$double$1 0x0 |
| 272 ; CHECK: 0x34 R_386_32 .L$double$2 0x0 |
| 273 ; The set of relocations between llvm-mc and integrated elf-writer |
| 274 ; are different. The integrated elf-writer doesn't yet handle |
| 275 ; global data and external/undef functions like memcpy. |
| 276 ; Also, it does not resolve internal function calls and instead |
| 277 ; writes out the relocation. However, there's probably some |
| 278 ; function call so check for a PC32 relocation at least. |
| 279 ; CHECK: 0x{{.*}} R_386_PC32 |
| 280 ; CHECK: } |
231 ; CHECK: ] | 281 ; CHECK: ] |
232 | 282 |
233 | 283 |
234 ; CHECK: Symbols [ | 284 ; CHECK: Symbols [ |
235 ; CHECK-NEXT: Symbol { | 285 ; CHECK-NEXT: Symbol { |
236 ; CHECK-NEXT: Name: (0) | 286 ; CHECK-NEXT: Name: (0) |
237 ; CHECK-NEXT: Value: 0x0 | 287 ; CHECK-NEXT: Value: 0x0 |
238 ; CHECK-NEXT: Size: 0 | 288 ; CHECK-NEXT: Size: 0 |
239 ; CHECK-NEXT: Binding: Local | 289 ; CHECK-NEXT: Binding: Local |
240 ; CHECK-NEXT: Type: None | 290 ; CHECK-NEXT: Type: None |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 ; CHECK: Symbol { | 359 ; CHECK: Symbol { |
310 ; CHECK: Name: _start | 360 ; CHECK: Name: _start |
311 ; CHECK-NEXT: Value: 0x{{[1-9A-F][0-9A-F]*}} | 361 ; CHECK-NEXT: Value: 0x{{[1-9A-F][0-9A-F]*}} |
312 ; CHECK-NEXT: Size: 0 | 362 ; CHECK-NEXT: Size: 0 |
313 ; CHECK-NEXT: Binding: Global | 363 ; CHECK-NEXT: Binding: Global |
314 ; CHECK-NEXT: Type: Function | 364 ; CHECK-NEXT: Type: Function |
315 ; CHECK-NEXT: Other: 0 | 365 ; CHECK-NEXT: Other: 0 |
316 ; CHECK-NEXT: Section: .text | 366 ; CHECK-NEXT: Section: .text |
317 ; CHECK-NEXT: } | 367 ; CHECK-NEXT: } |
318 ; CHECK: ] | 368 ; CHECK: ] |
OLD | NEW |