293 lines · yaml
1## Check that yaml2obj is able to customize the string table.2## `ContentSize`, `Length`, `Strings` and/or `RawContent` can be specified in3## YAML. Here we test the behaviour in various cases.4 5## Case 1: yaml2obj writes the default content (i.e. long symbol names in6## XCOFF32 or any symbol names in XCOFF64) when no StringTable field7## is specified.8# RUN: yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -o %t19# RUN: llvm-readobj %t1 --string-table | FileCheck %s --check-prefix=CASE110 11# CASE1: StringTable {12# CASE1-NEXT: Length: 1713# CASE1-NEXT: [ 4] nameInStrTbl14# CASE1-NEXT: }15 16--- !XCOFF17FileHeader:18 MagicNumber: 0x1DF19Symbols:20 - Name: [[SYMNAME=<none>]]21 - Name: [[SYMNAME2=<none>]]22StringTable:23 ContentSize: [[CONTENTSIZE=<none>]]24 Length: [[LENGTHVALUE=<none>]]25 RawContent: [[RAWCONTENT=<none>]]26 27## We can specify `ContentSize` only when the value is equal to or greater28## than the content size. For greater cases, zeros are added as padding.29## Cases 2-6 are trying to check this.30 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 %t234# RUN: llvm-readobj %t2 -s --string-table | FileCheck %s --check-prefix=CASE235 36# CASE2: StringTable {37# CASE2-NEXT: Length: 2038# CASE2-NEXT: }39 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 %t343# RUN: llvm-readobj %t3 --string-table | FileCheck %s --check-prefix=CASE344 45# CASE3: StringTable {46# CASE3-NEXT: Length: 2047# CASE3-NEXT: [ 4] nameInStrTbl48# CASE3-NEXT: }49 50## Case 4: the value of `ContentSize` matches the actual content size.51# RUN: yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -DCONTENTSIZE=17 -o %t452# RUN: llvm-readobj %t4 --string-table | FileCheck %s --check-prefix=CASE453 54# CASE4: StringTable {55# CASE4-NEXT: Length: 1756# CASE4-NEXT: [ 4] nameInStrTbl57# CASE4-NEXT: }58 59## Case 5: an error is reported when the value of "ContentSize" is less than60## the content size.61# RUN: not yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -DCONTENTSIZE=16 \62# RUN: -o %t5 2>&1 | FileCheck %s --check-prefix=CASE563 64# CASE5: error: specified ContentSize (16) is less than the size of the data that would otherwise be written (17)65 66## Case 6: an error is reported when `ContentSize` is less than 4 without67## `RawContent`.68# RUN: not yaml2obj --docnum=1 %s -DCONTENTSIZE=3 -o %t6 2>&1 \69# RUN: | FileCheck %s --check-prefix=CASE670 71# CASE6: error: ContentSize shouldn't be less than 4 without RawContent72 73## We can specify `Strings` for a string table. Default contents (ie. symbol74## names in string table) will be overwritten by specified values. Cases 7-975## are trying to check this function.76 77## Case 7: produce a string table with specified `Strings` directly. In this78## case, there is no default content.79# RUN: yaml2obj --docnum=2 %s -o %t780# RUN: llvm-readobj %t7 --string-table | FileCheck %s --check-prefix=CASE781 82# CASE7: StringTable {83# CASE7-NEXT: Length: 884# CASE7-NEXT: [ 4] b85# CASE7-NEXT: [ 6] a86# CASE7-NEXT: }87 88--- !XCOFF89FileHeader:90 MagicNumber: 0x1DF91Symbols:92 - Name: [[SYMNAME=<none>]]93 - Name: [[SYMNAME2=<none>]]94 - Name: [[SYMNAME3=<none>]]95StringTable:96 ContentSize: [[CONTENTSIZE=<none>]]97 Length: [[LENGTHVALUE=<none>]]98 RawContent: [[RAWCONTENT=<none>]]99 Strings:100 - a101 - b102 103## Case 8: if the number of `Strings` is greater than or equal to the number104## of default strings, all default strings will be overwritten by105## specified ones.106# RUN: yaml2obj --docnum=2 %s -DSYMNAME='nameInStrTbl' -o %t8107# RUN: llvm-readobj %t8 -s --string-table | FileCheck %s --check-prefix=CASE8108 109# CASE8: Symbols [110# CASE8-NEXT: Symbol {111# CASE8-NEXT: Index: 0112# CASE8-NEXT: Name: a113# CASE8-NEXT: Value: 0x0114# CASE8-NEXT: Section: N_UNDEF115# CASE8-NEXT: Type: 0x0116# CASE8-NEXT: StorageClass: C_NULL (0x0)117# CASE8-NEXT: NumberOfAuxEntries: 0118# CASE8-NEXT: }119# CASE8-NEXT: Symbol {120# CASE8-NEXT: Index: 1121# CASE8-NEXT: Name: <none>122# CASE8-NEXT: Value: 0x0123# CASE8-NEXT: Section: N_UNDEF124# CASE8-NEXT: Type: 0x0125# CASE8-NEXT: StorageClass: C_NULL (0x0)126# CASE8-NEXT: NumberOfAuxEntries: 0127# CASE8-NEXT: }128# CASE8-NEXT: Symbol {129# CASE8-NEXT: Index: 2130# CASE8-NEXT: Name: <none>131# CASE8-NEXT: Value: 0x0132# CASE8-NEXT: Section: N_UNDEF133# CASE8-NEXT: Type: 0x0134# CASE8-NEXT: StorageClass: C_NULL (0x0)135# CASE8-NEXT: NumberOfAuxEntries: 0136# CASE8-NEXT: }137# CASE8-NEXT: ]138# CASE8-NEXT: StringTable {139# CASE8-NEXT: Length: 8140# CASE8-NEXT: [ 4] b141# CASE8-NEXT: [ 6] a142# CASE8-NEXT: }143 144## Case 9: if the number of `Strings` is less than the number of default145## strings, default strings will be partially overwritten. The146## remaining strings will still be stored after the specified strings147## in the string table.148# RUN: yaml2obj --docnum=2 %s -DSYMNAME='nameInStrTbl' \149# RUN: -DSYMNAME2='name2InStrTbl' -DSYMNAME3='name3InStrTbl' -o %t9150# RUN: llvm-readobj %t9 -s --string-table | FileCheck %s --check-prefix=CASE9151 152# CASE9: Symbols [153# CASE9-NEXT: Symbol {154# CASE9-NEXT: Index: 0155# CASE9-NEXT: Name: a156# CASE9-NEXT: Value: 0x0157# CASE9-NEXT: Section: N_UNDEF158# CASE9-NEXT: Type: 0x0159# CASE9-NEXT: StorageClass: C_NULL (0x0)160# CASE9-NEXT: NumberOfAuxEntries: 0161# CASE9-NEXT: }162# CASE9-NEXT: Symbol {163# CASE9-NEXT: Index: 1164# CASE9-NEXT: Name: b165# CASE9-NEXT: Value: 0x0166# CASE9-NEXT: Section: N_UNDEF167# CASE9-NEXT: Type: 0x0168# CASE9-NEXT: StorageClass: C_NULL (0x0)169# CASE9-NEXT: NumberOfAuxEntries: 0170# CASE9-NEXT: }171# CASE9-NEXT: Symbol {172# CASE9-NEXT: Index: 2173# CASE9-NEXT: Name: name3InStrTbl174# CASE9-NEXT: Value: 0x0175# CASE9-NEXT: Section: N_UNDEF176# CASE9-NEXT: Type: 0x0177# CASE9-NEXT: StorageClass: C_NULL (0x0)178# CASE9-NEXT: NumberOfAuxEntries: 0179# CASE9-NEXT: }180# CASE9-NEXT: ]181# CASE9-NEXT: StringTable {182# CASE9-NEXT: Length: 22183# CASE9-NEXT: [ 4] name3InStrTbl184# CASE9-NEXT: [ 12] b185# CASE9-NEXT: [ 14] a186# CASE9-NEXT: }187 188## We can specify both `ContentSize` and `Strings` when `ContentSize` is equal189## to or greater than the content size. Cases 10-12 are trying to check this.190 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 %t10195# RUN: llvm-readobj %t10 --string-table | FileCheck %s --check-prefix=CASE10196 197# CASE10: StringTable {198# CASE10-NEXT: Length: 20199# CASE10-NEXT: [ 4] b200# CASE10-NEXT: [ 6] a201# CASE10-NEXT: }202 203## Case 11: for a string table with default contents, we can specify204## `ContentSize` and `Strings` when the `ContentSize` is greater205## 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 %t11208# RUN: llvm-readobj %t11 --string-table | FileCheck %s --check-prefix=CASE11209 210# CASE11: StringTable {211# CASE11-NEXT: Length: 30212# CASE11-NEXT: [ 4] name3InStrTbl213# CASE11-NEXT: [ 12] b214# CASE11-NEXT: [ 14] a215# CASE11-NEXT: }216 217## Case 12: an error is reported when the value of `ContentSize` is less218## than the final content size. None of `ContentSize`, `Strings` or219## 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=CASE12223 224# CASE12: error: specified ContentSize (10) is less than the size of the data that would otherwise be written (22)225 226## We can use `RawContent` to generate a string table. Cases 13-16 are trying to227## check the `RawContent`.228 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 %t13232# RUN: llvm-readobj %t13 --string-table | FileCheck %s --check-prefix=CASE13233 234# CASE13: StringTable {235# CASE13-NEXT: Length: 9236# CASE13-NEXT: [ 5] b237# CASE13-NEXT: [ 7] c238# CASE13-NEXT: }239 240## Case 14: if `RawContent` is specified and `ContentSize` matches the size241## of the `RawContent` data. Write the `RawContent` data.242# RUN: yaml2obj --docnum=1 %s -DRAWCONTENT="000000090062006300" -DCONTENTSIZE=9 -o %t14243# RUN: llvm-readobj %t14 --string-table | FileCheck %s --check-prefix=CASE14244 245# CASE14: StringTable {246# CASE14-NEXT: Length: 9247# CASE14-NEXT: [ 5] b248# CASE14-NEXT: [ 7] c249# CASE14-NEXT: }250 251## Case 15: an error is reported when `ContentSize` is less than the `RawContent`252## data size.253# RUN: not yaml2obj --docnum=1 %s -DRAWCONTENT="000000090062006300" -DCONTENTSIZE=6 \254# RUN: -o %t15 2>&1 | FileCheck %s --check-prefix=CASE15255 256# CASE15: error: specified ContentSize (6) is less than the RawContent data size (9)257 258## Case 16: if `RawContent` is specified and `ContentSize` is greater than the259## `RawContent` data size, pad the RawContent with trailing zeroes.260# RUN: yaml2obj --docnum=1 %s -DRAWCONTENT="000000090062006300" -DCONTENTSIZE=11 -o %t16261# RUN: llvm-readobj %t16 --string-table | FileCheck %s --check-prefix=CASE16262 263# CASE16: StringTable {264# CASE16-NEXT: Length: 9265# CASE16-NEXT: [ 5] b266# CASE16-NEXT: [ 7] c267# CASE16-NEXT: }268 269## We can specify `Length`. Use the value of the `Length` field for the first270## 4 bytes of the table. The value may not make sense for the data that is271## being written. Cases 17-20 are trying to check this.272 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=CASE17276 277# CASE17: error: can't specify Strings or Length when RawContent is specified278 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=CASE18282 283# CASE18: error: can't specify Strings or Length when RawContent is specified284 285## Case 19: use the value of the `Length` field for the first 4 bytes of the286## table. We dump the string table from the offset of 0x38.287# RUN: yaml2obj --docnum=1 %s -DSYMNAME='nameInStrTbl' -DLENGTHVALUE=20 -o %t19288# RUN: od -A n -t x1 -v -j 0x38 %t19 \289# RUN: | FileCheck %s --ignore-case --check-prefix=CASE19290 291# CASE19: 00 00 00 14 6e 61 6d 65 49 6e 53 74 72 54 62 6c292# CASE19-NEXT: 00293