1## For implicit dynamic symbol table sections, `Size` and/or `Content` 2## fields can also be specified in YAML. Here we test the behavior in 3## different cases. 4 5## When no `Size` or `Content` is specified for a dynamic symbol table section, 6## yaml2obj writes the default content. 7 8# RUN: yaml2obj --docnum=1 %s -o %t1 9# RUN: llvm-readelf %t1 --dyn-symbols | FileCheck %s --check-prefix=CASE1 10 11# CASE1: Symbol table '.dynsym' contains 2 entries: 12# CASE1-NEXT: Num: Value Size Type Bind Vis Ndx Name 13# CASE1-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 14# CASE1-NEXT: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND foo 15# CASE1-EMPTY: 16 17--- !ELF 18FileHeader: 19 Class: ELFCLASS64 20 Data: ELFDATA2LSB 21 Type: ET_DYN 22Sections: 23 - Name: .dynsym 24 Type: SHT_DYNSYM 25DynamicSymbols: 26 - Name: foo 27 Binding: STB_GLOBAL 28 29## Specifying both `Size` and symbols at the same time is not allowed for .dynsym. 30 31# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --implicit-check-not=error --check-prefix=CASE2 32# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --implicit-check-not=error --check-prefix=CASE2 33 34# CASE2: yaml2obj: error: cannot specify both `Size` and `DynamicSymbols` for symbol table section '.dynsym' 35 36--- !ELF 37FileHeader: 38 Class: ELFCLASS64 39 Data: ELFDATA2LSB 40 Type: ET_DYN 41Sections: 42 - Name: .dynsym 43 Type: SHT_DYNSYM 44 Size: 0x100 45 - Name: .dynsym2 46 Type: SHT_DYNSYM 47 Size: 0x100 48DynamicSymbols: 49 - Name: foo 50 Binding: STB_GLOBAL 51 52--- !ELF 53FileHeader: 54 Class: ELFCLASS64 55 Data: ELFDATA2LSB 56 Type: ET_DYN 57Sections: 58 - Name: .dynsym 59 Type: SHT_DYNSYM 60 Size: 0x100 61 - Name: .dynsym2 62 Type: SHT_DYNSYM 63 Size: 0x100 64DynamicSymbols: [] 65 66## Specifying both `Content` and symbols at the same time is not allowed for .dynsym. 67 68# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --implicit-check-not=error --check-prefix=CASE3 69# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --implicit-check-not=error --check-prefix=CASE3 70 71# CASE3: yaml2obj: error: cannot specify both `Content` and `DynamicSymbols` for symbol table section '.dynsym' 72 73--- !ELF 74FileHeader: 75 Class: ELFCLASS64 76 Data: ELFDATA2LSB 77 Type: ET_DYN 78Sections: 79 - Name: .dynsym 80 Type: SHT_DYNSYM 81 Content: "00" 82 - Name: .dynsym2 83 Type: SHT_DYNSYM 84 Content: "00" 85DynamicSymbols: 86 - Name: foo 87 Binding: STB_GLOBAL 88 89--- !ELF 90FileHeader: 91 Class: ELFCLASS64 92 Data: ELFDATA2LSB 93 Type: ET_DYN 94Sections: 95 - Name: .dynsym 96 Type: SHT_DYNSYM 97 Content: "00" 98 - Name: .dynsym2 99 Type: SHT_DYNSYM 100 Content: "00" 101DynamicSymbols: [] 102 103## Check we can use just `Content` to emit custom data in the symbol table section. 104# RUN: yaml2obj --docnum=6 %s -o %t4 105# RUN: llvm-readobj --section-data -S %t4 | FileCheck %s --check-prefix=CASE4 106 107# CASE4: Name: .dynsym 108# CASE4-NEXT: Type: SHT_DYNSYM 109# CASE4-NEXT: Flags [ 110# CASE4-NEXT: SHF_ALLOC 111# CASE4-NEXT: ] 112# CASE4-NEXT: Address: 0x0 113# CASE4-NEXT: Offset: 0x40 114# CASE4-NEXT: Size: 2 115# CASE4-NEXT: Link: 0 116# CASE4-NEXT: Info: 1 117# CASE4-NEXT: AddressAlignment: 0 118# CASE4-NEXT: EntrySize: 24 119# CASE4-NEXT: SectionData ( 120# CASE4-NEXT: 0000: 0123 121# CASE4-NEXT: ) 122 123--- !ELF 124FileHeader: 125 Class: ELFCLASS64 126 Data: ELFDATA2LSB 127 Type: ET_DYN 128Sections: 129 - Name: .dynsym 130 Type: SHT_DYNSYM 131 Content: "0123" 132 133## Check we can use just `Size` to emit custom data filled with zeroes 134## in the symbol table section. 135# RUN: yaml2obj --docnum=7 %s -o %t5 136# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE5 137 138# CASE5: Name: .dynsym 139# CASE5-NEXT: Type: SHT_DYNSYM 140# CASE5-NEXT: Flags [ 141# CASE5-NEXT: SHF_ALLOC 142# CASE5-NEXT: ] 143# CASE5-NEXT: Address: 0x0 144# CASE5-NEXT: Offset: 0x40 145# CASE5-NEXT: Size: 5 146# CASE5-NEXT: Link: 0 147# CASE5-NEXT: Info: 1 148# CASE5-NEXT: AddressAlignment: 0 149# CASE5-NEXT: EntrySize: 24 150# CASE5-NEXT: SectionData ( 151# CASE5-NEXT: 0000: 00000000 00 152# CASE5-NEXT: ) 153 154--- !ELF 155FileHeader: 156 Class: ELFCLASS64 157 Data: ELFDATA2LSB 158 Type: ET_DYN 159Sections: 160 - Name: .dynsym 161 Type: SHT_DYNSYM 162 Size: 5 163 164## Check we can specify both `Size` and `Content` when size is greater 165## than content size. In this case zeroes are added as padding 166## after after the specified content. 167 168# RUN: yaml2obj --docnum=8 %s -o %t6 169# RUN: llvm-readobj %t6 --section-data -S | FileCheck %s --check-prefix=CASE6 170 171# CASE6: Name: .dynsym 172# CASE6-NEXT: Type: SHT_DYNSYM 173# CASE6-NEXT: Flags [ 174# CASE6-NEXT: SHF_ALLOC 175# CASE6-NEXT: ] 176# CASE6-NEXT: Address: 0x0 177# CASE6-NEXT: Offset: 0x40 178# CASE6-NEXT: Size: 4 179# CASE6-NEXT: Link: 0 180# CASE6-NEXT: Info: 1 181# CASE6-NEXT: AddressAlignment: 0 182# CASE6-NEXT: EntrySize: 24 183# CASE6-NEXT: SectionData ( 184# CASE6-NEXT: 0000: 01230000 185# CASE6-NEXT: ) 186 187--- !ELF 188FileHeader: 189 Class: ELFCLASS64 190 Data: ELFDATA2LSB 191 Type: ET_DYN 192Sections: 193 - Name: .dynsym 194 Type: SHT_DYNSYM 195 Content: "0123" 196 Size: 4 197 198## Check we can specify both `Size` and `Content` when size is 199## equal to content size. 200 201# RUN: yaml2obj --docnum=9 %s -o %t7 202# RUN: llvm-readobj --section-data -S %t7 | FileCheck %s --check-prefix=CASE7 203 204# CASE7: Name: .dynsym 205# CASE7-NEXT: Type: SHT_DYNSYM 206# CASE7-NEXT: Flags [ 207# CASE7-NEXT: SHF_ALLOC 208# CASE7-NEXT: ] 209# CASE7-NEXT: Address: 0x0 210# CASE7-NEXT: Offset: 0x40 211# CASE7-NEXT: Size: 2 212# CASE7-NEXT: Link: 0 213# CASE7-NEXT: Info: 1 214# CASE7-NEXT: AddressAlignment: 0 215# CASE7-NEXT: EntrySize: 24 216# CASE7-NEXT: SectionData ( 217# CASE7-NEXT: 0000: 0123 218# CASE7-NEXT: ) 219 220--- !ELF 221FileHeader: 222 Class: ELFCLASS64 223 Data: ELFDATA2LSB 224 Type: ET_DYN 225Sections: 226 - Name: .dynsym 227 Type: SHT_DYNSYM 228 Content: "0123" 229 Size: 2 230