Chromium Code Reviews

Side by Side Diff: tests_lit/llvm2ice_tests/elf_container.ll

Issue 678533005: Subzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: cleanup Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 ; Tests that we generate an elf container with fields that make sense,
2 ; cross-validating against llvm-mc.
3
4 ; Test with the integrated elf writer.
5 ; We can't pipe the output because we need to seek backward and patch up
6 ; the file headers. So, use a temporary file.
7 ; RUN: %p2i -i %s --args -O2 --verbose none -elf-writer -o %t \
8 ; RUN: && llvm-readobj -file-headers -sections -section-data \
9 ; RUN: -relocations -symbols %t | FileCheck %s
10
11 ; RUN: %p2i -i %s --args -O2 --verbose none \
12 ; RUN: | llvm-mc -triple=i686-none-nacl -filetype=obj -o - \
13 ; RUN: | llvm-readobj -file-headers -sections -section-data \
14 ; RUN: -relocations -symbols - | FileCheck %s
15
16 ; Use intrinsics to test external calls.
17 declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
18 declare void @llvm.memset.p0i8.i32(i8*, i8, i32, i32, i1)
19
20 ; Test some global data relocs (data, rodata, bss).
21 @bytes = internal global [7 x i8] c"abcdefg", align 1
22 @const_bytes = internal constant [7 x i8] c"abcdefg", align 1
23
24 @ptr = internal global i32 ptrtoint ([7 x i8]* @bytes to i32), align 4
25 @const_ptr = internal constant i32 ptrtoint ([7 x i8]* @bytes to i32), align 4
26
27 @ptr_to_func = internal global i32 ptrtoint (double ()* @returnDoubleConst to i3 2), align 4
28 @const_ptr_to_func = internal constant i32 ptrtoint (double ()* @returnDoubleCon st to i32), align 4
29
30 @short_zero = internal global [2 x i8] zeroinitializer, align 2
31 @double_zero = internal global [8 x i8] zeroinitializer, align 8
32 @const_short_zero = internal constant [2 x i8] zeroinitializer, align 2
33 @const_double_zero = internal constant [8 x i8] zeroinitializer, align 8
34
35
36 @addend_ptr = internal global i32 add (i32 ptrtoint (i32* @ptr to i32), i32 128)
37 @const_addend_ptr = internal constant i32 add (i32 ptrtoint (i32* @ptr to i32), i32 64)
38
39 ; Use float/double constants to test constant pools.
40 define internal float @returnFloatConst() {
41 entry:
42 %f = fadd float 0x3FF3AE1480000000, 0x3FF3AE1400000000
43 ret float %f
44 }
45
46 define internal double @returnDoubleConst() {
47 entry:
48 %d = fadd double 1.230000e+00, 3.210000e+00
49 ret double %d
50 }
51
52 define internal void @test_memcpy(i32 %iptr_dst, i32 %len) {
53 entry:
54 %dst = inttoptr i32 %iptr_dst to i8*
55 %src = bitcast [7 x i8]* @bytes to i8*
56 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dst, i8* %src,
57 i32 %len, i32 1, i1 false)
58 ret void
59 }
60
61 define internal void @test_memset(i32 %iptr_dst, i32 %wide_val, i32 %len) {
62 entry:
63 %val = trunc i32 %wide_val to i8
64 %dst = inttoptr i32 %iptr_dst to i8*
65 call void @llvm.memset.p0i8.i32(i8* %dst, i8 %val,
66 i32 %len, i32 1, i1 false)
67 ret void
68 }
69
70 ; Test non-internal functions too.
71 define void @_start(i32) {
72 %f = call float @returnFloatConst()
73 %d = call double @returnDoubleConst()
74 call void @test_memcpy(i32 0, i32 99)
75 call void @test_memset(i32 0, i32 0, i32 99)
76 ret void
77 }
78
79
80 ; CHECK: ElfHeader {
81 ; CHECK: Ident {
82 ; CHECK: Magic: (7F 45 4C 46)
83 ; CHECK: Class: 32-bit
84 ; CHECK: DataEncoding: LittleEndian
85 ; CHECK: OS/ABI: SystemV (0x0)
86 ; CHECK: ABIVersion: 0
87 ; CHECK: Unused: (00 00 00 00 00 00 00)
88 ; CHECK: }
89 ; CHECK: Type: Relocatable (0x1)
90 ; CHECK: Machine: EM_386 (0x3)
91 ; CHECK: Version: 1
92 ; CHECK: Entry: 0x0
93 ; CHECK: ProgramHeaderOffset: 0x0
94 ; CHECK: SectionHeaderOffset: 0x{{[1-9A-F][0-9A-F]*}}
95 ; CHECK: Flags [ (0x0)
96 ; CHECK: ]
97 ; CHECK: HeaderSize: 52
98 ; CHECK: ProgramHeaderEntrySize: 0
99 ; CHECK: ProgramHeaderCount: 0
100 ; CHECK: SectionHeaderEntrySize: 40
101 ; CHECK: SectionHeaderCount: {{[1-9][0-9]*}}
102 ; CHECK: StringTableSectionIndex: {{[1-9][0-9]*}}
103 ; CHECK: }
104
105
106 ; CHECK: Sections [
107 ; CHECK: Section {
108 ; CHECK: Index: 0
109 ; CHECK: Name: (0)
110 ; CHECK: Type: SHT_NULL
111 ; CHECK: Flags [ (0x0)
112 ; CHECK: ]
113 ; CHECK: Address: 0x0
114 ; CHECK: Offset: 0x0
115 ; CHECK: Size: 0
116 ; CHECK: Link: 0
117 ; CHECK: Info: 0
118 ; CHECK: AddressAlignment: 0
119 ; CHECK: EntrySize: 0
120 ; CHECK: SectionData (
121 ; CHECK-NEXT: )
122 ; CHECK: }
123 ; CHECK: Section {
124 ; CHECK: Index: {{[1-9][0-9]*}}
125 ; CHECK: Name: .text
126 ; CHECK: Type: SHT_PROGBITS
127 ; CHECK: Flags [ (0x6)
128 ; CHECK: SHF_ALLOC
129 ; CHECK: SHF_EXECINSTR
130 ; CHECK: ]
131 ; CHECK: Address: 0x0
132 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}}
133 ; CHECK: Size: {{[1-9][0-9]*}}
134 ; CHECK: Link: 0
135 ; CHECK: Info: 0
136 ; CHECK: AddressAlignment: 32
137 ; CHECK: EntrySize: 0
138 ; CHECK: SectionData (
139 ; There's probably halt padding (0xF4) in there somewhere.
140 ; CHECK: {{.*}}F4
141 ; CHECK: )
142 ; CHECK: }
143 ; CHECK: Section {
144 ; CHECK: Index: {{[1-9][0-9]*}}
145 ; CHECK: Name: .shstrtab
146 ; CHECK: Type: SHT_STRTAB
147 ; CHECK: Flags [ (0x0)
148 ; CHECK: ]
149 ; CHECK: Address: 0x0
150 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}}
151 ; CHECK: Size: {{[1-9][0-9]*}}
152 ; CHECK: Link: 0
153 ; CHECK: Info: 0
154 ; CHECK: AddressAlignment: 1
155 ; CHECK: EntrySize: 0
156 ; CHECK: SectionData (
157 ; CHECK: {{.*}}.text{{.*}}
158 ; CHECK: )
159 ; CHECK: }
160 ; CHECK: Section {
161 ; CHECK: Index: {{[1-9][0-9]*}}
162 ; CHECK: Name: .symtab
163 ; CHECK: Type: SHT_SYMTAB
164 ; CHECK: Flags [ (0x0)
165 ; CHECK: ]
166 ; CHECK: Address: 0x0
167 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}}
168 ; CHECK: Size: {{[1-9][0-9]*}}
169 ; CHECK: Link: [[STRTAB_INDEX:[1-9][0-9]*]]
170 ; CHECK: Info: [[GLOBAL_START_INDEX:[1-9][0-9]*]]
171 ; CHECK: AddressAlignment: 4
172 ; CHECK: EntrySize: 16
173 ; CHECK: }
174 ; CHECK: Section {
175 ; CHECK: Index: [[STRTAB_INDEX]]
176 ; CHECK: Name: .strtab
177 ; CHECK: Type: SHT_STRTAB
178 ; CHECK: Flags [ (0x0)
179 ; CHECK: ]
180 ; CHECK: Address: 0x0
181 ; CHECK: Offset: 0x{{[1-9A-F][0-9A-F]*}}
182 ; CHECK: Size: {{[1-9][0-9]*}}
183 ; CHECK: Link: 0
184 ; CHECK: Info: 0
185 ; CHECK: AddressAlignment: 1
186 ; CHECK: EntrySize: 0
187 ; CHECK: }
188
189
190 ; CHECK: Relocations [
191 ; CHECK: ]
192
193
194 ; CHECK: Symbols [
195 ; CHECK-NEXT: Symbol {
196 ; CHECK-NEXT: Name: (0)
197 ; CHECK-NEXT: Value: 0x0
198 ; CHECK-NEXT: Size: 0
199 ; CHECK-NEXT: Binding: Local
200 ; CHECK-NEXT: Type: None
201 ; CHECK-NEXT: Other: 0
202 ; CHECK-NEXT: Section: Undefined (0x0)
203 ; CHECK-NEXT: }
204 ; TODO: fill in the data symbols.
205 ; CHECK: Symbol {
206 ; CHECK: Name: returnDoubleConst
207 ; CHECK-NEXT: Value: 0x{{[1-9A-F][0-9A-F]*}}
208 ; CHECK-NEXT: Size: 0
209 ; CHECK-NEXT: Binding: Local
210 ; CHECK-NEXT: Type: None
211 ; CHECK-NEXT: Other: 0
212 ; CHECK-NEXT: Section: .text
213 ; CHECK-NEXT: }
214 ; CHECK: Symbol {
215 ; CHECK: Name: returnFloatConst
216 ; This happens to be the first function, so its offset is 0 within the text.
217 ; CHECK-NEXT: Value: 0x0
218 ; CHECK-NEXT: Size: 0
219 ; CHECK-NEXT: Binding: Local
220 ; CHECK-NEXT: Type: None
221 ; CHECK-NEXT: Other: 0
222 ; CHECK-NEXT: Section: .text
223 ; CHECK-NEXT: }
224 ; CHECK: Symbol {
225 ; CHECK: Name: test_memcpy
226 ; CHECK-NEXT: Value: 0x{{[1-9A-F][0-9A-F]*}}
227 ; CHECK-NEXT: Size: 0
228 ; CHECK-NEXT: Binding: Local
229 ; CHECK-NEXT: Type: None
230 ; CHECK-NEXT: Other: 0
231 ; CHECK-NEXT: Section: .text
232 ; CHECK-NEXT: }
233 ; CHECK: Symbol {
234 ; CHECK: Name: _start
235 ; CHECK-NEXT: Value: 0x{{[1-9A-F][0-9A-F]*}}
236 ; CHECK-NEXT: Size: 0
237 ; CHECK-NEXT: Binding: Global
238 ; CHECK-NEXT: Type: Function
239 ; CHECK-NEXT: Other: 0
240 ; CHECK-NEXT: Section: .text
241 ; CHECK-NEXT: }
242 ; CHECK: ]
OLDNEW
« src/IceMemoryRegion.h ('K') | « src/llvm2ice.cpp ('k') | unittest/IceELFSectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine