[llvm-readobj/elf] - Don't use unwrapOrError when reporting errors about SHT_DYNAMIC sections.

This changes messages reported to stop using dynamic section names (use `describe()` instead).
This allows to avoid `unwrapOrError` and improves diagnostics.

Differential revision: https://reviews.llvm.org/D87503
This commit is contained in:
Georgii Rymar 2020-09-11 13:29:33 +03:00
parent 14e191a0e7
commit 7448e64a79
3 changed files with 7 additions and 9 deletions

View File

@ -11,7 +11,7 @@
# RUN: llvm-readelf --dynamic-table %t1.o 2>&1 \
# RUN: | FileCheck -DFILE=%t1.o --check-prefixes=WARNING1,GNU1 %s
# WARNING1: warning: '[[FILE]]': The SHT_DYNAMIC section '.dynamic' is not contained within the PT_DYNAMIC segment
# WARNING1: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 is not contained within the PT_DYNAMIC segment
# WARNING1: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x1){{$}}
# WARNING1: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table
# WARNING1: warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
@ -69,7 +69,7 @@ ProgramHeaders:
# RUN: llvm-readelf --dynamic-table %t2.o 2>&1 \
# RUN: | FileCheck -DFILE=%t2.o --check-prefixes=WARNING2,GNU2 %s
# WARNING2: warning: '[[FILE]]': The SHT_DYNAMIC section '.dynamic' is not contained within the PT_DYNAMIC segment
# WARNING2: warning: '[[FILE]]': SHT_DYNAMIC section with index 1 is not contained within the PT_DYNAMIC segment
# WARNING2: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table
# LLVM2: DynamicSection [ (1 entries)

View File

@ -10,7 +10,7 @@
# RUN: llvm-readelf --dynamic-table %t1.o 2>&1 \
# RUN: | FileCheck %s --DFILE=%t1.o --check-prefixes=WARNING,GNU
# WARNING: warning: '[[FILE]]': The SHT_DYNAMIC section '.dynamic' is not at the start of PT_DYNAMIC segment
# WARNING: warning: '[[FILE]]': SHT_DYNAMIC section with index 2 is not at the start of PT_DYNAMIC segment
# WARNING: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x21){{$}}
# WARNING: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table
# WARNING: warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used

View File

@ -1886,19 +1886,17 @@ ELFDumper<ELFT>::findDynamic(const ELFFile<ELFT> *Obj) {
}
if (DynamicPhdr && DynamicSec) {
StringRef Name =
unwrapOrError(ObjF->getFileName(), Obj->getSectionName(DynamicSec));
if (DynamicSec->sh_addr + DynamicSec->sh_size >
DynamicPhdr->p_vaddr + DynamicPhdr->p_memsz ||
DynamicSec->sh_addr < DynamicPhdr->p_vaddr)
reportWarning(createError("The SHT_DYNAMIC section '" + Name +
"' is not contained within the "
reportWarning(createError(describe(*DynamicSec) +
" is not contained within the "
"PT_DYNAMIC segment"),
ObjF->getFileName());
if (DynamicSec->sh_addr != DynamicPhdr->p_vaddr)
reportWarning(createError("The SHT_DYNAMIC section '" + Name +
"' is not at the start of "
reportWarning(createError(describe(*DynamicSec) +
" is not at the start of "
"PT_DYNAMIC segment"),
ObjF->getFileName());
}