Skip to content

Commit

Permalink
[llvm-readobj][test] - Deduplicate YAMLs in gnuhash.test and hash-tab…
Browse files Browse the repository at this point in the history
…le.test. NFCI.

We can use `-D` to generalize inputs. This patch does it.

Differential revision: https://reviews.llvm.org/D80199
  • Loading branch information
Georgii Rymar committed May 20, 2020
1 parent a9d7b45 commit 1dcdb02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 87 deletions.
61 changes: 10 additions & 51 deletions llvm/test/tools/llvm-readobj/ELF/gnuhash.test
@@ -1,7 +1,7 @@
## Check how the GNU Hash section is dumped with --gnu-hash-table.

# RUN: yaml2obj --docnum=1 -D MASKWORDS=2 -D NBUCKETS=3 %s -o %t.x64
# RUN: yaml2obj --docnum=2 %s -o %t.x32
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 -D MASKWORDS=2 -D NBUCKETS=3 %s -o %t.x64
# RUN: yaml2obj --docnum=1 -DBITS=32 -DMACHINE=EM_386 %s -D MASKWORDS=2 -D NBUCKETS=3 -o %t.x32

# RUN: llvm-readobj --gnu-hash-table %t.x64 | FileCheck %s
# RUN: llvm-readelf --gnu-hash-table %t.x64 | FileCheck %s
Expand All @@ -21,10 +21,10 @@

--- !ELF
FileHeader:
Class: ELFCLASS64
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Machine: [[MACHINE]]
Sections:
- Name: .gnu.hash
Type: SHT_GNU_HASH
Expand Down Expand Up @@ -64,50 +64,9 @@ ProgramHeaders:
- Section: .gnu.hash
- Section: .dynamic

--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_386
Sections:
- Name: .gnu.hash
Type: SHT_GNU_HASH
Flags: [ SHF_ALLOC ]
Header:
SymNdx: 0x1
Shift2: 0x2
BloomFilter: [0x3, 0x4]
HashBuckets: [0x5, 0x6, 0x7]
HashValues: [0x8, 0x9, 0xA, 0xB]
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Link: .dynstr
Entries:
- Tag: DT_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
DynamicSymbols:
- Name: aaa
Binding: STB_GLOBAL
- Name: bbb
Binding: STB_GLOBAL
- Name: ccc
Binding: STB_GLOBAL
- Name: ddd
Binding: STB_GLOBAL
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
Sections:
- Section: .gnu.hash
- Section: .dynamic

## Check we report a warning if there is no dynamic symbol section in the object.

# RUN: yaml2obj --docnum=3 %s -o %t.nodynsym
# RUN: yaml2obj --docnum=2 %s -o %t.nodynsym
# RUN: llvm-readobj --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM
# RUN: llvm-readelf --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM

Expand Down Expand Up @@ -155,7 +114,7 @@ ProgramHeaders:
## Check what we do when the index of the first symbol in the dynamic symbol table
## included in the hash table is larger than the number of dynamic symbols.

# RUN: yaml2obj --docnum=4 %s -o %t.brokensymndx
# RUN: yaml2obj --docnum=3 %s -o %t.brokensymndx
# RUN: llvm-readobj --gnu-hash-table %t.brokensymndx 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.brokensymndx --check-prefix=SYMNDX
# RUN: llvm-readelf --gnu-hash-table %t.brokensymndx 2>&1 \
Expand Down Expand Up @@ -209,7 +168,7 @@ ProgramHeaders:
## Check we emit a warning when the dynamic symbol table is empty.
## A valid dynamic symbol table should have at least one symbol: the symbol with index 0.

# RUN: yaml2obj --docnum=5 %s -o %t.emptydynsym
# RUN: yaml2obj --docnum=4 %s -o %t.emptydynsym
# RUN: llvm-readobj --gnu-hash-table %t.emptydynsym 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.emptydynsym --check-prefix=EMPTY-DYNSYM
# RUN: llvm-readelf --gnu-hash-table %t.emptydynsym 2>&1 \
Expand Down Expand Up @@ -270,7 +229,7 @@ ProgramHeaders:
## which is one larger than the index of the last dynamic symbol.
## For empty tables however, this value is unimportant and can be ignored.

# RUN: yaml2obj --docnum=6 %s -o %t.empty
# RUN: yaml2obj --docnum=5 %s -o %t.empty
# RUN: llvm-readobj --gnu-hash-table %t.empty 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.empty --check-prefix=EMPTY --implicit-check-not="warning:"
# RUN: llvm-readelf --gnu-hash-table %t.empty 2>&1 \
Expand Down Expand Up @@ -322,14 +281,14 @@ ProgramHeaders:
## Check we report a proper warning when a hash table goes past the end of the file.

## Case A: the 'nbuckets' field is set so that the table goes past the end of the file.
# RUN: yaml2obj --docnum=1 -D MASKWORDS=4294967295 -D NBUCKETS=3 %s -o %t.err.maskwords
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 -D MASKWORDS=4294967295 -D NBUCKETS=3 %s -o %t.err.maskwords
# RUN: llvm-readobj --gnu-hash-table %t.err.maskwords 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.maskwords -DMASKWORDS=4294967295 -DNBUCKETS=3 --check-prefix=ERR
# RUN: llvm-readelf --gnu-hash-table %t.err.maskwords 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.maskwords -DMASKWORDS=4294967295 -DNBUCKETS=3 --check-prefix=ERR

## Case B: the 'maskwords' field is set so that the table goes past the end of the file.
# RUN: yaml2obj --docnum=1 -D MASKWORDS=2 -D NBUCKETS=4294967295 %s -o %t.err.nbuckets
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 -D MASKWORDS=2 -D NBUCKETS=4294967295 %s -o %t.err.nbuckets
# RUN: llvm-readobj --gnu-hash-table %t.err.nbuckets 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.nbuckets -DMASKWORDS=2 -DNBUCKETS=4294967295 --check-prefix=ERR
# RUN: llvm-readelf --gnu-hash-table %t.err.nbuckets 2>&1 | \
Expand Down
46 changes: 10 additions & 36 deletions llvm/test/tools/llvm-readobj/ELF/hash-table.test
@@ -1,7 +1,7 @@
## Check how the SHT_HASH section is dumped with --hash-table.

# RUN: yaml2obj --docnum=1 %s -o %t.x64
# RUN: yaml2obj --docnum=2 %s -o %t.x32
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 %s -o %t.x64
# RUN: yaml2obj --docnum=1 -DBITS=32 -DMACHINE=EM_386 %s -o %t.x32

# RUN: llvm-readobj --hash-table %t.x64 | FileCheck %s --check-prefix=HASH
# RUN: llvm-readelf --hash-table %t.x64 | FileCheck %s --check-prefix=HASH
Expand All @@ -18,36 +18,10 @@

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- Name: .hash
Type: SHT_HASH
Flags: [ SHF_ALLOC ]
Bucket: [ 1, 2 ]
Chain: [ 3, 4, 5 ]
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Entries:
- Tag: DT_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
ProgramHeaders:
- Type: PT_LOAD
Sections:
- Section: .hash
- Section: .dynamic

--- !ELF
FileHeader:
Class: ELFCLASS32
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_386
Machine: [[MACHINE]]
Sections:
- Name: .hash
Type: SHT_HASH
Expand All @@ -71,7 +45,7 @@ ProgramHeaders:
## Check we can dump the SHT_HASH section even when an object
## does not have the section header table.

# RUN: yaml2obj --docnum=3 %s -o %t.noshdr
# RUN: yaml2obj --docnum=2 %s -o %t.noshdr
# RUN: llvm-readobj --hash-table %t.noshdr | FileCheck %s --check-prefix=NOSHDR
# RUN: llvm-readelf --hash-table %t.noshdr | FileCheck %s --check-prefix=NOSHDR

Expand Down Expand Up @@ -119,7 +93,7 @@ ProgramHeaders:
## Each SHT_HASH section starts with two 32-bit fields: nbucket and nchain.
## Check we report an error when a DT_HASH value points to data that has size less than 8 bytes.

# RUN: yaml2obj --docnum=4 %s -o %t4.o
# RUN: yaml2obj --docnum=3 %s -o %t4.o
# RUN: llvm-readelf --hash-table %t4.o 2>&1 | FileCheck %s --check-prefix=ERR1 -DFILE=%t4.o
# RUN: llvm-readobj --hash-table %t4.o 2>&1 | FileCheck %s --check-prefix=ERR1 -DFILE=%t4.o

Expand Down Expand Up @@ -159,7 +133,7 @@ ProgramHeaders:

## Case A.1: the hash table ends right before the EOF. We have a broken nbucket
## field that has a value larger than the number of buckets.
# RUN: yaml2obj --docnum=5 %s -o %t5.1.o -DNBUCKET=0x5d -DNCHAIN=0x1
# RUN: yaml2obj --docnum=4 %s -o %t5.1.o -DNBUCKET=0x5d -DNCHAIN=0x1
# RUN: llvm-readelf --hash-table %t5.1.o 2>&1 | \
# RUN: FileCheck %s --check-prefix=NOERR1 --implicit-check-not="warning:"
# RUN: llvm-readobj --hash-table %t5.1.o 2>&1 | \
Expand All @@ -176,7 +150,7 @@ ProgramHeaders:

## Case A.2: the hash table ends 1 byte past the EOF. We have a broken nbucket
## field that has a value larger than the number of buckets.
# RUN: yaml2obj --docnum=5 %s -o %t5.2.o -DNBUCKET=0x5e -DNCHAIN=0x1
# RUN: yaml2obj --docnum=4 %s -o %t5.2.o -DNBUCKET=0x5e -DNCHAIN=0x1
# RUN: llvm-readelf --hash-table %t5.2.o 2>&1 | \
# RUN: FileCheck %s --check-prefix=ERR2 -DFILE=%t5.2.o --implicit-check-not="warning:"
# RUN: llvm-readobj --hash-table %t5.2.o 2>&1 | \
Expand All @@ -188,7 +162,7 @@ ProgramHeaders:

## Case B.1: the hash table ends right before the EOF. We have a broken nchain
## field that has a value larger than the number of chains.
# RUN: yaml2obj --docnum=5 %s -o %t5.3.o -DNBUCKET=0x1 -DNCHAIN=0x5d
# RUN: yaml2obj --docnum=4 %s -o %t5.3.o -DNBUCKET=0x1 -DNCHAIN=0x5d
# RUN: llvm-readelf --hash-table %t5.3.o 2>&1 | \
# RUN: FileCheck %s --check-prefix=NOERR2 -DFILE=%t5.3.o --implicit-check-not="warning:"
# RUN: llvm-readobj --hash-table %t5.3.o 2>&1 | \
Expand All @@ -206,7 +180,7 @@ ProgramHeaders:

## Case B.2: the hash table ends 1 byte past the EOF. We have a broken nchain
## field that has a value larger than the number of chains.
# RUN: yaml2obj --docnum=5 %s -o %t5.4.o -DNBUCKET=0x1 -DNCHAIN=0x5e
# RUN: yaml2obj --docnum=4 %s -o %t5.4.o -DNBUCKET=0x1 -DNCHAIN=0x5e
# RUN: llvm-readelf --hash-table %t5.4.o 2>&1 | \
# RUN: FileCheck %s --check-prefix=ERR3 -DFILE=%t5.4.o --implicit-check-not="warning:"
# RUN: llvm-readobj --hash-table %t5.4.o 2>&1 | \
Expand Down

0 comments on commit 1dcdb02

Please sign in to comment.