Skip to content

Commit 70a6817

Browse files
authored
DWARF: Fix debug lines in fannkuch -O0 (#2611)
Just some trivial fixes: * Properly reset prologue after each line (unlike others, this flag should be reset immediately). * Test for a function's end address first, as LLVM output appears to use 1-past-the-end-of-the-function as a location in that function, and not the next (note the first byte of the next function, which is ambiguously identical to that value, is used at least in low_pc; I'm not sure if it's used in debug lines too). * Ignore the same address if LLVM emitted it more than once, which it does sometimes.
1 parent ed3277a commit 70a6817

File tree

5 files changed

+10478
-300
lines changed

5 files changed

+10478
-300
lines changed

src/wasm/wasm-debug.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ struct LineState {
118118
uint32_t discriminator = 0;
119119
bool isStmt;
120120
bool basicBlock = false;
121-
// XXX these two should be just prologue, epilogue?
122121
bool prologueEnd = false;
123122
bool epilogueBegin = false;
124123
bool endSequence = false;
@@ -314,8 +313,12 @@ struct LineState {
314313
newOpcodes.push_back(makeItem(llvm::dwarf::DW_LNS_copy));
315314
}
316315
}
316+
resetAfterLine();
317317
}
318318

319+
// Some flags are automatically reset after each debug line.
320+
void resetAfterLine() { prologueEnd = false; }
321+
319322
private:
320323
llvm::DWARFYAML::LineTableOpcode makeItem(llvm::dwarf::LineNumberOps opcode) {
321324
llvm::DWARFYAML::LineTableOpcode item = {};
@@ -597,21 +600,32 @@ static void updateDebugLines(llvm::DWARFYAML::Data& data,
597600
BinaryLocation newAddr = 0;
598601
if (locationUpdater.hasOldExprAddr(oldAddr)) {
599602
newAddr = locationUpdater.getNewExprAddr(oldAddr);
603+
}
604+
// Test for a function's end address first, as LLVM output appears to
605+
// use 1-past-the-end-of-the-function as a location in that function,
606+
// and not the next (but the first byte of the next function, which is
607+
// ambiguously identical to that value, is used at least in low_pc).
608+
else if (locationUpdater.hasOldFuncEndAddr(oldAddr)) {
609+
newAddr = locationUpdater.getNewFuncEndAddr(oldAddr);
600610
} else if (locationUpdater.hasOldFuncStartAddr(oldAddr)) {
601611
newAddr = locationUpdater.getNewFuncStartAddr(oldAddr);
602-
} else if (locationUpdater.hasOldFuncEndAddr(oldAddr)) {
603-
newAddr = locationUpdater.getNewFuncEndAddr(oldAddr);
604612
} else if (locationUpdater.hasOldExtraAddr(oldAddr)) {
605613
newAddr = locationUpdater.getNewExtraAddr(oldAddr);
606614
}
607615
// TODO: last 'end' of a function
608616
if (newAddr) {
617+
// LLVM sometimes emits the same address more than once. We should
618+
// probably investigate that.
619+
if (newAddrInfo.count(newAddr)) {
620+
continue;
621+
}
609622
newAddrs.push_back(newAddr);
610-
assert(newAddrInfo.count(newAddr) == 0);
611623
newAddrInfo.emplace(newAddr, state);
612624
auto& updatedState = newAddrInfo.at(newAddr);
613625
// The only difference is the address TODO other stuff?
614626
updatedState.addr = newAddr;
627+
// Reset relevant state.
628+
state.resetAfterLine();
615629
}
616630
if (opcode.Opcode == 0 &&
617631
opcode.SubOpcode == llvm::dwarf::DW_LNE_end_sequence) {
@@ -765,8 +779,6 @@ void writeDWARFSections(Module& wasm, const BinaryLocations& newLocations) {
765779

766780
updateCompileUnits(info, data, locationUpdater);
767781

768-
// TODO: Actually update, and remove sections we don't know how to update yet?
769-
770782
// Convert to binary sections.
771783
auto newSections =
772784
EmitDebugSections(data, false /* EmitFixups for debug_info */);

0 commit comments

Comments
 (0)