summaryrefslogtreecommitdiff
path: root/src
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 /src
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
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-debug.cpp10
1 files changed, 8 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]);
}