summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo
diff options
context:
space:
mode:
authorSpyridoula Gravani <sgravani@apple.com>2017-06-14 00:17:55 +0000
committerSpyridoula Gravani <sgravani@apple.com>2017-06-14 00:17:55 +0000
commite41823bb894165a504c21b139a81445f6f55d4df (patch)
treeb04f20f5b73882b653ce7745ba89f67c05061ad6 /llvm/lib/DebugInfo
parent41def9b72c104408f2711dbfc82b27098c705fa0 (diff)
downloadbcm5719-llvm-e41823bb894165a504c21b139a81445f6f55d4df.tar.gz
bcm5719-llvm-e41823bb894165a504c21b139a81445f6f55d4df.zip
Added partial verification for .apple_names accelerator table in llvm-dwarfdump output.
This patch adds code which verifies that each bucket in the .apple_names accelerator table is either empty or has a valid hash index. Differential Revision: https://reviews.llvm.org/D34177 llvm-svn: 305344
Diffstat (limited to 'llvm/lib/DebugInfo')
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp7
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFContext.cpp5
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp34
3 files changed, 46 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index 97b52f0fbdd..87009bf1b6a 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -55,6 +55,13 @@ bool DWARFAcceleratorTable::extract() {
return true;
}
+uint32_t DWARFAcceleratorTable::getNumBuckets() { return Hdr.NumBuckets; }
+uint32_t DWARFAcceleratorTable::getNumHashes() { return Hdr.NumHashes; }
+uint32_t DWARFAcceleratorTable::getSizeHdr() { return sizeof(Hdr); }
+uint32_t DWARFAcceleratorTable::getHeaderDataLength() {
+ return Hdr.HeaderDataLength;
+}
+
LLVM_DUMP_METHOD void DWARFAcceleratorTable::dump(raw_ostream &OS) const {
// Dump the header.
OS << "Magic = " << format("0x%08x", Hdr.Magic) << '\n'
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index fb48253b2ad..ff9230d9d18 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -678,8 +678,13 @@ bool DWARFContext::verify(raw_ostream &OS, DIDumpType DumpType) {
if (!verifier.handleDebugLine())
Success = false;
}
+ if (DumpType == DIDT_All || DumpType == DIDT_AppleNames) {
+ if (!verifier.handleAppleNames())
+ Success = false;
+ }
return Success;
}
+
const DWARFUnitIndex &DWARFContext::getCUIndex() {
if (CUIndex)
return *CUIndex;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
index 8a544296f65..a6240fb6014 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -14,6 +14,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
+#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
#include "llvm/Support/raw_ostream.h"
#include <map>
#include <set>
@@ -275,3 +276,36 @@ bool DWARFVerifier::handleDebugLine() {
verifyDebugLineRows();
return NumDebugLineErrors == 0;
}
+
+bool DWARFVerifier::handleAppleNames() {
+ NumAppleNamesErrors = 0;
+ OS << "Verifying .apple_names...\n";
+
+ DataExtractor AppleNamesSection(DCtx.getAppleNamesSection().Data,
+ DCtx.isLittleEndian(), 0);
+ DataExtractor StrData(DCtx.getStringSection(), DCtx.isLittleEndian(), 0);
+ DWARFAcceleratorTable AppleNames(AppleNamesSection, StrData,
+ DCtx.getAppleNamesSection().Relocs);
+
+ if (!AppleNames.extract()) {
+ OS << "error: cannot extract .apple_names accelerator table\n";
+ return false;
+ }
+
+ // Verify that all buckets have a valid hash index or are empty
+ uint32_t NumBuckets = AppleNames.getNumBuckets();
+ uint32_t NumHashes = AppleNames.getNumHashes();
+
+ uint32_t BucketsOffset =
+ AppleNames.getSizeHdr() + AppleNames.getHeaderDataLength();
+
+ for (uint32_t BucketIdx = 0; BucketIdx < NumBuckets; ++BucketIdx) {
+ uint32_t HashIdx = AppleNamesSection.getU32(&BucketsOffset);
+ if (HashIdx >= NumHashes && HashIdx != UINT32_MAX) {
+ OS << format("error: Bucket[%d] has invalid hash index: [%d]\n",
+ BucketIdx, HashIdx);
+ ++NumAppleNamesErrors;
+ }
+ }
+ return NumAppleNamesErrors == 0;
+}
OpenPOWER on IntegriCloud