forked from OSchip/llvm-project
[llvm-readobj/elf] - Improve warning messages, reported for .stack_sizes sections.
Instead of referring to stack sizes sections only by name, we can add section indexes and types to warnings reported. Differential revision: https://reviews.llvm.org/D86934
This commit is contained in:
parent
485e6db872
commit
56ee83e36c
|
@ -186,7 +186,7 @@ Symbols:
|
|||
# SHORT-GNU: Stack Sizes:
|
||||
# SHORT-GNU-NEXT: Size Function
|
||||
# SHORT-GNU-NEXT: 8 foo
|
||||
# SHORT-GNU-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into section .stack_sizes while trying to extract a stack size entry
|
||||
# SHORT-GNU-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into SHT_PROGBITS section with index 2 while trying to extract a stack size entry
|
||||
# SHORT-GNU-NEXT: 8 foo
|
||||
|
||||
# SHORT-LLVM: StackSizes [
|
||||
|
@ -194,7 +194,7 @@ Symbols:
|
|||
# SHORT-LLVM-NEXT: Function: foo
|
||||
# SHORT-LLVM-NEXT: Size: 0x8
|
||||
# SHORT-LLVM-NEXT: }
|
||||
# SHORT-LLVM-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into section .stack_sizes while trying to extract a stack size entry
|
||||
# SHORT-LLVM-NEXT: warning: '[[FILE]]': found invalid relocation offset (0x1) into SHT_PROGBITS section with index 2 while trying to extract a stack size entry
|
||||
# SHORT-LLVM-NEXT: Entry {
|
||||
# SHORT-LLVM-NEXT: Function: foo
|
||||
# SHORT-LLVM-NEXT: Size: 0x8
|
||||
|
@ -361,9 +361,8 @@ Symbols:
|
|||
# RUN: llvm-readelf --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06
|
||||
# RUN: llvm-readobj --stack-sizes %t06 2>&1 | FileCheck %s --check-prefix=BADSIZE -DFILE=%t06
|
||||
|
||||
## TODO: these messages should be improved to include section indices.
|
||||
# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size in section .stack_sizes
|
||||
# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size in section .stack_sizes
|
||||
# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size in SHT_PROGBITS section with index 2
|
||||
# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size in SHT_PROGBITS section with index 3
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
|
@ -460,7 +459,7 @@ Symbols:
|
|||
# NORELOCSECTION-OUT-LLVM: StackSizes [
|
||||
# NORELOCSECTION-OUT-LLVM-NEXT: ]
|
||||
|
||||
# NORELOCSECTION-ERR: warning: '[[FILE]]': section .stack_sizes does not have a corresponding relocation section
|
||||
# NORELOCSECTION-ERR: warning: '[[FILE]]': .stack_sizes (SHT_PROGBITS section with index 2) does not have a corresponding relocation section
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
|
|
|
@ -731,11 +731,10 @@ public:
|
|||
std::function<void()> PrintHeader);
|
||||
void printFunctionStackSize(const ELFObjectFile<ELFT> *Obj, uint64_t SymValue,
|
||||
Optional<SectionRef> FunctionSec,
|
||||
const StringRef SectionName, DataExtractor Data,
|
||||
const Elf_Shdr &StackSizeSec, DataExtractor Data,
|
||||
uint64_t *Offset);
|
||||
void printStackSize(const ELFObjectFile<ELFT> *Obj, RelocationRef Rel,
|
||||
SectionRef FunctionSec,
|
||||
const StringRef &StackSizeSectionName,
|
||||
SectionRef FunctionSec, const Elf_Shdr &StackSizeSec,
|
||||
const RelocationResolver &Resolver, DataExtractor Data);
|
||||
virtual void printStackSizeEntry(uint64_t Size, StringRef FuncName) = 0;
|
||||
virtual void printMipsGOT(const MipsGOTParser<ELFT> &Parser) = 0;
|
||||
|
@ -5596,7 +5595,7 @@ template <class ELFT>
|
|||
void DumpStyle<ELFT>::printFunctionStackSize(const ELFObjectFile<ELFT> *Obj,
|
||||
uint64_t SymValue,
|
||||
Optional<SectionRef> FunctionSec,
|
||||
const StringRef SectionName,
|
||||
const Elf_Shdr &StackSizeSec,
|
||||
DataExtractor Data,
|
||||
uint64_t *Offset) {
|
||||
// This function ignores potentially erroneous input, unless it is directly
|
||||
|
@ -5641,8 +5640,8 @@ void DumpStyle<ELFT>::printFunctionStackSize(const ELFObjectFile<ELFT> *Obj,
|
|||
if (*Offset == PrevOffset) {
|
||||
reportWarning(
|
||||
createStringError(object_error::parse_failed,
|
||||
"could not extract a valid stack size in section %s",
|
||||
SectionName.data()),
|
||||
"could not extract a valid stack size in " +
|
||||
describe(*Obj->getELFFile(), StackSizeSec)),
|
||||
Obj->getFileName());
|
||||
return;
|
||||
}
|
||||
|
@ -5662,7 +5661,7 @@ template <class ELFT>
|
|||
void DumpStyle<ELFT>::printStackSize(const ELFObjectFile<ELFT> *Obj,
|
||||
RelocationRef Reloc,
|
||||
SectionRef FunctionSec,
|
||||
const StringRef &StackSizeSectionName,
|
||||
const Elf_Shdr &StackSizeSec,
|
||||
const RelocationResolver &Resolver,
|
||||
DataExtractor Data) {
|
||||
// This function ignores potentially erroneous input, unless it is directly
|
||||
|
@ -5703,15 +5702,15 @@ void DumpStyle<ELFT>::printStackSize(const ELFObjectFile<ELFT> *Obj,
|
|||
reportUniqueWarning(createStringError(
|
||||
object_error::parse_failed,
|
||||
"found invalid relocation offset (0x" + Twine::utohexstr(Offset) +
|
||||
") into section " + StackSizeSectionName +
|
||||
") into " + describe(*Obj->getELFFile(), StackSizeSec) +
|
||||
" while trying to extract a stack size entry"));
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t Addend = Data.getAddress(&Offset);
|
||||
uint64_t SymValue = Resolver(Reloc, RelocSymValue, Addend);
|
||||
this->printFunctionStackSize(Obj, SymValue, FunctionSec, StackSizeSectionName,
|
||||
Data, &Offset);
|
||||
this->printFunctionStackSize(Obj, SymValue, FunctionSec, StackSizeSec, Data,
|
||||
&Offset);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
|
@ -5721,8 +5720,7 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
|
|||
// related to stack size reporting.
|
||||
const ELFFile<ELFT> *EF = Obj->getELFFile();
|
||||
for (const SectionRef &Sec : Obj->sections()) {
|
||||
StringRef SectionName = getSectionName(Sec);
|
||||
if (SectionName != ".stack_sizes")
|
||||
if (getSectionName(Sec) != ".stack_sizes")
|
||||
continue;
|
||||
PrintHeader();
|
||||
const Elf_Shdr *ElfSec = Obj->getSection(Sec.getRawDataRefImpl());
|
||||
|
@ -5741,8 +5739,8 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
|
|||
break;
|
||||
}
|
||||
uint64_t SymValue = Data.getAddress(&Offset);
|
||||
printFunctionStackSize(Obj, SymValue, /*FunctionSec=*/None, SectionName,
|
||||
Data, &Offset);
|
||||
printFunctionStackSize(Obj, SymValue, /*FunctionSec=*/None, *ElfSec, Data,
|
||||
&Offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5807,22 +5805,23 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
|
|||
PrintHeader();
|
||||
const SectionRef &StackSizesSec = StackSizeMapEntry.first;
|
||||
const SectionRef &RelocSec = StackSizeMapEntry.second;
|
||||
const Elf_Shdr *StackSizesELFSec =
|
||||
Obj->getSection(StackSizesSec.getRawDataRefImpl());
|
||||
|
||||
// Warn about stack size sections without a relocation section.
|
||||
StringRef StackSizeSectionName = getSectionName(StackSizesSec);
|
||||
if (RelocSec == NullSection) {
|
||||
reportWarning(createError("section " + StackSizeSectionName +
|
||||
" does not have a corresponding "
|
||||
"relocation section"),
|
||||
Obj->getFileName());
|
||||
reportWarning(
|
||||
createError(".stack_sizes (" +
|
||||
describe(*Obj->getELFFile(), *StackSizesELFSec) +
|
||||
") does not have a corresponding "
|
||||
"relocation section"),
|
||||
Obj->getFileName());
|
||||
continue;
|
||||
}
|
||||
|
||||
// A .stack_sizes section header's sh_link field is supposed to point
|
||||
// to the section that contains the functions whose stack sizes are
|
||||
// described in it.
|
||||
const Elf_Shdr *StackSizesELFSec =
|
||||
Obj->getSection(StackSizesSec.getRawDataRefImpl());
|
||||
const SectionRef FunctionSec = Obj->toSectionRef(unwrapOrError(
|
||||
this->FileName, EF->getSection(StackSizesELFSec->sh_link)));
|
||||
|
||||
|
@ -5844,8 +5843,8 @@ void DumpStyle<ELFT>::printRelocatableStackSizes(
|
|||
": " + EF->getRelocationTypeName(Reloc.getType())));
|
||||
continue;
|
||||
}
|
||||
this->printStackSize(Obj, Reloc, FunctionSec, StackSizeSectionName,
|
||||
Resolver, Data);
|
||||
this->printStackSize(Obj, Reloc, FunctionSec, *StackSizesELFSec, Resolver,
|
||||
Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue