diff options
author | Alon Zakai <azakai@google.com> | 2020-01-28 10:45:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-28 10:45:48 -0800 |
commit | 9384ff68eea8090578354bab35fce2e621a588c4 (patch) | |
tree | 3ba04c14502f6fdbe552ba283cfa0287728f77cb /third_party/llvm-project/DWARFVisitor.cpp | |
parent | b00f7f9b97631b214eff177b92639df6307db286 (diff) | |
download | binaryen-9384ff68eea8090578354bab35fce2e621a588c4.tar.gz binaryen-9384ff68eea8090578354bab35fce2e621a588c4.tar.bz2 binaryen-9384ff68eea8090578354bab35fce2e621a588c4.zip |
DWARF: Fix debug_abbrev section (#2630)
Each compilation unit's abbreviations must be terminated by
a zero, so that we use the right abbreviations. This adds that
support to the YAML layer, both adding the zeros and parsing
them to look in the right abbreviation section at the right time.
Also add two large testcases, zlib and cubescript, which
crash without this and the last PR.
Diffstat (limited to 'third_party/llvm-project/DWARFVisitor.cpp')
-rw-r--r-- | third_party/llvm-project/DWARFVisitor.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/third_party/llvm-project/DWARFVisitor.cpp b/third_party/llvm-project/DWARFVisitor.cpp index 05c4194e3..44bb33b47 100644 --- a/third_party/llvm-project/DWARFVisitor.cpp +++ b/third_party/llvm-project/DWARFVisitor.cpp @@ -44,25 +44,38 @@ static unsigned getRefSize(const DWARFYAML::Unit &Unit) { } template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() { + // XXX BINARYEN: Handle multiple linked compile units. Each one has its own + // range of values, terminated by a zero. AbbrevStart refers to the start + // index for the current unit, and AbbrevEnd to one past the last one + // (which is the index of the 0 terminator). + // TODO: This code appears to assume that abbreviation codes increment by 1 + // so that lookups are linear. In LLVM output that is true, but it might not + // be in general. + size_t AbbrevStart = 0, AbbrevEnd = -1; for (auto &Unit : DebugInfo.CompileUnits) { + // Skip the 0 terminator. + AbbrevEnd = AbbrevStart = AbbrevEnd + 1; + while (AbbrevEnd < DebugInfo.AbbrevDecls.size() && + DebugInfo.AbbrevDecls[AbbrevEnd].Code) { + AbbrevEnd++; + } onStartCompileUnit(Unit); if (Unit.Entries.empty()) { // XXX BINARYEN continue; } auto FirstAbbrevCode = Unit.Entries[0].AbbrCode; - for (auto &Entry : Unit.Entries) { 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"; + if (Entry.AbbrCode - FirstAbbrevCode + AbbrevStart >= AbbrevEnd) { + errs() << "warning: invalid abbreviation code " << Entry.AbbrCode + << " (range: " << FirstAbbrevCode << " : " << AbbrevStart + << ".." << AbbrevEnd << ")\n"; continue; } - auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode]; + auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode + AbbrevStart]; auto FormVal = Entry.Values.begin(); auto AbbrForm = Abbrev.Attributes.begin(); for (; |