Skip to content

Commit 2977fbc

Browse files
author
Alex B
committed
Address Feedback Nr.1
1 parent 33d3ac6 commit 2977fbc

File tree

4 files changed

+57
-31
lines changed

4 files changed

+57
-31
lines changed

llvm/include/llvm/MC/MCDwarf.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ class MCDwarfLineEntry : public MCDwarfLoc {
195195
public:
196196
// Constructor to create an MCDwarfLineEntry given a symbol and the dwarf loc.
197197
MCDwarfLineEntry(MCSymbol *label, const MCDwarfLoc loc,
198-
MCSymbol *lineStreamLabel = nullptr)
199-
: MCDwarfLoc(loc), Label(label), LineStreamLabel(lineStreamLabel) {}
198+
MCSymbol *lineStreamLabel = nullptr,
199+
SMLoc streamLabelDefLoc = {})
200+
: MCDwarfLoc(loc), Label(label), LineStreamLabel(lineStreamLabel),
201+
StreamLabelDefLoc(streamLabelDefLoc) {}
200202

201203
MCSymbol *getLabel() const { return Label; }
202204

@@ -205,6 +207,10 @@ class MCDwarfLineEntry : public MCDwarfLoc {
205207
// line sequence.
206208
MCSymbol *LineStreamLabel;
207209

210+
// Location where LineStreamLabel was defined. If there is an error emitting
211+
// LineStreamLabel, we can use the SMLoc to report an error.
212+
SMLoc StreamLabelDefLoc;
213+
208214
// This indicates the line entry is synthesized for an end entry.
209215
bool IsEndEntry = false;
210216

@@ -371,6 +377,9 @@ class MCDwarfLineTable {
371377
emitOne(MCStreamer *MCOS, MCSection *Section,
372378
const MCLineSection::MCDwarfLineEntryCollection &LineEntries);
373379

380+
void endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS, SMLoc DefLoc,
381+
StringRef Name);
382+
374383
Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
375384
std::optional<MD5::MD5Result> Checksum,
376385
std::optional<StringRef> Source,

llvm/lib/MC/MCDwarf.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void MCDwarfLineTable::emitOne(
197197
MCOS->emitDwarfLineEndEntry(Section, LastLabel);
198198
init();
199199
}
200-
MCOS->emitLabel(LineEntry.LineStreamLabel);
200+
MCOS->emitLabel(LineEntry.LineStreamLabel, LineEntry.StreamLabelDefLoc);
201201

202202
IsAtStartSeq = true;
203203
continue;
@@ -270,6 +270,23 @@ void MCDwarfLineTable::emitOne(
270270
MCOS->emitDwarfLineEndEntry(Section, LastLabel);
271271
}
272272

273+
void MCDwarfLineTable::endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS,
274+
SMLoc DefLoc,
275+
StringRef Name) {
276+
auto &ctx = MCOS->getContext();
277+
auto *LineStreamLabel = ctx.getOrCreateSymbol(Name);
278+
auto *LineSym = ctx.createTempSymbol();
279+
const MCDwarfLoc &DwarfLoc = ctx.getCurrentDwarfLoc();
280+
281+
// Create a 'fake' line entry by having LineStreamLabel be non-null. This
282+
// won't actually emit any line information, it will reset the line table
283+
// sequence and emit a label at the start of the new line table sequence.
284+
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc, LineStreamLabel, DefLoc);
285+
286+
// Add the line entry to this section's entries.
287+
getMCLineSections().addLineEntry(LineEntry, MCOS->getCurrentSectionOnly());
288+
}
289+
273290
//
274291
// This emits the Dwarf file and the line tables.
275292
//

llvm/lib/MC/MCStreamer.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,22 +268,9 @@ void MCStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
268268
}
269269

270270
void MCStreamer::emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name) {
271-
auto &ctx = getContext();
272-
273-
auto *LineStreamLabel = ctx.getOrCreateSymbol(Name);
274-
275-
auto *LineSym = ctx.createTempSymbol();
276-
const MCDwarfLoc &DwarfLoc = ctx.getCurrentDwarfLoc();
277-
278-
// Create a 'fake' line entry by having LineStreamLabel be non-null. This
279-
// won't actually emit any line information, it will reset the line table
280-
// sequence and emit a label at the start of the new line table sequence.
281-
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc, LineStreamLabel);
282-
283-
// Add the line entry to this section's entries.
284-
ctx.getMCDwarfLineTable(ctx.getDwarfCompileUnitID())
285-
.getMCLineSections()
286-
.addLineEntry(LineEntry, getCurrentSectionOnly());
271+
getContext()
272+
.getMCDwarfLineTable(getContext().getDwarfCompileUnitID())
273+
.endCurrentSeqAndEmitLineStreamLabel(this, Loc, Name);
287274
}
288275

289276
MCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) {

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

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22
// the requested label at the correct position in the line stream
33

44
// RUN: llvm-mc -filetype obj -triple x86_64-linux-elf %s -o %t.o
5-
// RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefix=CHECK-ASM
65
// RUN: llvm-dwarfdump -v --debug-line %t.o | FileCheck %s --check-prefix=CHECK-LINE-TABLE
6+
// RUN: llvm-objdump -s -j .offset_02 -j .offset_03 -j .offset_05 %t.o | FileCheck %s --check-prefix=CHECK-SECTIONS
7+
78

8-
# CHECK-ASM: <foo>:
9-
# CHECK-ASM-NEXT: movq %rdx, 0x33
10-
# CHECK-ASM-NEXT: movq %rax, 0x3b
11-
# CHECK-ASM-NEXT: movq %rbx, 0x4e
12-
# CHECK-ASM-NEXT: movq %rcx, 0x60
13-
# CHECK-ASM-NEXT: retq
149

1510
# CHECK-LINE-TABLE: Address Line Column File ISA Discriminator OpIndex Flags
1611
# CHECK-LINE-TABLE-NEXT: ------------------ ------ ------ ------ --- ------------- ------- -------------
@@ -45,6 +40,15 @@
4540
# CHECK-LINE-TABLE-NEXT: 0x00000071: 02 DW_LNS_advance_pc (addr += 9, op-index += 0)
4641
# CHECK-LINE-TABLE-NEXT: 0x00000073: 00 DW_LNE_end_sequence
4742
# CHECK-LINE-TABLE-NEXT: 0x0000000000000021 1 5 1 0 0 0 is_stmt end_sequence
43+
44+
# CHECK-SECTIONS: Contents of section .offset_02:
45+
# CHECK-SECTIONS-NEXT: 0000 3b000000
46+
47+
# CHECK-SECTIONS: Contents of section .offset_03:
48+
# CHECK-SECTIONS-NEXT: 0000 4e000000
49+
50+
# CHECK-SECTIONS: Contents of section .offset_05:
51+
# CHECK-SECTIONS-NEXT: 0000 60000000
4852
.text
4953
.file "test.c"
5054
.globl foo
@@ -55,20 +59,29 @@ foo:
5559
.file 1 "test.c"
5660
.cfi_startproc
5761
.loc 1 1 1
58-
mov %rdx, 0x33
62+
mov %rax, 0x01
5963
.loc_label my_label_02
6064
.loc 1 1 2
61-
movq %rax, my_label_02-.Lline_table_start0
65+
mov %rax, 0x02
6266
.loc 1 1 3
6367
.loc_label my_label_03
6468
.loc_label my_label_03.1
65-
movq %rbx, my_label_03-.Lline_table_start0
69+
mov %rax, 0x03
6670
.loc 1 1 4
67-
.loc_label my_label_05
71+
.loc_label my_label_04
6872
.loc 1 1 5
69-
movq %rcx, my_label_05-.Lline_table_start0
73+
mov %rax, 0x04
7074
ret
7175
.cfi_endproc
7276

7377
.section .debug_line,"",@progbits
7478
.Lline_table_start0:
79+
80+
.section .offset_02,"",@progbits
81+
.quad my_label_02-.Lline_table_start0
82+
83+
.section .offset_03,"",@progbits
84+
.quad my_label_03-.Lline_table_start0
85+
86+
.section .offset_05,"",@progbits
87+
.quad my_label_04-.Lline_table_start0

0 commit comments

Comments
 (0)