[llvm-branch-commits] [llvm] 177779e - [llvm-readelf/obj] - Improve the warning reported when unable to read the stack size.
Georgii Rymar via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Dec 25 00:54:09 PST 2020
Author: Georgii Rymar
Date: 2020-12-25T11:40:35+03:00
New Revision: 177779e8dd9f7d20b96d4711a81d65ab7d480bb5
URL: https://github.com/llvm/llvm-project/commit/177779e8dd9f7d20b96d4711a81d65ab7d480bb5
DIFF: https://github.com/llvm/llvm-project/commit/177779e8dd9f7d20b96d4711a81d65ab7d480bb5.diff
LOG: [llvm-readelf/obj] - Improve the warning reported when unable to read the stack size.
It was discussed in D92545 that we might want to improve messages
reported when something is wrong with the stack size section.
This patch does it.
Differential revision: https://reviews.llvm.org/D93802
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test b/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
index 9d0c0b532e5e..8a8e481d8ff3 100644
--- a/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
+++ b/llvm/test/tools/llvm-readobj/ELF/stack-sizes.test
@@ -442,11 +442,13 @@ Symbols:
## 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:
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index fe2aad166250..8fbef39c5a25 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -759,7 +759,7 @@ template <typename ELFT> class DumpStyle {
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);
@@ -5833,7 +5833,7 @@ template <class ELFT> void GNUStyle<ELFT>::printDependentLibs() {
}
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;
@@ -5893,16 +5893,16 @@ void DumpStyle<ELFT>::printFunctionStackSize(
// 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>
@@ -5991,8 +5991,9 @@ void DumpStyle<ELFT>::printNonRelocatableStackSizes(
break;
}
uint64_t SymValue = Data.getAddress(&Offset);
- printFunctionStackSize(SymValue, /*FunctionSec=*/None, Sec, Data,
- &Offset);
+ if (!printFunctionStackSize(SymValue, /*FunctionSec=*/None, Sec, Data,
+ &Offset))
+ break;
}
}
}
More information about the llvm-branch-commits
mailing list