Index: llvm/test/tools/llvm-readobj/ELF/stack-sizes.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/stack-sizes.test +++ 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: Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -739,11 +739,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; @@ -5649,7 +5648,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 @@ -5694,8 +5693,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; } @@ -5715,7 +5714,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 @@ -5756,15 +5755,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 @@ -5774,8 +5773,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()); @@ -5794,8 +5792,8 @@ break; } uint64_t SymValue = Data.getAddress(&Offset); - printFunctionStackSize(Obj, SymValue, /*FunctionSec=*/None, SectionName, - Data, &Offset); + printFunctionStackSize(Obj, SymValue, /*FunctionSec=*/None, *ElfSec, Data, + &Offset); } } } @@ -5860,12 +5858,14 @@ 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 " + reportWarning(createError(".stack_sizes (" + + describe(Obj->getELFFile(), *StackSizesELFSec) + + ") does not have a corresponding " "relocation section"), Obj->getFileName()); continue; @@ -5874,8 +5874,6 @@ // 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))); @@ -5897,8 +5895,8 @@ ": " + EF->getRelocationTypeName(Reloc.getType()))); continue; } - this->printStackSize(Obj, Reloc, FunctionSec, StackSizeSectionName, - Resolver, Data); + this->printStackSize(Obj, Reloc, FunctionSec, *StackSizesELFSec, Resolver, + Data); } } }