[PATCH] D93802: [llvm-readelf/obj] - Improve the warning reported when unable to read the stack size.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 24 04:55:03 PST 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
grimar requested review of this revision.
Herald added a project: LLVM.
It was discussed in D92545 <https://reviews.llvm.org/D92545> that we might want to improve messages
reported when something is wrong with the stack size section.
This patch does it.
https://reviews.llvm.org/D93802
Files:
llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
llvm/tools/llvm-readobj/ELFDumper.cpp
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<void()> PrintHeader);
void printRelocatableStackSizes(std::function<void()> PrintHeader);
- void printFunctionStackSize(uint64_t SymValue,
+ bool printFunctionStackSize(uint64_t SymValue,
Optional<const Elf_Shdr *> FunctionSec,
const Elf_Shdr &StackSizeSec, DataExtractor Data,
uint64_t *Offset);
@@ -5862,7 +5862,7 @@
}
template <class ELFT>
-void DumpStyle<ELFT>::printFunctionStackSize(
+bool DumpStyle<ELFT>::printFunctionStackSize(
uint64_t SymValue, Optional<const Elf_Shdr *> 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 <class ELFT>
@@ -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;
}
}
}
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93802.313686.patch
Type: text/x-patch
Size: 3644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201224/f89059eb/attachment.bin>
More information about the llvm-commits
mailing list