Skip to content

Commit cb80665

Browse files
author
Alex B
committed
Correctly set end for end_sequence line entry
1 parent 8111dd1 commit cb80665

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ class MCObjectStreamer : public MCStreamer {
146146
void emitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
147147
const MCSymbol *Label,
148148
unsigned PointerSize) override;
149-
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) override;
149+
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel,
150+
MCSymbol *EndLabel = nullptr) override;
150151
void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
151152
const MCSymbol *Label, SMLoc Loc);
152153
void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,8 @@ class MCStreamer {
11221122
virtual void emitDwarfLineStartLabel(MCSymbol *StartSym);
11231123

11241124
/// Emit the debug line end entry.
1125-
virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) {}
1125+
virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel,
1126+
MCSymbol *EndLabel = nullptr) {}
11261127

11271128
/// If targets does not support representing debug line section by .loc/.file
11281129
/// directives in assembly output, we need to populate debug line section with

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ class MCAsmStreamer final : public MCStreamer {
431431

432432
void emitDwarfLineStartLabel(MCSymbol *StartSym) override;
433433

434-
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel) override;
434+
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel,
435+
MCSymbol *EndLabel = nullptr) override;
435436

436437
void emitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
437438
const MCSymbol *Label,
@@ -2587,7 +2588,8 @@ void MCAsmStreamer::emitDwarfLineStartLabel(MCSymbol *StartSym) {
25872588
}
25882589

25892590
void MCAsmStreamer::emitDwarfLineEndEntry(MCSection *Section,
2590-
MCSymbol *LastLabel) {
2591+
MCSymbol *LastLabel,
2592+
MCSymbol *EndLabel) {
25912593
// If the targets write the raw debug line data for assembly output (We can
25922594
// not switch to Section and add the end symbol there for assembly output)
25932595
// we currently use the .text end label as any section end. This will not
@@ -2604,9 +2606,10 @@ void MCAsmStreamer::emitDwarfLineEndEntry(MCSection *Section,
26042606
MCSection *TextSection = Ctx.getObjectFileInfo()->getTextSection();
26052607
assert(TextSection->hasEnded() && ".text section is not end!");
26062608

2607-
MCSymbol *SectionEnd = TextSection->getEndSymbol(Ctx);
2609+
if (!EndLabel)
2610+
EndLabel = TextSection->getEndSymbol(Ctx);
26082611
const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
2609-
emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
2612+
emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, EndLabel,
26102613
AsmInfo->getCodePointerSize());
26112614
}
26122615

llvm/lib/MC/MCDwarf.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ void MCDwarfLineTable::emitOne(
194194

195195
if (LineEntry.LineStreamLabel) {
196196
if (!IsAtStartSeq) {
197-
MCOS->emitDwarfLineEndEntry(Section, LastLabel);
197+
MCOS->emitDwarfLineEndEntry(Section, LastLabel,
198+
/*EndLabel =*/LastLabel);
198199
init();
199200
}
200201
MCOS->emitLabel(LineEntry.LineStreamLabel, LineEntry.StreamLabelDefLoc);
@@ -273,6 +274,7 @@ void MCDwarfLineTable::endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS,
273274
auto &ctx = MCOS->getContext();
274275
auto *LineStreamLabel = ctx.getOrCreateSymbol(Name);
275276
auto *LineSym = ctx.createTempSymbol();
277+
MCOS->emitLabel(LineSym);
276278
const MCDwarfLoc &DwarfLoc = ctx.getCurrentDwarfLoc();
277279

278280
// Create a 'fake' line entry by having LineStreamLabel be non-null. This

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,20 +467,22 @@ void MCObjectStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
467467
}
468468

469469
void MCObjectStreamer::emitDwarfLineEndEntry(MCSection *Section,
470-
MCSymbol *LastLabel) {
470+
MCSymbol *LastLabel,
471+
MCSymbol *EndLabel) {
471472
// Emit a DW_LNE_end_sequence for the end of the section.
472473
// Use the section end label to compute the address delta and use INT64_MAX
473474
// as the line delta which is the signal that this is actually a
474475
// DW_LNE_end_sequence.
475-
MCSymbol *SectionEnd = endSection(Section);
476+
if (!EndLabel)
477+
EndLabel = endSection(Section);
476478

477479
// Switch back the dwarf line section, in case endSection had to switch the
478480
// section.
479481
MCContext &Ctx = getContext();
480482
switchSection(Ctx.getObjectFileInfo()->getDwarfLineSection());
481483

482484
const MCAsmInfo *AsmInfo = Ctx.getAsmInfo();
483-
emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd,
485+
emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, EndLabel,
484486
AsmInfo->getCodePointerSize());
485487
}
486488

llvm/test/MC/ELF/debug-loc-label.s

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,39 @@
1313
# CHECK-LINE-TABLE-NEXT: 0x0000002a: 00 DW_LNE_set_address (0x0000000000000000)
1414
# CHECK-LINE-TABLE-NEXT: 0x00000035: 01 DW_LNS_copy
1515
# CHECK-LINE-TABLE-NEXT: 0x0000000000000000 1 1 1 0 0 0 is_stmt
16-
# CHECK-LINE-TABLE-NEXT: 0x00000036: 02 DW_LNS_advance_pc (addr += 33, op-index += 0)
17-
# CHECK-LINE-TABLE-NEXT: 0x00000038: 00 DW_LNE_end_sequence
18-
# CHECK-LINE-TABLE-NEXT: 0x0000000000000021 1 1 1 0 0 0 is_stmt end_sequence
19-
# CHECK-LINE-TABLE-NEXT: 0x0000003b: 05 DW_LNS_set_column (2)
20-
# CHECK-LINE-TABLE-NEXT: 0x0000003d: 00 DW_LNE_set_address (0x0000000000000008)
21-
# CHECK-LINE-TABLE-NEXT: 0x00000048: 01 DW_LNS_copy
16+
# CHECK-LINE-TABLE-NEXT: 0x00000036: 00 DW_LNE_end_sequence
17+
# CHECK-LINE-TABLE-NEXT: 0x0000000000000000 1 1 1 0 0 0 is_stmt end_sequence
18+
# CHECK-LINE-TABLE-NEXT: 0x00000039: 05 DW_LNS_set_column (2)
19+
# CHECK-LINE-TABLE-NEXT: 0x0000003b: 00 DW_LNE_set_address (0x0000000000000008)
20+
# CHECK-LINE-TABLE-NEXT: 0x00000046: 01 DW_LNS_copy
2221
# CHECK-LINE-TABLE-NEXT: 0x0000000000000008 1 2 1 0 0 0 is_stmt
23-
# CHECK-LINE-TABLE-NEXT: 0x00000049: 02 DW_LNS_advance_pc (addr += 25, op-index += 0)
24-
# CHECK-LINE-TABLE-NEXT: 0x0000004b: 00 DW_LNE_end_sequence
25-
# CHECK-LINE-TABLE-NEXT: 0x0000000000000021 1 2 1 0 0 0 is_stmt end_sequence
26-
# CHECK-LINE-TABLE-NEXT: 0x0000004e: 05 DW_LNS_set_column (3)
27-
# CHECK-LINE-TABLE-NEXT: 0x00000050: 00 DW_LNE_set_address (0x0000000000000010)
28-
# CHECK-LINE-TABLE-NEXT: 0x0000005b: 01 DW_LNS_copy
22+
# CHECK-LINE-TABLE-NEXT: 0x00000047: 00 DW_LNE_end_sequence
23+
# CHECK-LINE-TABLE-NEXT: 0x0000000000000008 1 2 1 0 0 0 is_stmt end_sequence
24+
# CHECK-LINE-TABLE-NEXT: 0x0000004a: 05 DW_LNS_set_column (3)
25+
# CHECK-LINE-TABLE-NEXT: 0x0000004c: 00 DW_LNE_set_address (0x0000000000000010)
26+
# CHECK-LINE-TABLE-NEXT: 0x00000057: 01 DW_LNS_copy
2927
# CHECK-LINE-TABLE-NEXT: 0x0000000000000010 1 3 1 0 0 0 is_stmt
30-
# CHECK-LINE-TABLE-NEXT: 0x0000005c: 08 DW_LNS_const_add_pc (addr += 0x0000000000000011, op-index += 0)
31-
# CHECK-LINE-TABLE-NEXT: 0x0000005d: 00 DW_LNE_end_sequence
32-
# CHECK-LINE-TABLE-NEXT: 0x0000000000000021 1 3 1 0 0 0 is_stmt end_sequence
33-
# CHECK-LINE-TABLE-NEXT: 0x00000060: 05 DW_LNS_set_column (4)
34-
# CHECK-LINE-TABLE-NEXT: 0x00000062: 00 DW_LNE_set_address (0x0000000000000018)
35-
# CHECK-LINE-TABLE-NEXT: 0x0000006d: 01 DW_LNS_copy
28+
# CHECK-LINE-TABLE-NEXT: 0x00000058: 00 DW_LNE_end_sequence
29+
# CHECK-LINE-TABLE-NEXT: 0x0000000000000010 1 3 1 0 0 0 is_stmt end_sequence
30+
# CHECK-LINE-TABLE-NEXT: 0x0000005b: 05 DW_LNS_set_column (4)
31+
# CHECK-LINE-TABLE-NEXT: 0x0000005d: 00 DW_LNE_set_address (0x0000000000000018)
32+
# CHECK-LINE-TABLE-NEXT: 0x00000068: 01 DW_LNS_copy
3633
# CHECK-LINE-TABLE-NEXT: 0x0000000000000018 1 4 1 0 0 0 is_stmt
37-
# CHECK-LINE-TABLE-NEXT: 0x0000006e: 05 DW_LNS_set_column (5)
38-
# CHECK-LINE-TABLE-NEXT: 0x00000070: 01 DW_LNS_copy
34+
# CHECK-LINE-TABLE-NEXT: 0x00000069: 05 DW_LNS_set_column (5)
35+
# CHECK-LINE-TABLE-NEXT: 0x0000006b: 01 DW_LNS_copy
3936
# CHECK-LINE-TABLE-NEXT: 0x0000000000000018 1 5 1 0 0 0 is_stmt
40-
# CHECK-LINE-TABLE-NEXT: 0x00000071: 02 DW_LNS_advance_pc (addr += 9, op-index += 0)
41-
# CHECK-LINE-TABLE-NEXT: 0x00000073: 00 DW_LNE_end_sequence
37+
# CHECK-LINE-TABLE-NEXT: 0x0000006c: 02 DW_LNS_advance_pc (addr += 9, op-index += 0)
38+
# CHECK-LINE-TABLE-NEXT: 0x0000006e: 00 DW_LNE_end_sequence
4239
# CHECK-LINE-TABLE-NEXT: 0x0000000000000021 1 5 1 0 0 0 is_stmt end_sequence
4340

4441
# CHECK-SECTIONS: Contents of section .offset_02:
45-
# CHECK-SECTIONS-NEXT: 0000 3b000000
42+
# CHECK-SECTIONS-NEXT: 0000 39000000
4643

4744
# CHECK-SECTIONS: Contents of section .offset_03:
48-
# CHECK-SECTIONS-NEXT: 0000 4e000000
45+
# CHECK-SECTIONS-NEXT: 0000 4a000000
4946

5047
# CHECK-SECTIONS: Contents of section .offset_05:
51-
# CHECK-SECTIONS-NEXT: 0000 60000000
48+
# CHECK-SECTIONS-NEXT: 0000 5b000000
5249
.text
5350
.file "test.c"
5451
.globl foo

0 commit comments

Comments
 (0)