From 647ef50fc4de9b5c49ffad1aec4271e79b171785 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 18 Mar 2021 11:41:51 -0700 Subject: 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 --- src/wasm/wasm-debug.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') 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 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]); } -- cgit v1.2.3