Skip to content

Commit 662dcec

Browse files
author
Alex B
committed
Fix compatibility with current MCStreamer Line Label implementation
1 parent bd3f96d commit 662dcec

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

llvm/include/llvm/MC/MCDwarf.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ class MCDwarfLoc {
123123
friend class MCContext;
124124
friend class MCDwarfLineEntry;
125125

126-
// DwarfDebug::endFunctionImpl needs to construct MCDwarfLoc(IsEndOfFunction)
127-
friend class DwarfDebug;
128-
129126
MCDwarfLoc(unsigned fileNum, unsigned line, unsigned column, unsigned flags,
130127
unsigned isa, unsigned discriminator)
131128
: FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(isa),
@@ -242,7 +239,7 @@ class MCLineSection {
242239

243240
// Add an end entry by cloning the last entry, if exists, for the section
244241
// the given EndLabel belongs to. The label is replaced by the given EndLabel.
245-
void addEndEntry(MCSymbol *EndLabel, bool generatingFuncLineTableOffsets);
242+
void addEndEntry(MCSymbol *EndLabel);
246243

247244
using MCDwarfLineEntryCollection = std::vector<MCDwarfLineEntry>;
248245
using iterator = MCDwarfLineEntryCollection::iterator;

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,8 +2262,7 @@ void DwarfDebug::terminateLineTable(const DwarfCompileUnit *CU) {
22622262
getDwarfCompileUnitIDForLineTable(*CU));
22632263
// Add the last range label for the given CU.
22642264
LineTable.getMCLineSections().addEndEntry(
2265-
const_cast<MCSymbol *>(CURanges.back().End),
2266-
EmitFuncLineTableOffsetsOption);
2265+
const_cast<MCSymbol *>(CURanges.back().End));
22672266
}
22682267

22692268
void DwarfDebug::skippedNonDebugFunction() {
@@ -2356,21 +2355,6 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
23562355
// Construct call site entries.
23572356
constructCallSiteEntryDIEs(*SP, TheCU, ScopeDIE, *MF);
23582357

2359-
// If we're emitting line table offsets, we also need to emit an end label
2360-
// after all function's line entries
2361-
if (EmitFuncLineTableOffsetsOption) {
2362-
MCSymbol *LineSym = Asm->OutStreamer->getContext().createTempSymbol();
2363-
Asm->OutStreamer->emitLabel(LineSym);
2364-
MCDwarfLoc DwarfLoc(
2365-
1, 1, 0, DWARF2_LINE_DEFAULT_IS_STMT ? DWARF2_FLAG_IS_STMT : 0, 0, 0);
2366-
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc);
2367-
Asm->OutStreamer->getContext()
2368-
.getMCDwarfLineTable(
2369-
Asm->OutStreamer->getContext().getDwarfCompileUnitID())
2370-
.getMCLineSections()
2371-
.addLineEntry(LineEntry, Asm->OutStreamer->getCurrentSectionOnly());
2372-
}
2373-
23742358
// Clear debug info
23752359
// Ownership of DbgVariables is a bit subtle - ScopeVariables owns all the
23762360
// DbgVariables except those that are also in AbstractVariables (since they

llvm/lib/MC/MCDwarf.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,22 @@ void MCDwarfLineEntry::make(MCStreamer *MCOS, MCSection *Section) {
104104
// Get the current .loc info saved in the context.
105105
const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc();
106106

107-
MCSymbol *LineStreamLabel = nullptr;
108107
// If functions need offsets into the generated line table, then we need to
109108
// create a label referencing where the line was generated in the output
110109
// stream
111-
if (MCOS->getGenerateFuncLineTableOffsets()) {
112-
LineStreamLabel = MCOS->getContext().createTempSymbol();
110+
if (MCOS->getGenerateFuncLineTableOffsets() &&
111+
!MCOS->getCurrentFuncFirstLineStreamSym()) {
112+
MCSymbol *LineStreamLabel = MCOS->getContext().createTempSymbol();
113113
MCOS->emittedLineStreamSym(LineStreamLabel);
114+
MCDwarfLineEntry LabelLineEntry(LineSym, DwarfLoc, LineStreamLabel);
115+
MCOS->getContext()
116+
.getMCDwarfLineTable(MCOS->getContext().getDwarfCompileUnitID())
117+
.getMCLineSections()
118+
.addLineEntry(LabelLineEntry, Section);
114119
}
115120

116121
// Create a (local) line entry with the symbol and the current .loc info.
117-
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc, LineStreamLabel);
122+
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc);
118123

119124
// clear DwarfLocSeen saying the current .loc info is now used.
120125
MCOS->getContext().clearDwarfLocSeen();
@@ -154,8 +159,7 @@ makeStartPlusIntExpr(MCContext &Ctx, const MCSymbol &Start, int IntVal) {
154159
return Res;
155160
}
156161

157-
void MCLineSection::addEndEntry(MCSymbol *EndLabel,
158-
bool generatingFuncLineTableOffsets) {
162+
void MCLineSection::addEndEntry(MCSymbol *EndLabel) {
159163
auto *Sec = &EndLabel->getSection();
160164
// The line table may be empty, which we should skip adding an end entry.
161165
// There are two cases:
@@ -168,12 +172,8 @@ void MCLineSection::addEndEntry(MCSymbol *EndLabel,
168172
if (I != MCLineDivisions.end()) {
169173
auto &Entries = I->second;
170174
auto EndEntry = Entries.back();
171-
// If generatingFuncLineTableOffsets is set, then we already generated an
172-
// end label at the end of the last function, so skip generating another one
173-
if (!generatingFuncLineTableOffsets) {
174-
EndEntry.setEndLabel(EndLabel);
175-
Entries.push_back(EndEntry);
176-
}
175+
EndEntry.setEndLabel(EndLabel);
176+
Entries.push_back(EndEntry);
177177
}
178178
}
179179

llvm/test/DebugInfo/X86/DW_AT_LLVM_stmt_seq_sec_offset.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
; STMT_SEQ: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] (0x00000028)
1313
; STMT_SEQ: DW_AT_name {{.*}}func01
1414
; STMT_SEQ: DW_TAG_subprogram [[[ABBREV_CODE]]]
15-
; STMT_SEQ: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] (0x00000033)
15+
; STMT_SEQ: DW_AT_LLVM_stmt_sequence [DW_FORM_sec_offset] (0x00000036)
1616
; STMT_SEQ: DW_AT_name {{.*}}main
1717

1818
;; Check that the line table starts at 0x00000028 (first function)
1919
; STMT_SEQ: Address Line Column File ISA Discriminator OpIndex Flags
2020
; STMT_SEQ-NEXT: ------------------ ------ ------ ------ --- ------------- ------- -------------
21-
; STMT_SEQ-NEXT: 0x00000028: 00 DW_LNE_set_address (0x00000006)
21+
; STMT_SEQ-NEXT: 0x00000028: 05 DW_LNS_set_column (3)
2222

23-
;; Check that we have an 'end_sequence' just before the next function (0x00000033)
24-
; STMT_SEQ: 0x0000000000000006 1 0 1 0 0 0 is_stmt end_sequence
25-
; STMT_SEQ-NEXT: 0x00000033: 00 DW_LNE_set_address (0x00000027)
23+
;; Check that we have an 'end_sequence' just before the next function (0x00000036)
24+
; STMT_SEQ: 0x0000000000000000 2 3 1 0 0 0 is_stmt end_sequence
25+
; STMT_SEQ-NEXT: 0x00000036: 00 DW_LNE_set_address (0x00000010)
2626

2727
;; Check that the end of the line table still has an 'end_sequence'
28-
; STMT_SEQ 0x00000049: 00 DW_LNE_end_sequence
28+
; STMT_SEQ 0x00000047: 00 DW_LNE_end_sequence
2929
; STMT_SEQ-NEXT 0x0000000000000027 6 3 1 0 0 0 end_sequence
3030

3131

0 commit comments

Comments
 (0)