summaryrefslogtreecommitdiff
path: root/third_party/llvm-project
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/llvm-project')
-rw-r--r--third_party/llvm-project/DWARFEmitter.cpp8
-rw-r--r--third_party/llvm-project/DWARFVisitor.cpp25
-rw-r--r--third_party/llvm-project/dwarf2yaml.cpp8
3 files changed, 31 insertions, 10 deletions
diff --git a/third_party/llvm-project/DWARFEmitter.cpp b/third_party/llvm-project/DWARFEmitter.cpp
index 92efcdfa0..6e4ee6119 100644
--- a/third_party/llvm-project/DWARFEmitter.cpp
+++ b/third_party/llvm-project/DWARFEmitter.cpp
@@ -78,6 +78,10 @@ void DWARFYAML::EmitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
void DWARFYAML::EmitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (auto AbbrevDecl : DI.AbbrevDecls) {
encodeULEB128(AbbrevDecl.Code, OS);
+ // XXX BINARYEN This is a terminator.
+ if (!AbbrevDecl.Code) {
+ continue;
+ }
encodeULEB128(AbbrevDecl.Tag, OS);
OS.write(AbbrevDecl.Children);
for (auto Attr : AbbrevDecl.Attributes) {
@@ -89,10 +93,6 @@ void DWARFYAML::EmitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
encodeULEB128(0, OS);
encodeULEB128(0, OS);
}
- // XXX BINARYEN: end the list with a zero. LLVM works with or without this,
- // but other decoders may error. See
- // https://bugs.llvm.org/show_bug.cgi?id=44511
- writeInteger((uint8_t)0, OS, true /* isLittleEndian */);
}
void DWARFYAML::EmitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
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 (;
diff --git a/third_party/llvm-project/dwarf2yaml.cpp b/third_party/llvm-project/dwarf2yaml.cpp
index b43b0e420..52e875637 100644
--- a/third_party/llvm-project/dwarf2yaml.cpp
+++ b/third_party/llvm-project/dwarf2yaml.cpp
@@ -43,6 +43,14 @@ void dumpDebugAbbrev(DWARFContext &DCtx, DWARFYAML::Data &Y) {
}
Y.AbbrevDecls.push_back(Abbrv);
}
+ // XXX BINARYEN: null-terminate the DeclSet. This is needed to separate
+ // DeclSets from each other, and to null-terminate the entire list
+ // (LLVM works with or without this, but other decoders may error, see
+ // https://bugs.llvm.org/show_bug.cgi?id=44511).
+ DWARFYAML::Abbrev Abbrv;
+ Abbrv.Code = 0;
+ Abbrv.Tag = dwarf::Tag(0);
+ Y.AbbrevDecls.push_back(Abbrv);
}
}
}