diff --git a/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test b/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test --- a/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test +++ b/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test @@ -186,7 +186,7 @@ # 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 @@ # 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 @@ # 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 @@ # 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: diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -731,11 +731,10 @@ std::function PrintHeader); void printFunctionStackSize(const ELFObjectFile *Obj, uint64_t SymValue, Optional FunctionSec, - const StringRef SectionName, DataExtractor Data, + const Elf_Shdr &StackSizeSec, DataExtractor Data, uint64_t *Offset); void printStackSize(const ELFObjectFile *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 &Parser) = 0; @@ -5596,7 +5595,7 @@ void DumpStyle::printFunctionStackSize(const ELFObjectFile *Obj, uint64_t SymValue, Optional 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 @@ 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 @@ void DumpStyle::printStackSize(const ELFObjectFile *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 @@ 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 @@ -5721,8 +5720,7 @@ // related to stack size reporting. const ELFFile *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 @@ 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 @@ 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 @@ ": " + EF->getRelocationTypeName(Reloc.getType()))); continue; } - this->printStackSize(Obj, Reloc, FunctionSec, StackSizeSectionName, - Resolver, Data); + this->printStackSize(Obj, Reloc, FunctionSec, *StackSizesELFSec, Resolver, + Data); } } }