aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCDwarf.cpp
diff options
context:
space:
mode:
authoralx32 <103613512+alx32@users.noreply.github.com>2024-09-20 06:32:34 -0700
committerGitHub <noreply@github.com>2024-09-20 06:32:34 -0700
commit28646d0cc12a01b0de2e4eb982cb91590bc2f84a (patch)
treeeb5c49a1ac208bf04c719e67544a25965d185f3f /llvm/lib/MC/MCDwarf.cpp
parent42b696d7b9942fdf07d65267da40ab178464adaa (diff)
downloadllvm-28646d0cc12a01b0de2e4eb982cb91590bc2f84a.zip
llvm-28646d0cc12a01b0de2e4eb982cb91590bc2f84a.tar.gz
llvm-28646d0cc12a01b0de2e4eb982cb91590bc2f84a.tar.bz2
[MC] Add .loc_label instruction (#99710)
As discussed in [the RFC](https://discourse.llvm.org/t/rfc-extending-llvm-mc-loc-directive-with-labeling-support/79608) we need a way to create labels in the assembler-generated line section in order to support the future addition of the [DW_AT_LLVM_stmt_sequence](https://discourse.llvm.org/t/rfc-new-dwarf-attribute-for-symbolication-of-merged-functions/79434) attribute. We have a similar precedent for such behavior with the [.cfi_label](https://github.com/llvm/llvm-project/pull/97922) instruction - so we add the `.loc_label THE_LABEL_NAME` instruction which: - Terminates the current line sequence in the line section - Creates a new label with the specified label name in the `.debug_line` section
Diffstat (limited to 'llvm/lib/MC/MCDwarf.cpp')
-rw-r--r--llvm/lib/MC/MCDwarf.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index 0dd1137..8ff097f 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -172,6 +172,7 @@ void MCDwarfLineTable::emitOne(
const MCLineSection::MCDwarfLineEntryCollection &LineEntries) {
unsigned FileNum, LastLine, Column, Flags, Isa, Discriminator;
+ bool IsAtStartSeq;
MCSymbol *LastLabel;
auto init = [&]() {
FileNum = 1;
@@ -181,6 +182,7 @@ void MCDwarfLineTable::emitOne(
Isa = 0;
Discriminator = 0;
LastLabel = nullptr;
+ IsAtStartSeq = true;
};
init();
@@ -189,6 +191,17 @@ void MCDwarfLineTable::emitOne(
for (const MCDwarfLineEntry &LineEntry : LineEntries) {
MCSymbol *Label = LineEntry.getLabel();
const MCAsmInfo *asmInfo = MCOS->getContext().getAsmInfo();
+
+ if (LineEntry.LineStreamLabel) {
+ if (!IsAtStartSeq) {
+ MCOS->emitDwarfLineEndEntry(Section, LastLabel,
+ /*EndLabel =*/LastLabel);
+ init();
+ }
+ MCOS->emitLabel(LineEntry.LineStreamLabel, LineEntry.StreamLabelDefLoc);
+ continue;
+ }
+
if (LineEntry.IsEndEntry) {
MCOS->emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, Label,
asmInfo->getCodePointerSize());
@@ -243,6 +256,7 @@ void MCDwarfLineTable::emitOne(
Discriminator = 0;
LastLine = LineEntry.getLine();
LastLabel = Label;
+ IsAtStartSeq = false;
}
// Generate DWARF line end entry.
@@ -250,10 +264,26 @@ void MCDwarfLineTable::emitOne(
// table using ranges whenever CU or section changes. However, the MC path
// does not track ranges nor terminate the line table. In that case,
// conservatively use the section end symbol to end the line table.
- if (!EndEntryEmitted)
+ if (!EndEntryEmitted && !IsAtStartSeq)
MCOS->emitDwarfLineEndEntry(Section, LastLabel);
}
+void MCDwarfLineTable::endCurrentSeqAndEmitLineStreamLabel(MCStreamer *MCOS,
+ SMLoc DefLoc,
+ StringRef Name) {
+ auto &ctx = MCOS->getContext();
+ auto *LineStreamLabel = ctx.getOrCreateSymbol(Name);
+ auto *LineSym = ctx.createTempSymbol();
+ MCOS->emitLabel(LineSym);
+ const MCDwarfLoc &DwarfLoc = ctx.getCurrentDwarfLoc();
+
+ // Create a 'fake' line entry by having LineStreamLabel be non-null. This
+ // won't actually emit any line information, it will reset the line table
+ // sequence and emit a label at the start of the new line table sequence.
+ MCDwarfLineEntry LineEntry(LineSym, DwarfLoc, LineStreamLabel, DefLoc);
+ getMCLineSections().addLineEntry(LineEntry, MCOS->getCurrentSectionOnly());
+}
+
//
// This emits the Dwarf file and the line tables.
//