From b410773b502abfcd8cc225fe4cd36d84108c0aeb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 22 Sep 2020 08:44:31 -0700 Subject: DWARF: Fix abbreviation lookups, they are relative to 1 (#3158) Apparently I misunderstood the DWARF spec on this. Abbreviation offsets are all relative to 1 (as 0 is not a valid number). For some reason I thought the first DIE's index was the "base", as in practice LLVM always emits the lowest index there, and that's what the LLVM YAML code suggested to me. --- third_party/llvm-project/DWARFVisitor.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'third_party/llvm-project/DWARFVisitor.cpp') diff --git a/third_party/llvm-project/DWARFVisitor.cpp b/third_party/llvm-project/DWARFVisitor.cpp index 4b6ed5ada..22df78639 100644 --- a/third_party/llvm-project/DWARFVisitor.cpp +++ b/third_party/llvm-project/DWARFVisitor.cpp @@ -101,19 +101,19 @@ template void DWARFYAML::VisitorImpl::traverseDebugInfo() { 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 + AbbrevStart >= AbbrevEnd) { + // XXX BINARYEN valid abbreviation codes start from 1, so subtract that, + // and are relative to the start of the abbrev table + auto RelativeAbbrIndex = Entry.AbbrCode - 1 + AbbrevStart; + if (RelativeAbbrIndex >= AbbrevEnd) { errs() << "warning: invalid abbreviation code " << Entry.AbbrCode - << " (range: " << FirstAbbrevCode << " : " << AbbrevStart - << ".." << AbbrevEnd << ")\n"; + << " (range: " << AbbrevStart << ".." << AbbrevEnd << ")\n"; continue; } - auto &Abbrev = DebugInfo.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode + AbbrevStart]; + auto &Abbrev = DebugInfo.AbbrevDecls[RelativeAbbrIndex]; auto FormVal = Entry.Values.begin(); auto AbbrForm = Abbrev.Attributes.begin(); for (; -- cgit v1.2.3