[llvm-readobj] - Add a test for --hash-table option.

We had no test for --hash-table in tools/llvm-readobj.

The one we had was in test/Object and checked that
it is possible to dump the hash table even when an object
doesn't have a section header table.

In this patch I created a test, moved and merged the existent one.
During moving I converted it to be YAML based to stop using the
precompiled binary.

Differential revision: https://reviews.llvm.org/D73105
This commit is contained in:
Georgii Rymar 2020-01-21 17:49:42 +03:00
parent d0a7cc7177
commit a33427447d
3 changed files with 117 additions and 36 deletions
llvm/test

View File

@ -1,36 +0,0 @@
RUN: llvm-readobj %p/Inputs/no-section-table.so -hash-table -dynamic-table \
RUN: | FileCheck %s
CHECK: DynamicSection [ (24 entries)
CHECK: Tag Type Name/Value
CHECK: 0x0000000000000001 NEEDED Shared library: [libc.so.6]
CHECK: 0x000000000000000C INIT 0x4B8
CHECK: 0x000000000000000D FINI 0x618
CHECK: 0x0000000000000019 INIT_ARRAY 0x2006C0
CHECK: 0x000000000000001B INIT_ARRAYSZ 8 (bytes)
CHECK: 0x000000000000001A FINI_ARRAY 0x2006C8
CHECK: 0x000000000000001C FINI_ARRAYSZ 8 (bytes)
CHECK: 0x0000000000000004 HASH 0x158
CHECK: 0x0000000000000005 STRTAB 0x2D8
CHECK: 0x0000000000000006 SYMTAB 0x1A0
CHECK: 0x000000000000000A STRSZ 179 (bytes)
CHECK: 0x000000000000000B SYMENT 24 (bytes)
CHECK: 0x0000000000000003 PLTGOT 0x2008C0
CHECK: 0x0000000000000002 PLTRELSZ 48 (bytes)
CHECK: 0x0000000000000014 PLTREL RELA
CHECK: 0x0000000000000017 JMPREL 0x488
CHECK: 0x0000000000000007 RELA 0x3C8
CHECK: 0x0000000000000008 RELASZ 192 (bytes)
CHECK: 0x0000000000000009 RELAENT 24 (bytes)
CHECK: 0x000000006FFFFFFE VERNEED 0x3A8
CHECK: 0x000000006FFFFFFF VERNEEDNUM 1
CHECK: 0x000000006FFFFFF0 VERSYM 0x38C
CHECK: 0x000000006FFFFFF9 RELACOUNT 3
CHECK: 0x0000000000000000 NULL 0x0
CHECK: ]
CHECK: HashTable {
CHECK: Num Buckets: 3
CHECK: Num Chains: 13
CHECK: Buckets: [12, 10, 11]
CHECK: Chains: [0, 0, 0, 0, 2, 3, 4, 0, 7, 5, 6, 8, 9]
CHECK: }

View File

@ -0,0 +1,117 @@
## 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: llvm-readobj --hash-table %t.x64 | FileCheck %s --check-prefix=HASH
# RUN: llvm-readelf --hash-table %t.x64 | FileCheck %s --check-prefix=HASH
# RUN: llvm-readobj --hash-table %t.x32 | FileCheck %s --check-prefix=HASH
# RUN: llvm-readelf --hash-table %t.x32 | FileCheck %s --check-prefix=HASH
# HASH: HashTable {
# HASH-NEXT: Num Buckets: 2
# HASH-NEXT: Num Chains: 3
# HASH-NEXT: Buckets: [1, 2]
# HASH-NEXT: Chains: [3, 4, 5]
# HASH-NEXT: }
--- !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
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_386
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
## 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: llvm-readobj --hash-table %t.noshdr | FileCheck %s --check-prefix=NOSHDR
# RUN: llvm-readelf --hash-table %t.noshdr | FileCheck %s --check-prefix=NOSHDR
# NOSHDR: HashTable {
# NOSHDR-NEXT: Num Buckets: 1
# NOSHDR-NEXT: Num Chains: 1
# NOSHDR-NEXT: Buckets: [0]
# NOSHDR-NEXT: Chains: [1]
# NOSHDR-NEXT: }
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
## We simulate no section header table by
## overriding the ELF header properties.
SHOff: 0x0
SHNum: 0x0
Sections:
- Name: .hash
Type: SHT_HASH
Flags: [ SHF_ALLOC ]
Bucket: [ 0 ]
Chain: [ 1 ]
- 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
- Type: PT_DYNAMIC
VAddr: 0x1010
Sections:
- Section: .dynamic