Skip to content

Commit

Permalink
DebugInfo: Hash DW_OP_convert in loclists when using Split DWARF
Browse files Browse the repository at this point in the history
This code was incorrectly emitting extra bytes into arbitrary parts of
the object file when it was meant to be hashing them to compute the DWO
ID.

Follow-up patch(es) will refactor this API somewhat to make such bugs
harder to introduce, hopefully.
  • Loading branch information
dwblaikie committed Feb 4, 2020
1 parent bc3f87c commit 1ced28c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/ByteStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class APByteStreamer final : public ByteStreamer {
}
void EmitULEB128(uint64_t DWord, const Twine &Comment, unsigned PadTo) override {
AP.OutStreamer->AddComment(Comment);
AP.EmitULEB128(DWord);
AP.EmitULEB128(DWord, nullptr, PadTo);
}
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,7 @@ void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
uint64_t Offset =
CU->ExprRefedBaseTypes[Op.getRawOperand(I)].Die->getOffset();
assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit");
Asm->EmitULEB128(Offset, nullptr, ULEB128PadSize);
Streamer.EmitULEB128(Offset, "", ULEB128PadSize);
// Make sure comments stay aligned.
for (unsigned J = 0; J < ULEB128PadSize; ++J)
if (Comment != End)
Expand Down
24 changes: 21 additions & 3 deletions llvm/test/DebugInfo/X86/convert-loclist.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
; RUN: llc -dwarf-version=5 -filetype=obj -O0 < %s | llvm-dwarfdump -debug-info -debug-loclists - | FileCheck %s
; RUN: llc -dwarf-version=5 -split-dwarf-file=foo.dwo -filetype=obj -O0 < %s | llvm-dwarfdump -debug-info -debug-loclists - | FileCheck %s
; RUN: llc -dwarf-version=5 -filetype=obj -O0 < %s \
; RUN: | llvm-dwarfdump -debug-info -debug-loclists - | FileCheck %s
; RUN: llc -dwarf-version=5 -split-dwarf-file=foo.dwo -filetype=obj -O0 < %s \
; RUN: | llvm-dwarfdump -debug-info -debug-loclists - | FileCheck --check-prefix=CHECK --check-prefix=SPLIT %s
; RUN: llc -dwarf-version=5 -split-dwarf-file=foo.dwo -filetype=asm -O0 < %s | FileCheck --check-prefix=ASM %s

; A bit of a brittle test - this is testing the specific DWO_id. The
; alternative would be to test two files with different DW_OP_convert values &
; ensuring the DWO IDs differ when the DW_OP_convert parameter differs.

; So if this test ends up being a brittle pain to maintain, updating the DWO ID
; often - add another IR file with a different DW_OP_convert that's otherwise
; identical and demonstrate that they have different DWO IDs.

; SPLIT: 0x00000000: Compile Unit: {{.*}} DWO_id = 0xafd73565c68bc661

; Regression testing a fairly quirky bug where instead of hashing (see above),
; extra bytes would be emitted into the output assembly in no
; particular/intentional section - so let's check they don't show up at all:
; ASM-NOT: .asciz "\200\200\200"

; CHECK: 0x{{0*}}[[TYPE:.*]]: DW_TAG_base_type
; CHECK-NEXT: DW_AT_name ("DW_ATE_unsigned_32")
; CHECK-NEXT: DW_AT_name ("DW_ATE_unsigned_32")

; CHECK: DW_LLE_offset_pair ({{.*}}): DW_OP_consts +7, DW_OP_convert 0x[[TYPE]], DW_OP_stack_value

Expand Down

0 comments on commit 1ced28c

Please sign in to comment.