[llvm-readobj/elf] - Change the behavior of handing DT_SONAME.

The current situation/behavior is:
1) llvm-readelf doesn't need a string that is specified by `DT_SONAME`.
2) llvm-readobj/elf always tries to read it, even when there is no `DT_SONAME` tag.
3) Because of that both tools reports a warning for many our test cases.

This patch delays getting a SOName string and changes the behavior (llvm-readobj) to
only report a warning when there is a `DT_SONAME` and a string cab't be read.
Warning is not reported for llvm-readelf, as it never tries to dump it.

Differential revision: https://reviews.llvm.org/D89384
This commit is contained in:
Georgii Rymar 2020-10-14 14:20:38 +03:00
parent 03f3ef221b
commit 6a5f950364
5 changed files with 43 additions and 39 deletions

View File

@ -116,8 +116,7 @@ ProgramHeaders:
# BAD-STRING-LLVM-NEXT: 0x0000000000000000 NULL 0x0
# BAD-STRING-LLVM-NEXT: ]
# BAD-STRING-GNU: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6: it goes past the end of the table (0xb1)
# BAD-STRING-GNU-NEXT: Dynamic section at offset 0xb1 contains 10 entries:
# BAD-STRING-GNU: Dynamic section at offset 0xb1 contains 10 entries:
# BAD-STRING-GNU-NEXT: Tag Type Name/Value
# BAD-STRING-GNU-NEXT: 0x0000000000000005 (STRTAB) 0x1000
# BAD-STRING-GNU-NEXT: 0x000000000000000a (STRSZ) 1 (bytes)
@ -129,7 +128,7 @@ ProgramHeaders:
# BAD-STRING-GNU-NEXT: 0x000000007ffffffd (AUXILIARY) Auxiliary library: [<?>]
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5: it goes past the end of the table (0xb1)
# BAD-STRING-GNU-NEXT: 0x000000007ffffffe (USED) Not needed object: [<?>]
## Note: there is no "string table at offset 0xb6..." warning here, because it was printed earlier.
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb6: it goes past the end of the table (0xb1)
# BAD-STRING-GNU-NEXT: 0x000000000000000e (SONAME) Library soname: [<?>]
# BAD-STRING-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb7: it goes past the end of the table (0xb1)
# BAD-STRING-GNU-NEXT: 0x000000000000000f (RPATH) Library rpath: [<?>]
@ -186,23 +185,26 @@ ProgramHeaders:
# RUN: yaml2obj %s --docnum=4 -o %t.bad-strtab
# RUN: llvm-readobj --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
# RUN: FileCheck -DFILE=%t.bad-strtab %s --implicit-check-not=warning: --check-prefix=BAD-STRTAB-ERR
# RUN: llvm-readelf --dynamic-table %t.bad-strtab 2>&1 >/dev/null | \
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefix BAD-STRTAB-ERR
# BAD-STRTAB-ERR: warning: '[[FILE]]': Unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
# BAD-STRTAB-ERR: warning: '[[FILE]]': string table was not found
# RUN: FileCheck -DFILE=%t.bad-strtab %s --implicit-check-not=warning: --check-prefix=BAD-STRTAB-ERR
# BAD-STRTAB-ERR: warning: '[[FILE]]': Unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
# BAD-STRTAB-ERR: warning: '[[FILE]]': string table was not found
# BAD-STRTAB-ERR-NOT:{{.}}
# RUN: llvm-readobj --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR,BAD-STRTAB,BAD-STRTAB-LLVM
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR2,BAD-STRTAB,BAD-STRTAB-LLVM
# RUN: llvm-readelf --dynamic-table --needed-libs %t.bad-strtab 2>&1 | \
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR,BAD-STRTAB,BAD-STRTAB-GNU
# RUN: FileCheck -DFILE=%t.bad-strtab %s --check-prefixes=BAD-STRTAB-ERR2,BAD-STRTAB,BAD-STRTAB-GNU
# BAD-STRTAB-LLVM: LoadName: <?>
# BAD-STRTAB-LLVM: 0x0000000000000001 NEEDED Shared library: [<?>]
# BAD-STRTAB-GNU: 0x0000000000000001 (NEEDED) Shared library: [<?>]
# BAD-STRTAB: NeededLibraries [
# BAD-STRTAB: <?>
# BAD-STRTAB: ]
# BAD-STRTAB-ERR2: warning: '[[FILE]]': Unable to parse DT_STRTAB: virtual address is not in any segment: 0x2000000
# BAD-STRTAB-LLVM: LoadName: <Not found>
# BAD-STRTAB: warning: '[[FILE]]': string table was not found
# BAD-STRTAB-LLVM-NEXT: 0x0000000000000001 NEEDED Shared library: [<?>]
# BAD-STRTAB-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
# BAD-STRTAB: NeededLibraries [
# BAD-STRTAB: <?>
# BAD-STRTAB: ]
--- !ELF
FileHeader:
@ -281,27 +283,33 @@ ProgramHeaders:
## the not null-terminated dynamic string table.
# RUN: yaml2obj %s -DSTRSZ=7 --docnum=6 -o %t6
# RUN: llvm-readobj --dynamic-table %t6 2>&1 | \
# RUN: FileCheck %s -DFILE=%t6 --implicit-check-not=warning: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GREQ
# RUN: FileCheck %s -DFILE=%t6 --implicit-check-not=warning: \
# RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LLVM,NOT-TERMINATED-GREQ
# RUN: llvm-readelf --dynamic-table %t6 2>&1 | \
# RUN: FileCheck %s -DFILE=%t6 --implicit-check-not=warning: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GREQ
# RUN: FileCheck %s -DFILE=%t6 --implicit-check-not=warning: \
# RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GNU,NOT-TERMINATED-GREQ
## Case B: the value of the DT_STRSZ tag is less than the size of
## the not null-terminated dynamic string table.
# RUN: yaml2obj %s -DSTRSZ=6 --docnum=6 -o %t7
# RUN: llvm-readobj --dynamic-table %t7 2>&1 | \
# RUN: FileCheck %s -DFILE=%t7 --implicit-check-not=warning: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LESS
# RUN: FileCheck %s -DFILE=%t7 --implicit-check-not=warning: \
# RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LLVM,NOT-TERMINATED-LESS
# RUN: llvm-readelf --dynamic-table %t7 2>&1 | \
# RUN: FileCheck %s -DFILE=%t7 --implicit-check-not=warning: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LESS
# RUN: FileCheck %s -DFILE=%t7 --implicit-check-not=warning: \
# RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GNU,NOT-TERMINATED-LESS
## Case C: the value of the DT_STRSZ tag is one byte larger than the size of
## the not null-terminated dynamic string table.
# RUN: yaml2obj %s -DSTRSZ=8 --docnum=6 -o %t8
# RUN: llvm-readobj --dynamic-table %t8 2>&1 | \
# RUN: FileCheck %s -DFILE=%t8 --implicit-check-not=warning: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GREQ
# RUN: FileCheck %s -DFILE=%t8 --implicit-check-not=warning: \
# RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-LLVM,NOT-TERMINATED-GREQ
# RUN: llvm-readelf --dynamic-table %t8 2>&1 | \
# RUN: FileCheck %s -DFILE=%t8 --implicit-check-not=warning: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GREQ
# RUN: FileCheck %s -DFILE=%t8 --implicit-check-not=warning: \
# RUN: --check-prefixes=NOT-TERMINATED,NOT-TERMINATED-GNU,NOT-TERMINATED-GREQ
# NOT-TERMINATED: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: the string table is not null-terminated
# NOT-TERMINATED-LLVM: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: the string table is not null-terminated
# NOT-TERMINATED: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb0: the string table is not null-terminated
# NOT-TERMINATED-NEXT: {{[(]?}}NEEDED{{[)]?}} Shared library: [<?>]
# NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb1: the string table is not null-terminated
@ -310,6 +318,7 @@ ProgramHeaders:
# NOT-TERMINATED-NEXT: {{[(]?}}AUXILIARY{{[)]?}} Auxiliary library: [<?>]
# NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb3: the string table is not null-terminated
# NOT-TERMINATED-NEXT: {{[(]?}}USED{{[)]?}} Not needed object: [<?>]
# NOT-TERMINATED-GNU-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb4: the string table is not null-terminated
# NOT-TERMINATED-NEXT: {{[(]?}}SONAME{{[)]?}} Library soname: [<?>]
# NOT-TERMINATED-NEXT: warning: '[[FILE]]': string table at offset 0xb0: unable to read the string at 0xb5: the string table is not null-terminated
# NOT-TERMINATED-NEXT: {{[(]?}}RPATH{{[)]?}} Library rpath: [<?>]

View File

@ -491,7 +491,9 @@ Sections:
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_RELR: invalid e_phentsize: 1
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_ANDROID_RELR: invalid e_phentsize: 1
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': Unable to parse DT_GNU_HASH: invalid e_phentsize: 1
# PHENTSIZE-WARN-NEXT: warning: '[[FILE]]': string table was not found
# PHENTSIZE-LLVM: warning: '[[FILE]]': string table was not found
# PHENTSIZE-LLVM-NEXT: LoadName: <?>
# PHENTSIZE-LLVM: DynamicSection [ (61 entries)
# PHENTSIZE-LLVM-NEXT: Tag Type Name/Value
@ -560,6 +562,7 @@ Sections:
# PHENTSIZE-GNU: Dynamic section at offset 0xc0 contains 61 entries:
# PHENTSIZE-GNU-NEXT: Tag Type Name/Value
# PHENTSIZE-GNU-NEXT: warning: '[[FILE]]': string table was not found
# PHENTSIZE-GNU-NEXT: 0x0000000000000001 (NEEDED) Shared library: [<?>]
# PHENTSIZE-GNU-NEXT: 0x0000000000000002 (PLTRELSZ) 16 (bytes)
# PHENTSIZE-GNU-NEXT: 0x0000000000000003 (PLTGOT) 0x1000

View File

@ -73,12 +73,10 @@ ProgramHeaders:
## We don't report warnings about the unsupported hash table on EM_S390 and EM_ALPHA platforms
## when --hash-table is not requested.
# RUN: llvm-readobj %t.s390 2>&1 | FileCheck %s -DFILE=%t.s390 --implicit-check-not="warning:" --check-prefix=NOWARN
# RUN: llvm-readelf %t.s390 2>&1 | FileCheck %s -DFILE=%t.s390 --implicit-check-not="warning:" --check-prefix=NOWARN
# RUN: llvm-readobj %t.alpha 2>&1 | FileCheck %s -DFILE=%t.alpha --implicit-check-not="warning:" --check-prefix=NOWARN
# RUN: llvm-readelf %t.alpha 2>&1 | FileCheck %s -DFILE=%t.alpha --implicit-check-not="warning:" --check-prefix=NOWARN
# NOWARN: warning: '[[FILE]]': string table was not found
# RUN: llvm-readobj %t.s390 2>&1 | FileCheck %s -DFILE=%t.s390 --allow-empty --implicit-check-not="warning:"
# RUN: llvm-readelf %t.s390 2>&1 | FileCheck %s -DFILE=%t.s390 --allow-empty --implicit-check-not="warning:"
# RUN: llvm-readobj %t.alpha 2>&1 | FileCheck %s -DFILE=%t.alpha --allow-empty --implicit-check-not="warning:"
# RUN: llvm-readelf %t.alpha 2>&1 | FileCheck %s -DFILE=%t.alpha --allow-empty --implicit-check-not="warning:"
## Check we can dump the SHT_HASH section even when an object
## does not have the section header table.
@ -89,8 +87,6 @@ ProgramHeaders:
# RUN: llvm-readelf --hash-table %t.noshdr 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.noshdr --check-prefix=NOSHDR --implicit-check-not=warning:
# NOSHDR: warning: '[[FILE]]': string table was not found
# NOSHDR: HashTable {
# NOSHDR-NEXT: Num Buckets: 1
# NOSHDR-NEXT: Num Chains: 1
@ -146,8 +142,6 @@ ProgramHeaders:
# RUN: llvm-readelf --hash-table %t.no.dyntag 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.no.dyntag --check-prefix=NODYNTAG --implicit-check-not=warning:
# NODYNTAG: warning: '[[FILE]]': string table was not found
# NODYNTAG: HashTable {
# NODYNTAG-NEXT: }

View File

@ -62,8 +62,6 @@ ProgramHeaders:
# RUN: llvm-readelf --needed-libs %t2 2>&1 | \
# RUN: FileCheck %s -DFILE=%t2 --implicit-check-not=warning: --check-prefix=EMPTY-DYNSTR
# EMPTY-DYNSTR: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x78: it goes past the end of the table (0x78)
# EMPTY-DYNSTR-LLVM: LoadName: <?>
# EMPTY-DYNSTR: NeededLibraries [
# EMPTY-DYNSTR-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x79: it goes past the end of the table (0x78)
# EMPTY-DYNSTR-NEXT: warning: '[[FILE]]': string table at offset 0x78: unable to read the string at 0x7a: it goes past the end of the table (0x78)

View File

@ -304,7 +304,6 @@ private:
Optional<DynRegionInfo> DynSymRegion;
DynRegionInfo DynamicTable;
StringRef DynamicStringTable;
StringRef SOName = "<Not found>";
const Elf_Hash *HashTable = nullptr;
const Elf_GnuHash *GnuHashTable = nullptr;
const Elf_Shdr *DotSymtabSec = nullptr;
@ -312,6 +311,7 @@ private:
const Elf_Shdr *DotCGProfileSec = nullptr;
const Elf_Shdr *DotAddrsigSec = nullptr;
ArrayRef<Elf_Word> ShndxTable;
Optional<uint64_t> SONameOffset;
const Elf_Shdr *SymbolVersionSection = nullptr; // .gnu.version
const Elf_Shdr *SymbolVersionNeedSection = nullptr; // .gnu.version_r
@ -2066,7 +2066,6 @@ void ELFDumper<ELFT>::parseDynamicTable() {
return MappedAddrOrError.get();
};
uint64_t SONameOffset = 0;
const char *StringTableBegin = nullptr;
uint64_t StringTableSize = 0;
Optional<DynRegionInfo> DynSymFromTable;
@ -2184,8 +2183,6 @@ void ELFDumper<ELFT>::parseDynamicTable() {
DynamicStringTable = StringRef(StringTableBegin, StringTableSize);
}
SOName = getDynamicString(SONameOffset);
const bool IsHashTableSupported = getHashTableEntSize() == 4;
if (DynSymRegion) {
// Often we find the information about the dynamic symbol table
@ -2820,6 +2817,9 @@ void ELFDumper<ELFT>::printGnuHashTable() {
}
template <typename ELFT> void ELFDumper<ELFT>::printLoadName() {
StringRef SOName = "<Not found>";
if (SONameOffset)
SOName = getDynamicString(*SONameOffset);
W.printString("LoadName", SOName);
}