[llvm] [DWARF] Emit line 0 source locations for BB padding nops (PR #99496)
Nabeel Omer via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 22 11:44:58 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(
----------------
omern1 wrote:
I see what you mean.
```
0000000000000000 <f>:
; ...
3: 7e 2b jle 0x30 <f+0x30>
5: 66 2e 0f 1f 84 00 00 00 00 00 nopw %cs:(%rax,%rax)
f: 90 nop
10: e8 00 00 00 00 callq 0x15 <f+0x15>
15: e8 00 00 00 00 callq 0x1a <f+0x1a>
1a: e8 00 00 00 00 callq 0x1f <f+0x1f>
1f: e8 00 00 00 00 callq 0x24 <f+0x24>
24: e8 00 00 00 00 callq 0x29 <f+0x29>
29: e8 00 00 00 00 callq 0x2e <f+0x2e>
2e: eb e0 jmp 0x10 <f+0x10>
30: e8 00 00 00 00 callq 0x35 <f+0x35> ; BB starting here is a loop but has no nops
35: eb f9 jmp 0x30 <f+0x30>
```
We will end up with a line 0 record for address 0x30 immediately followed by a record for the correct line number.
The `MCAlignFragment` type only allows for the possibility of nops being emitted, it does not guarantee that they'll be emitted. The addresses aren't known till after the assembler computes layout which happens much later than here. I can't think of a way to handle this case as things currently stand though there may be other debug-info related mechanisms to deal with this that I'm not aware of, what do you suggest?
https://github.com/llvm/llvm-project/pull/99496
More information about the llvm-commits
mailing list