1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

[llvm-readobj] - Don't crash when checking the number of dynamic symbols.

When we deriving the number of symbols from the DT_HASH table, we can crash when
calculate the number of symbols in the symbol table when SHT_DYNSYM
has sh_entsize == 0.

The patch fixes the issue.

Differential revision: https://reviews.llvm.org/D82877
This commit is contained in:
Georgii Rymar 2020-06-30 17:14:45 +03:00
parent aa2b4ebf4e
commit b18d8b7481
2 changed files with 27 additions and 9 deletions

View File

@ -158,6 +158,20 @@ ProgramHeaders:
# RUN: FileCheck %s --check-prefixes=GNU2,GNU2-MORE,GNU2-ALL,WARN \ # RUN: FileCheck %s --check-prefixes=GNU2,GNU2-MORE,GNU2-ALL,WARN \
# RUN: --implicit-check-not=warning: -DNCHAIN=4 # RUN: --implicit-check-not=warning: -DNCHAIN=4
# WARN: warning: '{{.*}}2-{{.*}}': hash table nchain ([[NCHAIN]]) differs from symbol count derived from SHT_DYNSYM section header (3)
## Show we report a warning when the sh_entsize of the SHT_DYNSYM section is zero and therefore we are unable
## to derive the number of dynamic symbols from SHT_DYNSYM section header.
# RUN: yaml2obj --docnum=2 %s -o %t2-zero-entsize -DCHAIN="[1, 2, 3, 4]" -DENTSIZE=0
# RUN: llvm-readobj --dyn-symbols %t2-zero-entsize 2>&1 | \
# RUN: FileCheck %s -DFILE=%t2-zero-entsize --check-prefixes=LLVM2,LLVM2-MORE,LLVM2-ALL,WARN-ENTSIZE \
# RUN: --implicit-check-not=warning:
# RUN: llvm-readelf --dyn-symbols %t2-zero-entsize 2>&1 | \
# RUN: FileCheck %s -DFILE=%t2-zero-entsize --check-prefixes=GNU2,GNU2-MORE,GNU2-ALL,WARN-ENTSIZE \
# RUN: --implicit-check-not=warning: -DNCHAIN=4
## WARN-ENTSIZE: warning: '[[FILE]]': SHT_DYNSYM section has sh_entsize == 0
## Show there's no warning if the sizes match ## Show there's no warning if the sizes match
# RUN: yaml2obj --docnum=2 %s -o %t2-same -DCHAIN="[1, 2, 3]" # RUN: yaml2obj --docnum=2 %s -o %t2-same -DCHAIN="[1, 2, 3]"
# RUN: llvm-readobj --dyn-symbols %t2-same 2>&1 | \ # RUN: llvm-readobj --dyn-symbols %t2-same 2>&1 | \
@ -166,8 +180,6 @@ ProgramHeaders:
# RUN: FileCheck %s --check-prefixes=GNU2,GNU2-MORE \ # RUN: FileCheck %s --check-prefixes=GNU2,GNU2-MORE \
# RUN: --implicit-check-not=warning: -DNCHAIN=3 # RUN: --implicit-check-not=warning: -DNCHAIN=3
# WARN: warning: '{{.*}}2-{{.*}}': hash table nchain ([[NCHAIN]]) differs from symbol count derived from SHT_DYNSYM section header (3)
# LLVM2: DynamicSymbols [ # LLVM2: DynamicSymbols [
# LLVM2-NEXT: Symbol { # LLVM2-NEXT: Symbol {
# LLVM2-NEXT: Name: (0) # LLVM2-NEXT: Name: (0)
@ -236,6 +248,8 @@ Sections:
ShSize: 0x48 ShSize: 0x48
Address: 0x400 Address: 0x400
AddressAlign: 0x400 AddressAlign: 0x400
## 0x18 is the standard entsize value.
EntSize: [[ENTSIZE=0x18]]
- Name: .hash - Name: .hash
Type: SHT_HASH Type: SHT_HASH
Flags: [ SHF_ALLOC ] Flags: [ SHF_ALLOC ]

View File

@ -2215,13 +2215,17 @@ void ELFDumper<ELFT>::parseDynamicTable(const ELFFile<ELFT> *Obj) {
// equal nchain". Check to see if the DT_HASH hash table nchain value // equal nchain". Check to see if the DT_HASH hash table nchain value
// conflicts with the number of symbols in the dynamic symbol table // conflicts with the number of symbols in the dynamic symbol table
// according to the section header. // according to the section header.
if (HashTable && if (HashTable) {
HashTable->nchain != DynSymRegion->Size / DynSymRegion->EntSize) if (DynSymRegion->EntSize == 0)
reportUniqueWarning(createError( reportUniqueWarning(
"hash table nchain (" + Twine(HashTable->nchain) + createError("SHT_DYNSYM section has sh_entsize == 0"));
") differs from symbol count derived from SHT_DYNSYM section " else if (HashTable->nchain != DynSymRegion->Size / DynSymRegion->EntSize)
"header (" + reportUniqueWarning(createError(
Twine(DynSymRegion->Size / DynSymRegion->EntSize) + ")")); "hash table nchain (" + Twine(HashTable->nchain) +
") differs from symbol count derived from SHT_DYNSYM section "
"header (" +
Twine(DynSymRegion->Size / DynSymRegion->EntSize) + ")"));
}
} }
// Delay the creation of the actual dynamic symbol table until now, so that // Delay the creation of the actual dynamic symbol table until now, so that