Skip to content

Commit 3578945

Browse files
author
Georgii Rymar
committed
[llvm-readobj][test] - Improve testing in hash-table.test
This makes tests stricter and adds cases to verify what we do when: 1) there is no `DT_HASH` tag (but there is a `SHT_HASH` section in sections header) 2) the sh_entsize of the `SHT_HASH` section is not equal to 4. Differential revision: https://reviews.llvm.org/D88812
1 parent 9824d5c commit 3578945

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

llvm/test/tools/llvm-readobj/ELF/hash-table.test

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ ProgramHeaders:
4545
## Check we can dump the SHT_HASH section even when an object
4646
## does not have the section header table.
4747

48-
# RUN: yaml2obj --docnum=2 %s -o %t.noshdr
49-
# RUN: llvm-readobj --hash-table %t.noshdr | FileCheck %s --check-prefix=NOSHDR
50-
# RUN: llvm-readelf --hash-table %t.noshdr | FileCheck %s --check-prefix=NOSHDR
48+
# RUN: yaml2obj --docnum=2 -DNOHEADERS=true %s -o %t.noshdr
49+
# RUN: llvm-readobj --hash-table %t.noshdr 2>&1 | \
50+
# RUN: FileCheck %s -DFILE=%t.noshdr --check-prefix=NOSHDR --implicit-check-not=warning:
51+
# RUN: llvm-readelf --hash-table %t.noshdr 2>&1 | \
52+
# RUN: FileCheck %s -DFILE=%t.noshdr --check-prefix=NOSHDR --implicit-check-not=warning:
53+
54+
# NOSHDR: warning: '[[FILE]]': string table was not found
5155

5256
# NOSHDR: HashTable {
5357
# NOSHDR-NEXT: Num Buckets: 1
@@ -58,37 +62,57 @@ ProgramHeaders:
5862

5963
--- !ELF
6064
FileHeader:
61-
Class: ELFCLASS64
62-
Data: ELFDATA2LSB
63-
Type: ET_DYN
64-
## We simulate no section header table by
65-
## overriding the ELF header properties.
66-
EShOff: 0x0
67-
EShNum: 0x0
65+
Class: ELFCLASS64
66+
Data: ELFDATA2LSB
67+
Type: ET_DYN
6868
Sections:
6969
- Name: .hash
7070
Type: SHT_HASH
7171
Flags: [ SHF_ALLOC ]
7272
Bucket: [ 0 ]
7373
Chain: [ 1 ]
74+
EntSize: [[ENTSIZE=4]]
7475
- Name: .dynamic
7576
Type: SHT_DYNAMIC
7677
Flags: [ SHF_ALLOC ]
7778
Entries:
78-
- Tag: DT_HASH
79+
- Tag: [[DYNTAG=DT_HASH]]
7980
Value: 0x0
8081
- Tag: DT_NULL
8182
Value: 0x0
83+
SectionHeaderTable:
84+
NoHeaders: [[NOHEADERS=false]]
8285
ProgramHeaders:
8386
- Type: PT_LOAD
8487
Sections:
8588
- Section: .hash
8689
- Section: .dynamic
8790
- Type: PT_DYNAMIC
88-
VAddr: 0x1010
91+
VAddr: 0x10
8992
Sections:
9093
- Section: .dynamic
9194

95+
## Document we don't report a warning when the value of the sh_entsize field of the SHT_HASH section is not 4.
96+
97+
# RUN: yaml2obj --docnum=2 -DENTSIZE=0xff %s -o %t.ent.size
98+
# RUN: llvm-readobj --hash-table %t.ent.size 2>&1 | \
99+
# RUN: FileCheck %s -DFILE=%t.ent.size --check-prefix=NOSHDR --implicit-check-not=warning:
100+
# RUN: llvm-readelf --hash-table %t.ent.size 2>&1 | \
101+
# RUN: FileCheck %s -DFILE=%t.ent.size --check-prefix=NOSHDR --implicit-check-not=warning:
102+
103+
## Document we need the DT_HASH dynamic tag to locate the hash table.
104+
105+
# RUN: yaml2obj --docnum=2 -DDYNTAG=DT_NULL %s -o %t.no.dyntag
106+
# RUN: llvm-readobj --hash-table %t.no.dyntag 2>&1 | \
107+
# RUN: FileCheck %s -DFILE=%t.no.dyntag --check-prefix=NODYNTAG --implicit-check-not=warning:
108+
# RUN: llvm-readelf --hash-table %t.no.dyntag 2>&1 | \
109+
# RUN: FileCheck %s -DFILE=%t.no.dyntag --check-prefix=NODYNTAG --implicit-check-not=warning:
110+
111+
# NODYNTAG: warning: '[[FILE]]': string table was not found
112+
113+
# NODYNTAG: HashTable {
114+
# NODYNTAG-NEXT: }
115+
92116
## Each SHT_HASH section starts with two 32-bit fields: nbucket and nchain.
93117
## Check we report an error when a DT_HASH value points to data that has size less than 8 bytes.
94118

0 commit comments

Comments
 (0)