diff options
author | Alon Zakai <azakai@google.com> | 2020-01-21 17:24:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-21 17:24:01 -0800 |
commit | 51fff211d7aae002ff28e1c6245e3f9349493f11 (patch) | |
tree | 74268f2442f95d440a9274a2aafb3564bad5cbb5 | |
parent | 52550c26325ff3d6649fa84c83bf8d4ce9ad4fde (diff) | |
download | binaryen-51fff211d7aae002ff28e1c6245e3f9349493f11.tar.gz binaryen-51fff211d7aae002ff28e1c6245e3f9349493f11.tar.bz2 binaryen-51fff211d7aae002ff28e1c6245e3f9349493f11.zip |
Handle an invalid AbbrCode in DWARF handling (#2607)
Fixes the testcase in #2343 (comment)
Looks like that's from Rust. Not sure why it would have an invalid
abbreviation code, but perhaps the LLVM there emits dwarf differently
than we've tested on so far. May be worth investigating further, but
for now emit a warning, skip that element, and don't crash.
Also fix valgrind warnings about Span values not being initialized,
which was invalid and bad as well (wasted memory in our maps,
and might have overlapped with real values), and interfered with
figuring this out.
-rw-r--r-- | src/wasm.h | 2 | ||||
-rw-r--r-- | third_party/llvm-project/DWARFVisitor.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/wasm.h b/src/wasm.h index 9aafb7425..8b60885e3 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1170,7 +1170,7 @@ using BinaryLocation = uint32_t; // Offsets are relative to the beginning of the code section, as in DWARF. struct BinaryLocations { struct Span { - BinaryLocation start, end; + BinaryLocation start = 0, end = 0; }; std::unordered_map<Expression*, Span> expressions; std::unordered_map<Function*, Span> functions; diff --git a/third_party/llvm-project/DWARFVisitor.cpp b/third_party/llvm-project/DWARFVisitor.cpp index 35d5ccf57..05c4194e3 100644 --- a/third_party/llvm-project/DWARFVisitor.cpp +++ b/third_party/llvm-project/DWARFVisitor.cpp @@ -55,6 +55,13 @@ template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() { onStartDIE(Unit, Entry); if (Entry.AbbrCode == 0u) continue; + // XXX BINARYEN + if (Entry.AbbrCode - FirstAbbrevCode >= DebugInfo.AbbrevDecls.size()) { + errs() << "warning: invalid abbreviation code " << Entry.AbbrCode << + " (range: " << FirstAbbrevCode << "-" << + (DebugInfo.AbbrevDecls.size() - FirstAbbrevCode) << ")\n"; + continue; + } auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode]; auto FormVal = Entry.Values.begin(); auto AbbrForm = Abbrev.Attributes.begin(); |