public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* DW_TAG_compile_unit's references to .debug_line and .loc directive extension
@ 2024-07-04 19:42 Fangrui Song
  0 siblings, 0 replies; 2+ messages in thread
From: Fangrui Song @ 2024-07-04 19:42 UTC (permalink / raw)
  To: binutils, gcc

I have noticed that Meta Platforms folks have a proposal to extend the
.loc directive https://discourse.llvm.org/t/rfc-extending-llvm-mc-loc-directive-with-labeling-support/79608
 .
I filed https://sourceware.org/bugzilla/show_bug.cgi?id=31955 ("gas:
Extend .loc directive to emit a label") and am sending this message in
case there are interest/opinions.

For your convenience, the gas documentation is at
https://sourceware.org/binutils/docs/as/Loc.html

> The .loc directive will add a row to the .debug_line line number matrix corresponding to the immediately following assembly instruction.

Here is my summary of their proposal:

Clang will add a new debug mode to emit a DW_AT_LLVM_stmt_sequence
attribute to each DW_TAG_subprogram DIE, referencing the start of a
line number program sequence associated with the subprogram.
(https://discourse.llvm.org/t/rfc-new-dwarf-attribute-for-symbolication-of-merged-functions/79434)

```
main:
  .loc 0 1 13  debug_line_label .Lmain_line_entries
  ...

.section .debug_info,"",@progbits
  ...
  .byte   1                               # Abbrev [1] 0xc:0x78
DW_TAG_compile_unit
  .long   .Lline_table_start0             # DW_AT_stmt_list
  ...

  .byte 14                                           # Abbrev [14]
DW_TAG_subprogram
  ...
  .long .Lmain_line_entries - .Lline_table_start0    # DW_AT_LLVM_stmt_sequence

.section        .debug_line,"",@progbits # generated
.Lline_table_start0:
# Conceptually, the .Lmain_line_entries label is emitted at start of a
line number program sequence associated with `main`
```

Advantages.

*Faster symbolization*

Traditional address symbolization involves locating the
DW_TAG_compile_unit DIE and parsing the line number program from the
DW_AT_stmt_list offset.
This process requires skipping unrelated DW_TAG_subprogram DIEs. The
DW_AT_LLVM_stmt_sequence attribute directly points to the relevant
line number program sequence, eliminating unnecessary steps.

*Improved ICF disambiguating*

Identical Code Folding (ICF) can make two line number program
sequences (associated with folded subprograms) indistinguishable.
While DW_AT_LLVM_stmt_sequence doesn't resolve this, it identifies the
associated function. If the caller is known, this additional
information could help disambiguate the correct sequence.

---

ELF/COFF -fno-function-sections and Mach-O .subsections_via_symbols
allow consecutive functions to share the same line number program
sequence.
To utilize DW_AT_LLVM_stmt_sequence better, the sequences should be
split to resemble ELF/COFF -ffunction-sections.

Mach-O doesn't have -ffunction-sections -fno-function-sections
differences and normally needs very few relocations for .debug_line
and the new mode will introduce more like ELF/COFF
-ffunction-sections.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: DW_TAG_compile_unit's references to .debug_line and .loc directive extension
       [not found] <CAN30aBHfSDb33NL5Of8Ny32_G9=jJ2XxrFVodH3mQDmHSik7PA@mail.gmail.com>
@ 2024-07-20  0:18 ` Fangrui Song
  0 siblings, 0 replies; 2+ messages in thread
From: Fangrui Song @ 2024-07-20  0:18 UTC (permalink / raw)
  To: binutils, gcc, jbeulich

On Thu, Jul 4, 2024 at 12:42 PM Fangrui Song <i@maskray.me> wrote:
>
> I have noticed that Meta Platforms folks have a proposal to extend the
> .loc directive https://discourse.llvm.org/t/rfc-extending-llvm-mc-loc-directive-with-labeling-support/79608
>  .
> I filed https://sourceware.org/bugzilla/show_bug.cgi?id=31955 ("gas:
> Extend .loc directive to emit a label") and am sending this message in
> case there are interest/opinions.
>
> For your convenience, the gas documentation is at
> https://sourceware.org/binutils/docs/as/Loc.html
>
> > The .loc directive will add a row to the .debug_line line number matrix corresponding to the immediately following assembly instruction.
>
> Here is my summary of their proposal:
>
> Clang will add a new debug mode to emit a DW_AT_LLVM_stmt_sequence
> attribute to each DW_TAG_subprogram DIE, referencing the start of a
> line number program sequence associated with the subprogram.
> (https://discourse.llvm.org/t/rfc-new-dwarf-attribute-for-symbolication-of-merged-functions/79434)
>
> ```
> main:
>   .loc 0 1 13  debug_line_label .Lmain_line_entries
>   ...
>
> .section .debug_info,"",@progbits
>   ...
>   .byte   1                               # Abbrev [1] 0xc:0x78
> DW_TAG_compile_unit
>   .long   .Lline_table_start0             # DW_AT_stmt_list
>   ...
>
>   .byte 14                                           # Abbrev [14]
> DW_TAG_subprogram
>   ...
>   .long .Lmain_line_entries - .Lline_table_start0    # DW_AT_LLVM_stmt_sequence
>
> .section        .debug_line,"",@progbits # generated
> .Lline_table_start0:
> # Conceptually, the .Lmain_line_entries label is emitted at start of a
> line number program sequence associated with `main`
> ```
>
> Advantages.
>
> *Faster symbolization*
>
> Traditional address symbolization involves locating the
> DW_TAG_compile_unit DIE and parsing the line number program from the
> DW_AT_stmt_list offset.
> This process requires skipping unrelated DW_TAG_subprogram DIEs. The
> DW_AT_LLVM_stmt_sequence attribute directly points to the relevant
> line number program sequence, eliminating unnecessary steps.
>
> *Improved ICF disambiguating*
>
> Identical Code Folding (ICF) can make two line number program
> sequences (associated with folded subprograms) indistinguishable.
> While DW_AT_LLVM_stmt_sequence doesn't resolve this, it identifies the
> associated function. If the caller is known, this additional
> information could help disambiguate the correct sequence.
>
> ---
>
> ELF/COFF -fno-function-sections and Mach-O .subsections_via_symbols
> allow consecutive functions to share the same line number program
> sequence.
> To utilize DW_AT_LLVM_stmt_sequence better, the sequences should be
> split to resemble ELF/COFF -ffunction-sections.
>
> Mach-O doesn't have -ffunction-sections -fno-function-sections
> differences and normally needs very few relocations for .debug_line
> and the new mode will introduce more like ELF/COFF
> -ffunction-sections.

Heads-up: they have created a patch to add the  .loc_label assembler
directive https://github.com/llvm/llvm-project/pull/99710 .

.cfi_label is existing, so .loc_label looks reasonable.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-20  0:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-04 19:42 DW_TAG_compile_unit's references to .debug_line and .loc directive extension Fangrui Song
     [not found] <CAN30aBHfSDb33NL5Of8Ny32_G9=jJ2XxrFVodH3mQDmHSik7PA@mail.gmail.com>
2024-07-20  0:18 ` Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).