summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-18 11:41:51 -0700
committerGitHub <noreply@github.com>2021-03-18 11:41:51 -0700
commit647ef50fc4de9b5c49ffad1aec4271e79b171785 (patch)
tree7a84ea338982d1fbfeb19c7163984c6b93416698
parent8ea6e13fe18b69419411edfd979ce15302820da2 (diff)
downloadbinaryen-647ef50fc4de9b5c49ffad1aec4271e79b171785.tar.gz
binaryen-647ef50fc4de9b5c49ffad1aec4271e79b171785.tar.bz2
binaryen-647ef50fc4de9b5c49ffad1aec4271e79b171785.zip
Ignore missing CUs in DWARF rewriting (#3700)
A recent change in LLVM causes it to sometimes end up with a thing with no parent. That is, a debug_line or a debug_loc that has no CU that refers to it. This is perhaps LLVM DCEing CUs, or something else that changed - not sure. But it seems like valid DWARF we should handle. This PR handles that in our code. Two things broke here. First, locs must be simply ignored when there is no CU. Second, lines are trickier as we used to compute their position by scanning them, and that list contained only ones with a CU. So we missed some and ended up with wrong offsets. To make things simpler and more robust, just track the position of each line table on itself. Fixes #3697
-rw-r--r--src/wasm/wasm-debug.cpp10
-rw-r--r--third_party/llvm-project/dwarf2yaml.cpp2
-rw-r--r--third_party/llvm-project/include/llvm/ObjectYAML/DWARFYAML.h1
3 files changed, 11 insertions, 2 deletions
diff --git a/src/wasm/wasm-debug.cpp b/src/wasm/wasm-debug.cpp
index 867f4b14b..60e97a27e 100644
--- a/src/wasm/wasm-debug.cpp
+++ b/src/wasm/wasm-debug.cpp
@@ -629,6 +629,11 @@ struct LocationUpdater {
// Given an offset in .debug_loc, get the old and new compile unit bases.
OldToNew getCompileUnitBasesForLoc(size_t offset) const {
+ if (locToUnitMap.count(offset) == 0) {
+ // There is no compile unit for this loc. It doesn't matter what we set
+ // here.
+ return OldToNew{0, 0};
+ }
auto index = locToUnitMap.at(offset);
auto iter = compileUnitBases.find(index);
if (iter != compileUnitBases.end()) {
@@ -754,11 +759,12 @@ static void updateDebugLines(llvm::DWARFYAML::Data& data,
// debug_line section.
std::vector<size_t> computedLengths;
llvm::DWARFYAML::ComputeDebugLine(data, computedLengths);
- BinaryLocation oldLocation = 0, newLocation = 0;
+ BinaryLocation newLocation = 0;
for (size_t i = 0; i < data.DebugLines.size(); i++) {
auto& table = data.DebugLines[i];
+ auto oldLocation = table.Position;
locationUpdater.debugLineMap[oldLocation] = newLocation;
- oldLocation += table.Length.getLength() + AddressSize;
+ table.Position = newLocation;
newLocation += computedLengths[i] + AddressSize;
table.Length.setLength(computedLengths[i]);
}
diff --git a/third_party/llvm-project/dwarf2yaml.cpp b/third_party/llvm-project/dwarf2yaml.cpp
index eed340964..6ba73d1ec 100644
--- a/third_party/llvm-project/dwarf2yaml.cpp
+++ b/third_party/llvm-project/dwarf2yaml.cpp
@@ -325,6 +325,8 @@ void dumpDebugLines(DWARFContext &DCtx, DWARFYAML::Data &Y) {
DataExtractor LineData(DCtx.getDWARFObj().getLineSection().Data,
DCtx.isLittleEndian(), CU->getAddressByteSize());
uint64_t Offset = *StmtOffset;
+ DebugLines.Position = Offset;
+
dumpInitialLength(LineData, Offset, DebugLines.Length);
uint64_t LineTableLength = DebugLines.Length.getLength();
uint64_t SizeOfPrologueLength = DebugLines.Length.isDWARF64() ? 8 : 4;
diff --git a/third_party/llvm-project/include/llvm/ObjectYAML/DWARFYAML.h b/third_party/llvm-project/include/llvm/ObjectYAML/DWARFYAML.h
index 510610123..bb66565a5 100644
--- a/third_party/llvm-project/include/llvm/ObjectYAML/DWARFYAML.h
+++ b/third_party/llvm-project/include/llvm/ObjectYAML/DWARFYAML.h
@@ -151,6 +151,7 @@ struct LineTableOpcode {
};
struct LineTable {
+ uint64_t Position; // XXX BINARYEN: the binary location in .debug_line
InitialLength Length;
uint16_t Version;
uint64_t PrologueLength;