Skip to content

[DWARFLinker] Preserve DWARF discriminators while linking #96124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ void DwarfStreamer::emitLineTableRows(
unsigned FileNum = 1;
unsigned LastLine = 1;
unsigned Column = 0;
unsigned Discriminator = 0;
unsigned IsStatement = 1;
unsigned Isa = 0;
uint64_t Address = -1ULL;
Expand Down Expand Up @@ -1098,9 +1099,17 @@ void DwarfStreamer::emitLineTableRows(
MS->emitULEB128IntValue(Column);
LineSectionSize += 1 + getULEB128Size(Column);
}

// FIXME: We should handle the discriminator here, but dsymutil doesn't
// consider it, thus ignore it for now.
if (Discriminator != Row.Discriminator &&
MS->getContext().getDwarfVersion() >= 4) {
Discriminator = Row.Discriminator;
unsigned Size = getULEB128Size(Discriminator);
MS->emitIntValue(dwarf::DW_LNS_extended_op, 1);
MS->emitULEB128IntValue(Size + 1);
MS->emitIntValue(dwarf::DW_LNE_set_discriminator, 1);
MS->emitULEB128IntValue(Discriminator);
LineSectionSize += /* extended op */ 1 + getULEB128Size(Size + 1) +
/* discriminator */ 1 + Size;
}

if (Isa != Row.Isa) {
Isa = Row.Isa;
Expand Down Expand Up @@ -1156,7 +1165,7 @@ void DwarfStreamer::emitLineTableRows(
EncodingBuffer.resize(0);
Address = -1ULL;
LastLine = FileNum = IsStatement = 1;
RowsSinceLastSequence = Column = Isa = 0;
RowsSinceLastSequence = Column = Discriminator = Isa = 0;
}
}

Expand Down
14 changes: 10 additions & 4 deletions llvm/lib/DWARFLinker/Parallel/DebugLineSectionEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class DebugLineSectionEmitter {
unsigned FileNum = 1;
unsigned LastLine = 1;
unsigned Column = 0;
unsigned Discriminator = 0;
unsigned IsStatement = 1;
unsigned Isa = 0;
uint64_t Address = -1ULL;
Expand Down Expand Up @@ -350,9 +351,14 @@ class DebugLineSectionEmitter {
Section.emitIntVal(dwarf::DW_LNS_set_column, 1);
encodeULEB128(Column, Section.OS);
}

// FIXME: We should handle the discriminator here, but dsymutil doesn't
// consider it, thus ignore it for now.
if (Discriminator != Row.Discriminator && MC->getDwarfVersion() >= 4) {
Discriminator = Row.Discriminator;
unsigned Size = getULEB128Size(Discriminator);
Section.emitIntVal(dwarf::DW_LNS_extended_op, 1);
encodeULEB128(Size + 1, Section.OS);
Section.emitIntVal(dwarf::DW_LNE_set_discriminator, 1);
encodeULEB128(Discriminator, Section.OS);
}

if (Isa != Row.Isa) {
Isa = Row.Isa;
Expand Down Expand Up @@ -397,7 +403,7 @@ class DebugLineSectionEmitter {
EncodingBuffer.resize(0);
Address = -1ULL;
LastLine = FileNum = IsStatement = 1;
RowsSinceLastSequence = Column = Isa = 0;
RowsSinceLastSequence = Column = Discriminator = Isa = 0;
}
}

Expand Down
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions llvm/test/tools/dsymutil/discriminator.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; The input at Inputs/discriminator.arm64.dylib[.o] produced by compiling
;
; int foo(int i, int a, int b) {
; return i ? a : a * b;
; }
;
; with -g -fdebug-info-for-profiling -O2.

RUN: dsymutil --flat --linker=classic -oso-prepend-path %p -o - \
RUN: --oso-prepend-path %p/Inputs --verify-dwarf=none \
RUN: %p/Inputs/discriminator.arm64.dylib | llvm-dwarfdump -debug-line - \
RUN: | FileCheck %s

RUN: dsymutil --flat --linker=parallel -oso-prepend-path %p -o - \
RUN: --oso-prepend-path %p/Inputs --verify-dwarf=none \
RUN: %p/Inputs/discriminator.arm64.dylib | llvm-dwarfdump -debug-line - \
RUN: | FileCheck %s

CHECK: Address Line Column File ISA Discriminator OpIndex Flags
CHECK-NEXT: ------------------ ------ ------ ------ --- ------------- ------- -------------
CHECK-NEXT: 0x0000000000003f98 2 10 0 0 0 0 is_stmt prologue_end
CHECK-NEXT: 0x0000000000003fa4 2 3 0 0 6 0
CHECK-NEXT: 0x0000000000003fa8 2 3 0 0 0 0 end_sequence
Loading