[llvm] [DWARF] Emit line 0 source locations for BB padding nops (PR #99496)

Paul T Robinson via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 08:22:50 PDT 2024


================
@@ -3668,3 +3668,19 @@ bool DwarfDebug::alwaysUseRanges(const DwarfCompileUnit &CU) const {
     return true;
   return false;
 }
+
+void DwarfDebug::beginCodeAlignment(const MachineBasicBlock &MBB) {
+  auto *SP = MBB.getParent()->getFunction().getSubprogram();
+
+  bool NoDebug =
+      !SP || SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug;
+
+  if (NoDebug)
+    return;
+
+  auto PrevLoc = Asm->OutStreamer->getContext().getCurrentDwarfLoc();
+  Asm->OutStreamer->emitDwarfLocDirective(
----------------
pogo59 wrote:

> Dwarf line entries are encoded in a MCDwarfLineAddrFragment which contains an expression and fixups to compute the delta between the current symbol and the last symbol encoded with fixups and then eventually end up as a link-time relocation so the absolute address isn't known until that time.

That doesn't sound right. There should be only one link-time relocation per sequence (usually, one per function). Line-table entries are encoded with a line-adjustment and an instruction-offset delta from the previous entry. It should be feasible to detect a zero instruction delta.

That said, it is a broader problem as I've seen these zero deltas in other situations as well. This patch makes it more prevalent but isn't introducing a new problem. At the AsmPrinter level, you have to assume that there _could_ be nops introduced, and attaching line-0 to those nops is one reasonable solution.

Have you considered instead using the .loc of the first instruction of the new block? That is, emit the new block's .loc _before_ emitting the .align directive. This is something that occurred to me just now, I haven't looked at the code to see whether that's feasible.

https://github.com/llvm/llvm-project/pull/99496


More information about the llvm-commits mailing list