Skip to content

Commit

Permalink
Fix off-by-one error in DWARF reg-reg location (dotnet#317)
Browse files Browse the repository at this point in the history
The DWARF specification states that the form of an exprloc consists
of an unsigned LEB128 length value, followed by the encoded location bytes
of the specified length. For some reason we were adding one to the length
value being emitted. This looks incorrect to me. The above calculation for
REG-REG (a variable stored in two registers) correctly calculates the length
of each register type tag, plus the size of the interpolating PIECE tags,
plus the size of notation for each register. The extra byte looks wrong.

I've tested this locally and it appears to resolve dotnet/runtime#77407.

Unfortunately, it also causes llvm-dwarfdump --verify to constantly
complain about missing base addresses. I can't confirm at the moment,
but my suspicion is that this is revealing an existing bug. Even if this
is somehow causing a new bug, I think the resulting symbols with this
change are better than the alternative (no working symbols at all).
  • Loading branch information
agocke authored and MichalStrehovsky committed Nov 17, 2022
1 parent a2dc426 commit b404f37
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/tools/objwriter/debugInfo/dwarf/dwarfGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ static void EmitVarLocation(MCObjectStreamer *Streamer,
if (IsLocList) {
Streamer->emitIntValue(Len, 2);
} else {
Streamer->emitULEB128IntValue(Len + 1);
Streamer->emitULEB128IntValue(Len);
}

EmitReg(Streamer, DwarfRegNum2);
Expand Down

0 comments on commit b404f37

Please sign in to comment.