1 ## Check that yaml2obj is able to customize the string table.
2 ## `ContentSize`, `Length`, `Strings` and/or `RawContent` can be specified in
3 ## YAML. Here we test the behaviour in various cases.
5 ## Case 1: yaml2obj writes the default content (i.e. long symbol names in
6 ## XCOFF32 or any symbol names in XCOFF64) when no StringTable field
8 # RUN: yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -o %t1
9 # RUN: llvm-readobj %t1 --string-table | FileCheck %s --check-prefix=CASE1
11 # CASE1: StringTable {
12 # CASE1-NEXT: Length: 17
13 # CASE1-NEXT: [ 4] nameInStrTbl
20 - Name: [[SYMNAME=<none>]]
21 - Name: [[SYMNAME2=<none>]]
23 ContentSize: [[CONTENTSIZE=<none>]]
24 Length: [[LENGTHVALUE=<none>]]
25 RawContent: [[RAWCONTENT=<none>]]
27 ## We can specify `ContentSize` only when the value is equal to or greater
28 ## than the content size. For greater cases, zeros are added as padding.
29 ## Cases 2-6 are trying to check this.
31 ## Case 2: produce a string table with a specified `ContentSize`. In this case,
32 ## there is no default content and the content is filled with zeroes.
33 # RUN: yaml2obj --docnum=1 %s -DCONTENTSIZE=20 -o %t2
34 # RUN: llvm-readobj %t2 -s --string-table | FileCheck %s --check-prefix=CASE2
36 # CASE2: StringTable {
37 # CASE2-NEXT: Length: 20
40 ## Case 3: if the value of `ContentSize` is greater than the content size,
41 ## yaml2obj adds zeros as padding after the default content.
42 # RUN: yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -DCONTENTSIZE=20 -o %t3
43 # RUN: llvm-readobj %t3 --string-table | FileCheck %s --check-prefix=CASE3
45 # CASE3: StringTable {
46 # CASE3-NEXT: Length: 20
47 # CASE3-NEXT: [ 4] nameInStrTbl
50 ## Case 4: the value of `ContentSize` matches the actual content size.
51 # RUN: yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -DCONTENTSIZE=17 -o %t4
52 # RUN: llvm-readobj %t4 --string-table | FileCheck %s --check-prefix=CASE4
54 # CASE4: StringTable {
55 # CASE4-NEXT: Length: 17
56 # CASE4-NEXT: [ 4] nameInStrTbl
59 ## Case 5: an error is reported when the value of "ContentSize" is less than
61 # RUN: not yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -DCONTENTSIZE=16 \
62 # RUN: -o %t5 2>&1 | FileCheck %s --check-prefix=CASE5
64 # CASE5: error: specified ContentSize (16) is less than the size of the data that would otherwise be written (17)
66 ## Case 6: an error is reported when `ContentSize` is less than 4 without
68 # RUN: not yaml2obj --docnum=1 %s -DCONTENTSIZE=3 -o %t6 2>&1 \
69 # RUN: | FileCheck %s --check-prefix=CASE6
71 # CASE6: error: ContentSize shouldn't be less than 4 without RawContent
73 ## We can specify `Strings` for a string table. Default contents (ie. symbol
74 ## names in string table) will be overwritten by specified values. Cases 7-9
75 ## are trying to check this function.
77 ## Case 7: produce a string table with specified `Strings` directly. In this
78 ## case, there is no default content.
79 # RUN: yaml2obj --docnum=2 %s -o %t7
80 # RUN: llvm-readobj %t7 --string-table | FileCheck %s --check-prefix=CASE7
82 # CASE7: StringTable {
83 # CASE7-NEXT: Length: 8
92 - Name: [[SYMNAME=<none>]]
93 - Name: [[SYMNAME2=<none>]]
94 - Name: [[SYMNAME3=<none>]]
96 ContentSize: [[CONTENTSIZE=<none>]]
97 Length: [[LENGTHVALUE=<none>]]
98 RawContent: [[RAWCONTENT=<none>]]
103 ## Case 8: if the number of `Strings` is greater than or equal to the number
104 ## of default strings, all default strings will be overwritten by
106 # RUN: yaml2obj --docnum=2 %s -DSYMNAME='nameInStrTbl' -o %t8
107 # RUN: llvm-readobj %t8 -s --string-table | FileCheck %s --check-prefix=CASE8
110 # CASE8-NEXT: Symbol {
111 # CASE8-NEXT: Index: 0
112 # CASE8-NEXT: Name: a
113 # CASE8-NEXT: Value: 0x0
114 # CASE8-NEXT: Section: N_UNDEF
115 # CASE8-NEXT: Type: 0x0
116 # CASE8-NEXT: StorageClass: C_NULL (0x0)
117 # CASE8-NEXT: NumberOfAuxEntries: 0
119 # CASE8-NEXT: Symbol {
120 # CASE8-NEXT: Index: 1
121 # CASE8-NEXT: Name: <none>
122 # CASE8-NEXT: Value: 0x0
123 # CASE8-NEXT: Section: N_UNDEF
124 # CASE8-NEXT: Type: 0x0
125 # CASE8-NEXT: StorageClass: C_NULL (0x0)
126 # CASE8-NEXT: NumberOfAuxEntries: 0
128 # CASE8-NEXT: Symbol {
129 # CASE8-NEXT: Index: 2
130 # CASE8-NEXT: Name: <none>
131 # CASE8-NEXT: Value: 0x0
132 # CASE8-NEXT: Section: N_UNDEF
133 # CASE8-NEXT: Type: 0x0
134 # CASE8-NEXT: StorageClass: C_NULL (0x0)
135 # CASE8-NEXT: NumberOfAuxEntries: 0
138 # CASE8-NEXT: StringTable {
139 # CASE8-NEXT: Length: 8
144 ## Case 9: if the number of `Strings` is less than the number of default
145 ## strings, default strings will be partially overwritten. The
146 ## remaining strings will still be stored after the specified strings
147 ## in the string table.
148 # RUN: yaml2obj --docnum=2 %s -DSYMNAME='nameInStrTbl' \
149 # RUN: -DSYMNAME2='name2InStrTbl' -DSYMNAME3='name3InStrTbl' -o %t9
150 # RUN: llvm-readobj %t9 -s --string-table | FileCheck %s --check-prefix=CASE9
153 # CASE9-NEXT: Symbol {
154 # CASE9-NEXT: Index: 0
155 # CASE9-NEXT: Name: a
156 # CASE9-NEXT: Value: 0x0
157 # CASE9-NEXT: Section: N_UNDEF
158 # CASE9-NEXT: Type: 0x0
159 # CASE9-NEXT: StorageClass: C_NULL (0x0)
160 # CASE9-NEXT: NumberOfAuxEntries: 0
162 # CASE9-NEXT: Symbol {
163 # CASE9-NEXT: Index: 1
164 # CASE9-NEXT: Name: b
165 # CASE9-NEXT: Value: 0x0
166 # CASE9-NEXT: Section: N_UNDEF
167 # CASE9-NEXT: Type: 0x0
168 # CASE9-NEXT: StorageClass: C_NULL (0x0)
169 # CASE9-NEXT: NumberOfAuxEntries: 0
171 # CASE9-NEXT: Symbol {
172 # CASE9-NEXT: Index: 2
173 # CASE9-NEXT: Name: name3InStrTbl
174 # CASE9-NEXT: Value: 0x0
175 # CASE9-NEXT: Section: N_UNDEF
176 # CASE9-NEXT: Type: 0x0
177 # CASE9-NEXT: StorageClass: C_NULL (0x0)
178 # CASE9-NEXT: NumberOfAuxEntries: 0
181 # CASE9-NEXT: StringTable {
182 # CASE9-NEXT: Length: 22
183 # CASE9-NEXT: [ 4] name3InStrTbl
184 # CASE9-NEXT: [ 12] b
185 # CASE9-NEXT: [ 14] a
188 ## We can specify both `ContentSize` and `Strings` when `ContentSize` is equal
189 ## to or greater than the content size. Cases 10-12 are trying to check this.
191 ## Case 10: produce a string table with specified `ContentSize` and `Strings`
192 ## when the value is greater than the size of specified strings.
193 ## In this case, there is no default content.
194 # RUN: yaml2obj --docnum=2 %s -DCONTENTSIZE=20 -o %t10
195 # RUN: llvm-readobj %t10 --string-table | FileCheck %s --check-prefix=CASE10
197 # CASE10: StringTable {
198 # CASE10-NEXT: Length: 20
199 # CASE10-NEXT: [ 4] b
200 # CASE10-NEXT: [ 6] a
203 ## Case 11: for a string table with default contents, we can specify
204 ## `ContentSize` and `Strings` when the `ContentSize` is greater
205 ## than the data that would otherwise be written.
206 # RUN: yaml2obj --docnum=2 %s -DCONTENTSIZE=30 -DSYMNAME='nameInStrTbl' \
207 # RUN: -DSYMNAME2='name2InStrTbl' -DSYMNAME3='name3InStrTbl' -o %t11
208 # RUN: llvm-readobj %t11 --string-table | FileCheck %s --check-prefix=CASE11
210 # CASE11: StringTable {
211 # CASE11-NEXT: Length: 30
212 # CASE11-NEXT: [ 4] name3InStrTbl
213 # CASE11-NEXT: [ 12] b
214 # CASE11-NEXT: [ 14] a
217 ## Case 12: an error is reported when the value of `ContentSize` is less
218 ## than the final content size. None of `ContentSize`, `Strings` or
219 ## default contents is empty in this case.
220 # RUN: not yaml2obj --docnum=2 %s -DCONTENTSIZE=10 -DSYMNAME='nameInStrTbl' \
221 # RUN: -DSYMNAME2='name2InStrTbl' -DSYMNAME3='name3InStrTbl' -o %t12 2>&1 \
222 # RUN: | FileCheck %s --check-prefix=CASE12
224 # CASE12: error: specified ContentSize (10) is less than the size of the data that would otherwise be written (22)
226 ## We can use `RawContent` to generate a string table. Cases 13-16 are trying to
227 ## check the `RawContent`.
229 ## Case 13: if `RawContent` is specified and no `ContentSize` is specified.
230 ## Write the `RawContent` data.
231 # RUN: yaml2obj --docnum=1 %s -DRAWCONTENT="000000090062006300" -o %t13
232 # RUN: llvm-readobj %t13 --string-table | FileCheck %s --check-prefix=CASE13
234 # CASE13: StringTable {
235 # CASE13-NEXT: Length: 9
236 # CASE13-NEXT: [ 5] b
237 # CASE13-NEXT: [ 7] c
240 ## Case 14: if `RawContent` is specified and `ContentSize` matches the size
241 ## of the `RawContent` data. Write the `RawContent` data.
242 # RUN: yaml2obj --docnum=1 %s -DRAWCONTENT="000000090062006300" -DCONTENTSIZE=9 -o %t14
243 # RUN: llvm-readobj %t14 --string-table | FileCheck %s --check-prefix=CASE14
245 # CASE14: StringTable {
246 # CASE14-NEXT: Length: 9
247 # CASE14-NEXT: [ 5] b
248 # CASE14-NEXT: [ 7] c
251 ## Case 15: an error is reported when `ContentSize` is less than the `RawContent`
253 # RUN: not yaml2obj --docnum=1 %s -DRAWCONTENT="000000090062006300" -DCONTENTSIZE=6 \
254 # RUN: -o %t15 2>&1 | FileCheck %s --check-prefix=CASE15
256 # CASE15: error: specified ContentSize (6) is less than the RawContent data size (9)
258 ## Case 16: if `RawContent` is specified and `ContentSize` is greater than the
259 ## `RawContent` data size, pad the RawContent with trailing zeroes.
260 # RUN: yaml2obj --docnum=1 %s -DRAWCONTENT="000000090062006300" -DCONTENTSIZE=11 -o %t16
261 # RUN: llvm-readobj %t16 --string-table | FileCheck %s --check-prefix=CASE16
263 # CASE16: StringTable {
264 # CASE16-NEXT: Length: 9
265 # CASE16-NEXT: [ 5] b
266 # CASE16-NEXT: [ 7] c
269 ## We can specify `Length`. Use the value of the `Length` field for the first
270 ## 4 bytes of the table. The value may not make sense for the data that is
271 ## being written. Cases 17-20 are trying to check this.
273 ## Case 17: report an error if the `Length` is specified as well as `RawContent`.
274 # RUN: not yaml2obj --docnum=1 %s -DRAWCONTENT="0062006300" -DLENGTHVALUE=9 \
275 # RUN: -o %t17 2>&1 | FileCheck %s --check-prefix=CASE17
277 # CASE17: error: can't specify Strings or Length when RawContent is specified
279 ## Case 18: report an error if both `RawContent` and `Strings` are specified.
280 # RUN: not yaml2obj --docnum=2 %s -DRAWCONTENT="0062006300" -o %t18 2>&1 \
281 # RUN: | FileCheck %s --check-prefix=CASE18
283 # CASE18: error: can't specify Strings or Length when RawContent is specified
285 ## Case 19: use the value of the `Length` field for the first 4 bytes of the
286 ## table. We dump the string table from the offset of 0x38.
287 # RUN: yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -DLENGTHVALUE=20 -o %t19
288 # RUN: od -A n -t x1 -v -j 0x38 %t19 \
289 # RUN: | FileCheck %s --ignore-case --check-prefix=CASE19
291 # CASE19: 00 00 00 14 6e 61 6d 65 49 6e 53 74 72 54 62 6c