summaryrefslogtreecommitdiff
path: root/third_party/llvm-project
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-01-09 13:39:53 -0800
committerGitHub <noreply@github.com>2020-01-09 13:39:53 -0800
commit98747d97f089354091d115fb300006f3cc506a0c (patch)
tree441a8325cd91f6fe30653f4a0d69258db316b284 /third_party/llvm-project
parent77329439d6307d292e59986db3a194c3085abbe2 (diff)
downloadbinaryen-98747d97f089354091d115fb300006f3cc506a0c.tar.gz
binaryen-98747d97f089354091d115fb300006f3cc506a0c.tar.bz2
binaryen-98747d97f089354091d115fb300006f3cc506a0c.zip
DWARF support for multiple line tables (#2557)
Multiple tables appear to be emitted when linking files together. This fixes our support for that, which did not update their size properly. This required patching the YAML emitting code from LLVM in order to measure the size and then emit it, as that code is apparently not designed to handle changes in line table contents. Other minor fixes: * Set the flags for our dwarfdump command to emit the same as llvm-dwarfdump does with -v -all. * Add support for a few more opcodes, set_discriminator, set_basic_block, fixed_advance_pc, set_isa. * Handle a compile unit without abbreviations in the YAML code (again, apparently not something this LLVM code was intended to do). * Handle a compile unit with zero entries in the YAML code (ditto). * Properly set the AddressSize - we use the DWARFContext in a different way than LLVM expects, apparently. With this the emscripten test suite passes with -gforce_dwarf without crashing. My overall impression so from the the YAML code is that it probably isn't a long-term solution for us. Perhaps it may end up being scaffolding, that is, we can replace it with our own code eventually that is based on it, and remove most of the LLVM code. Before deciding that we should get everything working first, and this seems like the quickest path there.
Diffstat (limited to 'third_party/llvm-project')
-rw-r--r--third_party/llvm-project/DWARFCompileUnit.cpp8
-rw-r--r--third_party/llvm-project/DWARFContext.cpp4
-rw-r--r--third_party/llvm-project/DWARFDebugInfoEntry.cpp6
-rw-r--r--third_party/llvm-project/DWARFEmitter.cpp18
-rw-r--r--third_party/llvm-project/DWARFVisitor.cpp3
-rw-r--r--third_party/llvm-project/dwarf2yaml.cpp4
6 files changed, 35 insertions, 8 deletions
diff --git a/third_party/llvm-project/DWARFCompileUnit.cpp b/third_party/llvm-project/DWARFCompileUnit.cpp
index f59e49268..a9791f921 100644
--- a/third_party/llvm-project/DWARFCompileUnit.cpp
+++ b/third_party/llvm-project/DWARFCompileUnit.cpp
@@ -20,9 +20,11 @@ void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
<< " version = " << format("0x%04x", getVersion());
if (getVersion() >= 5)
OS << " unit_type = " << dwarf::UnitTypeString(getUnitType());
- OS << " abbr_offset = "
- << format("0x%04" PRIx64, getAbbreviations()->getOffset())
- << " addr_size = " << format("0x%02x", getAddressByteSize());
+ if (auto* Abbreviations = getAbbreviations()) { // XXX BINARYEN
+ OS << " abbr_offset = "
+ << format("0x%04" PRIx64, Abbreviations->getOffset());
+ }
+ OS << " addr_size = " << format("0x%02x", getAddressByteSize());
if (getVersion() >= 5 && getUnitType() != dwarf::DW_UT_compile)
OS << " DWO_id = " << format("0x%016" PRIx64, *getDWOId());
OS << " (next unit at " << format("0x%08" PRIx64, getNextUnitOffset())
diff --git a/third_party/llvm-project/DWARFContext.cpp b/third_party/llvm-project/DWARFContext.cpp
index da865a2c3..64c153bfa 100644
--- a/third_party/llvm-project/DWARFContext.cpp
+++ b/third_party/llvm-project/DWARFContext.cpp
@@ -1507,7 +1507,9 @@ class DWARFObjInMemory final : public DWARFObject {
public:
DWARFObjInMemory(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
uint8_t AddrSize, bool IsLittleEndian)
- : IsLittleEndian(IsLittleEndian) {
+ : IsLittleEndian(IsLittleEndian),
+ AddressSize(4) // XXX BINARYEN
+ {
for (const auto &SecIt : Sections) {
if (StringRef *SectionData = mapSectionToMember(SecIt.first()))
*SectionData = SecIt.second->getBuffer();
diff --git a/third_party/llvm-project/DWARFDebugInfoEntry.cpp b/third_party/llvm-project/DWARFDebugInfoEntry.cpp
index 87eab34d5..2da854fe2 100644
--- a/third_party/llvm-project/DWARFDebugInfoEntry.cpp
+++ b/third_party/llvm-project/DWARFDebugInfoEntry.cpp
@@ -38,7 +38,11 @@ bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
AbbrevDecl = nullptr;
return true;
}
- AbbrevDecl = U.getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
+ if (auto* Abbreviations = U.getAbbreviations()) { // XXX BINARYEN
+ AbbrevDecl = Abbreviations->getAbbreviationDeclaration(AbbrCode);
+ } else {
+ AbbrevDecl = nullptr; // XXX BINARYEN
+ }
if (nullptr == AbbrevDecl) {
// Restore the original offset.
*OffsetPtr = Offset;
diff --git a/third_party/llvm-project/DWARFEmitter.cpp b/third_party/llvm-project/DWARFEmitter.cpp
index dbaa06111..79f988498 100644
--- a/third_party/llvm-project/DWARFEmitter.cpp
+++ b/third_party/llvm-project/DWARFEmitter.cpp
@@ -221,9 +221,15 @@ static void EmitFileEntry(raw_ostream &OS, const DWARFYAML::File &File) {
encodeULEB128(File.Length, OS);
}
-void DWARFYAML::EmitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
+void DWARFYAML::EmitDebugLine(raw_ostream &RealOS, const DWARFYAML::Data &DI) {
for (const auto &LineTable : DI.DebugLines) {
- writeInitialLength(LineTable.Length, OS, DI.IsLittleEndian);
+ // XXX BINARYEN We need to update each line table's length. Write to a
+ // temp stream first, then get the size from that.
+ std::string Buffer;
+ raw_string_ostream OS(Buffer);
+
+ // XXX BINARYEN writeInitialLength(LineTable.Length, OS, DI.IsLittleEndian);
+
uint64_t SizeOfPrologueLength = LineTable.Length.isDWARF64() ? 8 : 4;
writeInteger((uint16_t)LineTable.Version, OS, DI.IsLittleEndian);
writeVariableSizedInteger(LineTable.PrologueLength, SizeOfPrologueLength,
@@ -301,6 +307,14 @@ void DWARFYAML::EmitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
}
}
}
+ // XXX BINARYEN Write to the actual stream, with the proper size.
+ // We assume for now that the length fits in 32 bits.
+ size_t Size = OS.str().size();
+ if (Size >= UINT32_MAX) {
+ llvm_unreachable("Table is too big");
+ }
+ writeInteger((uint32_t)Size, RealOS, DI.IsLittleEndian);
+ RealOS << OS.str();
}
}
diff --git a/third_party/llvm-project/DWARFVisitor.cpp b/third_party/llvm-project/DWARFVisitor.cpp
index ecb5967ac..35d5ccf57 100644
--- a/third_party/llvm-project/DWARFVisitor.cpp
+++ b/third_party/llvm-project/DWARFVisitor.cpp
@@ -46,6 +46,9 @@ static unsigned getRefSize(const DWARFYAML::Unit &Unit) {
template <typename T> void DWARFYAML::VisitorImpl<T>::traverseDebugInfo() {
for (auto &Unit : DebugInfo.CompileUnits) {
onStartCompileUnit(Unit);
+ if (Unit.Entries.empty()) { // XXX BINARYEN
+ continue;
+ }
auto FirstAbbrevCode = Unit.Entries[0].AbbrCode;
for (auto &Entry : Unit.Entries) {
diff --git a/third_party/llvm-project/dwarf2yaml.cpp b/third_party/llvm-project/dwarf2yaml.cpp
index bdaf1e429..7d5f2e048 100644
--- a/third_party/llvm-project/dwarf2yaml.cpp
+++ b/third_party/llvm-project/dwarf2yaml.cpp
@@ -146,7 +146,9 @@ void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
NewUnit.Version = CU->getVersion();
if(NewUnit.Version >= 5)
NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
- NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
+ if (auto* Abbreviations = CU->getAbbreviations()) { // XXX BINARYEN
+ NewUnit.AbbrOffset = Abbreviations->getOffset();
+ }
NewUnit.AddrSize = CU->getAddressByteSize();
for (auto DIE : CU->dies()) {
DWARFYAML::Entry NewEntry;