summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2017-12-11 18:22:47 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2017-12-11 18:22:47 +0000
commitba915897daebc34fa4e988e3e4c401ef122d68ce (patch)
tree1a176391c7481de445c0ed78c3360c1ebdf9f495 /llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
parent6c4835978a1ece85d1ea26bddc9dcc73876f6b10 (diff)
downloadbcm5719-llvm-ba915897daebc34fa4e988e3e4c401ef122d68ce.tar.gz
bcm5719-llvm-ba915897daebc34fa4e988e3e4c401ef122d68ce.zip
[dwarfdump] Fix off-by-one bug in accelerator table extractor.
This fixes a bug where the verifier was complaining about empty accelerator tables. When the table is empty, its size is not a valid offset as it points after the end of the section. This patch also makes the extractor return llvm:Error instead of bool for better error reporting in the verifier. Differential revision: https://reviews.llvm.org/D41063 rdar://35932007 llvm-svn: 320399
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index f04ec7706cd..670191418cd 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -22,12 +22,13 @@
using namespace llvm;
-bool DWARFAcceleratorTable::extract() {
+llvm::Error DWARFAcceleratorTable::extract() {
uint32_t Offset = 0;
// Check that we can at least read the header.
if (!AccelSection.isValidOffset(offsetof(Header, HeaderDataLength)+4))
- return false;
+ return make_error<StringError>("Section too small: cannot read header.",
+ inconvertibleErrorCode());
Hdr.Magic = AccelSection.getU32(&Offset);
Hdr.Version = AccelSection.getU16(&Offset);
@@ -38,9 +39,13 @@ bool DWARFAcceleratorTable::extract() {
// Check that we can read all the hashes and offsets from the
// section (see SourceLevelDebugging.rst for the structure of the index).
+ // We need to substract one because we're checking for an *offset* which is
+ // equal to the size for an empty table and hence pointer after the section.
if (!AccelSection.isValidOffset(sizeof(Hdr) + Hdr.HeaderDataLength +
- Hdr.NumBuckets*4 + Hdr.NumHashes*8))
- return false;
+ Hdr.NumBuckets * 4 + Hdr.NumHashes * 8 - 1))
+ return make_error<StringError>(
+ "Section too small: cannot read buckets and hashes.",
+ inconvertibleErrorCode());
HdrData.DIEOffsetBase = AccelSection.getU32(&Offset);
uint32_t NumAtoms = AccelSection.getU32(&Offset);
@@ -52,7 +57,7 @@ bool DWARFAcceleratorTable::extract() {
}
IsValid = true;
- return true;
+ return Error::success();
}
uint32_t DWARFAcceleratorTable::getNumBuckets() { return Hdr.NumBuckets; }
OpenPOWER on IntegriCloud