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 @@ -442,11 +442,13 @@ ## ends in a byte with the high bit set. # RUN: yaml2obj --docnum=6 %s -o %t06 -# 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 +# RUN: llvm-readelf --stack-sizes %t06 2>&1 | \ +# RUN: FileCheck %s --check-prefix=BADSIZE -DFILE=%t06 --implicit-check-not=warning: +# RUN: llvm-readobj --stack-sizes %t06 2>&1 | \ +# RUN: FileCheck %s --check-prefix=BADSIZE -DFILE=%t06 --implicit-check-not=warning: -# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 2 -# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 3 +# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 2: unable to decode LEB128 at offset 0x00000008: malformed uleb128, extends past end +# BADSIZE: warning: '[[FILE]]': could not extract a valid stack size from SHT_PROGBITS section with index 3: unable to decode LEB128 at offset 0x00000008: malformed uleb128, extends past end --- !ELF FileHeader: Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -788,7 +788,7 @@ virtual void printStackSizes() = 0; void printNonRelocatableStackSizes(std::function PrintHeader); void printRelocatableStackSizes(std::function PrintHeader); - void printFunctionStackSize(uint64_t SymValue, + bool printFunctionStackSize(uint64_t SymValue, Optional FunctionSec, const Elf_Shdr &StackSizeSec, DataExtractor Data, uint64_t *Offset); @@ -5862,7 +5862,7 @@ } template -void DumpStyle::printFunctionStackSize( +bool DumpStyle::printFunctionStackSize( uint64_t SymValue, Optional FunctionSec, const Elf_Shdr &StackSizeSec, DataExtractor Data, uint64_t *Offset) { uint32_t FuncSymIndex = 0; @@ -5922,16 +5922,16 @@ // Extract the size. The expectation is that Offset is pointing to the right // place, i.e. past the function address. - uint64_t PrevOffset = *Offset; - uint64_t StackSize = Data.getULEB128(Offset); - // getULEB128() does not advance Offset if it is not able to extract a valid - // integer. - if (*Offset == PrevOffset) { + Error Err = Error::success(); + uint64_t StackSize = Data.getULEB128(Offset, &Err); + if (Err) { reportUniqueWarning("could not extract a valid stack size from " + - describe(Obj, StackSizeSec)); - return; + describe(Obj, StackSizeSec) + ": " + + toString(std::move(Err))); + return false; } printStackSizeEntry(StackSize, FuncName); + return true; } template @@ -6020,8 +6020,9 @@ break; } uint64_t SymValue = Data.getAddress(&Offset); - printFunctionStackSize(SymValue, /*FunctionSec=*/None, Sec, Data, - &Offset); + if (!printFunctionStackSize(SymValue, /*FunctionSec=*/None, Sec, Data, + &Offset)) + break; } } }