xref: /llvm-project/llvm/test/tools/obj2yaml/ELF/gnu-hash-section.yaml (revision b8cb1802a8a2037bd893e038b4eafa61bd5c279e)
1## Check how obj2yaml produces SHT_GNU_HASH section descriptions.
2
3## Check that obj2yaml uses "Header", "BloomFilter", "HashBuckets" and "HashValues"
4## tags to describe a SHT_GNU_HASH section when it has content of a correct size.
5
6# RUN: yaml2obj --docnum=1 %s -o %t1
7# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=FIELDS
8
9# FIELDS:      - Name:   .gnu.hash
10# FIELDS-NEXT:     Type:   SHT_GNU_HASH
11# FIELDS-NEXT:     Flags:  [ SHF_ALLOC ]
12# FIELDS-NEXT:     Header:
13# FIELDS-NEXT:       SymNdx: 0x1
14# FIELDS-NEXT:       Shift2: 0x2
15# FIELDS-NEXT:     BloomFilter: [ 0x3, 0x4 ]
16# FIELDS-NEXT:     HashBuckets: [ 0x5, 0x6, 0x7 ]
17# FIELDS-NEXT:     HashValues:  [ 0x8, 0x9, 0xA, 0xB ]
18
19--- !ELF
20FileHeader:
21  Class: ELFCLASS32
22  Data:  ELFDATA2LSB
23  Type:  ET_DYN
24Sections:
25  - Name:  .gnu.hash
26    Type:  SHT_GNU_HASH
27    Flags: [ SHF_ALLOC ]
28    Header:
29      SymNdx: 0x1
30      Shift2: 0x2
31    BloomFilter: [0x3, 0x4]
32    HashBuckets: [0x5, 0x6, 0x7]
33    HashValues:  [0x8, 0x9, 0xA, 0xB]
34
35## Check how we handle broken cases.
36
37# RUN: yaml2obj --docnum=2 %s -o %t2
38# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=INVALID
39
40# INVALID:      - Name:        .gnu.hash.tooshort
41# INVALID-NEXT:   Type:        SHT_GNU_HASH
42# INVALID-NEXT:   Flags:       [ SHF_ALLOC ]
43# INVALID-NEXT:   Content:     112233445566778899AABBCCDDEEFF
44# INVALID-NEXT: - Name:        .gnu.hash.empty
45# INVALID-NEXT:   Type:        SHT_GNU_HASH
46# INVALID-NEXT:   Flags:       [ SHF_ALLOC ]
47# INVALID-NEXT:   Address:     0xF
48# INVALID-NEXT:   Header:
49# INVALID-NEXT:     SymNdx:      0x0
50# INVALID-NEXT:     Shift2:      0x0
51# INVALID-NEXT:   BloomFilter: [ ]
52# INVALID-NEXT:   HashBuckets: [ ]
53# INVALID-NEXT:   HashValues:  [ ]
54# INVALID-NEXT: - Name:        .gnu.hash.broken.maskwords
55# INVALID-NEXT:   Type:        SHT_GNU_HASH
56# INVALID-NEXT:   Content:     '00000000000000000100000000000000'
57# INVALID-NEXT: - Name:        .gnu.hash.broken.nbuckets.a
58# INVALID-NEXT:   Type:        SHT_GNU_HASH
59# INVALID-NEXT:   Content:     '01000000000000000000000000000000'
60# INVALID-NEXT: - Name:        .gnu.hash.broken.nbuckets.b
61# INVALID-NEXT:   Type:        SHT_GNU_HASH
62# INVALID-NEXT:   Content:     FFFFFFFF000000000100000000000000{{$}}
63# INVALID-NEXT: - Name:        .gnu.hash.hashvalues.ok
64# INVALID-NEXT:   Type:        SHT_GNU_HASH
65# INVALID-NEXT:   Header:
66# INVALID-NEXT:     SymNdx:      0x0
67# INVALID-NEXT:     Shift2:      0x0
68# INVALID-NEXT:   BloomFilter: [ ]
69# INVALID-NEXT:   HashBuckets: [ ]
70# INVALID-NEXT:   HashValues:  [ 0x0 ]
71# INVALID-NEXT: - Name:        .gnu.hash.hashvalues.fail
72# INVALID-NEXT:   Type:        SHT_GNU_HASH
73# INVALID-NEXT:   Content:     '000000000000000000000000000000000000000000'
74
75--- !ELF
76FileHeader:
77  Class: ELFCLASS32
78  Data:  ELFDATA2LSB
79  Type:  ET_DYN
80Sections:
81## Case 1: Content is less than 16 bytes.
82  - Name:   .gnu.hash.tooshort
83    Type:   SHT_GNU_HASH
84    Flags:  [ SHF_ALLOC ]
85    Content: "112233445566778899AABBCCDDEEFF"
86## Case2: Check how we handle a fully empty hash section.
87## It is almost technically valid, but uncommon. Modern linkers
88## create at least one entry in Bloom filter if they want to disable it.
89## Also, the dynamic symbol table has a null entry and having SymNdx = 0
90## here is at least strange.
91  - Name:  .gnu.hash.empty
92    Type:  SHT_GNU_HASH
93    Flags: [ SHF_ALLOC ]
94    Header:
95      SymNdx: 0x0
96      Shift2: 0x0
97      MaskWords: 0x0
98      NBuckets:  0x0
99    BloomFilter: []
100    HashBuckets: []
101    HashValues:  []
102## Case 3: MaskWords field is broken: it says that the number of entries
103## in the Bloom filter is 1, but the Bloom filter is empty.
104  - Name:  .gnu.hash.broken.maskwords
105    Type:  SHT_GNU_HASH
106    Header:
107      SymNdx: 0x0
108      Shift2: 0x0
109      MaskWords: 0x1
110      NBuckets:  0x0
111    BloomFilter: []
112    HashBuckets: []
113    HashValues:  []
114## Case 4(a): NBuckets field is broken, it says that the number of entries
115## in the hash buckets is 1, but it is empty.
116  - Name:  .gnu.hash.broken.nbuckets.a
117    Type:  SHT_GNU_HASH
118    Header:
119      SymNdx: 0x0
120      Shift2: 0x0
121      MaskWords: 0x0
122      NBuckets:  0x1
123    BloomFilter: []
124    HashBuckets: []
125    HashValues:  []
126## Case 4(b): NBuckets = 0xFFFFFFFF is incorrect. The result will cause 32-bit
127## unsigned overflows if we keep intermediate expressions uint32_t.
128  - Name:  .gnu.hash.broken.nbuckets.b
129    Type:  SHT_GNU_HASH
130    Header:
131      SymNdx: 0x0
132      Shift2: 0x0
133      MaskWords: 0x1
134      NBuckets:  0xFFFFFFFF
135    BloomFilter: []
136    HashBuckets: []
137    HashValues:  []
138## Case 5: Check that we use the various properties to dump the data when it
139## has a size that is a multiple of 4, but fallback to dumping the whole section
140## using the "Content" property otherwise.
141  - Name:  .gnu.hash.hashvalues.ok
142    Type:  SHT_GNU_HASH
143    Content: "0000000000000000000000000000000000000000"
144  - Name:  .gnu.hash.hashvalues.fail
145    Type:  SHT_GNU_HASH
146    Content: "000000000000000000000000000000000000000000"
147