PING: [PATCH v3] dwarf: Dump .debug_loclists only for DWARF-5

H.J. Lu hjl.tools@gmail.com
Sun Apr 27 23:25:11 GMT 2025


On Fri, Mar 28, 2025 at 1:21 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> .debug_loclists section is loaded into debug_information as DWARF-5 debug
> info and .debug_loc section is loaded into debug_information as pre-DWARF-5
> debug info.  When dumping .debug_loc section, we should only process
> pre-DWARF-5 debug info in debug_information.  When dumping .debug_loclists
> section, we should only process DWARF-5 info in debug_information.
>
> binutils/
>
>         PR binutils/32809
>         * dwarf.c (display_debug_loc): Dump .debug_loclists only for
>         DWARF-5.
>
> ld/
>
>         PR binutils/32809
>         * testsuite/ld-x86-64/dwarf4.s: New file.
>         * testsuite/ld-x86-64/dwarf5a.s: Likewise.
>         * testsuite/ld-x86-64/dwarf5b.s: Likewise.
>         * testsuite/ld-x86-64/pr32809.d: Likewise.
>         * testsuite/ld-x86-64/x86-64.exp: Run pr32809.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  binutils/dwarf.c                  |  14 +-
>  ld/testsuite/ld-x86-64/dwarf4.s   | 323 +++++++++++++++++++++++++
>  ld/testsuite/ld-x86-64/dwarf5a.s  | 377 ++++++++++++++++++++++++++++++
>  ld/testsuite/ld-x86-64/dwarf5b.s  | 321 +++++++++++++++++++++++++
>  ld/testsuite/ld-x86-64/pr32809.d  |  71 ++++++
>  ld/testsuite/ld-x86-64/x86-64.exp |   1 +
>  6 files changed, 1105 insertions(+), 2 deletions(-)
>  create mode 100644 ld/testsuite/ld-x86-64/dwarf4.s
>  create mode 100644 ld/testsuite/ld-x86-64/dwarf5a.s
>  create mode 100644 ld/testsuite/ld-x86-64/dwarf5b.s
>  create mode 100644 ld/testsuite/ld-x86-64/pr32809.d
>
> diff --git a/binutils/dwarf.c b/binutils/dwarf.c
> index 08bb623e405..fb09b866798 100644
> --- a/binutils/dwarf.c
> +++ b/binutils/dwarf.c
> @@ -7324,7 +7324,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
>    unsigned int *array = NULL;
>    const char *suffix = strrchr (section->name, '.');
>    bool is_dwo = false;
> -  int is_loclists = strstr (section->name, "debug_loclists") != NULL;
> +  bool is_loclists = strstr (section->name, "debug_loclists") != NULL;
>    uint64_t next_header_offset = 0;
>
>    if (suffix && strcmp (suffix, ".dwo") == 0)
> @@ -7450,6 +7450,16 @@ display_debug_loc (struct dwarf_section *section, void *file)
>        debug_info *debug_info_p = debug_information + i;
>        uint32_t offset_count;
>
> +      /* .debug_loclists section is loaded into debug_information as
> +        DWARF-5 debug info and .debug_loc section is loaded into
> +        debug_information as pre-DWARF-5 debug info.  When dumping
> +        .debug_loc section, we should only process pre-DWARF-5 debug
> +        info in debug_information.  When dumping .debug_loclists
> +        section, we should only process DWARF-5 info in
> +        debug_information.  */
> +      if ((debug_info_p->dwarf_version >= 5) != is_loclists)
> +       continue;
> +
>        if (!locs_sorted)
>         {
>           for (k = 0; k < debug_info_p->num_loc_offsets; k++)
> @@ -7462,7 +7472,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
>
>        /* .debug_loclists has a per-unit header.
>          Update start if we are detecting it.  */
> -      if (debug_info_p->dwarf_version == 5)
> +      if (debug_info_p->dwarf_version >= 5)
>         {
>           j = locs_sorted ? 0 : array [0];
>
> diff --git a/ld/testsuite/ld-x86-64/dwarf4.s b/ld/testsuite/ld-x86-64/dwarf4.s
> new file mode 100644
> index 00000000000..8eb1ad58602
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/dwarf4.s
> @@ -0,0 +1,323 @@
> +/* Assembly outputs of
> +
> +extern void bar();
> +
> +void foo(int p) {
> +  int local = p;
> +  bar();
> +  local = 123;
> +  bar();
> +  local = 456;
> +}
> +
> +compiled by GCC 14.2.1 with -O2 -g -gdwarf-4.  */
> +
> +       .file   "dwarf4.c"
> +       .text
> +.Ltext0:
> +       .file 1 "dwarf4.c"
> +       .p2align 4
> +       .globl  foo
> +       .type   foo, @function
> +foo:
> +.LVL0:
> +.LFB0:
> +       .loc 1 3 17 view -0
> +       .cfi_startproc
> +       .loc 1 4 3 view .LVU1
> +       .loc 1 5 3 view .LVU2
> +       .loc 1 3 17 is_stmt 0 view .LVU3
> +       subq    $8, %rsp
> +       .cfi_def_cfa_offset 16
> +       .loc 1 5 3 view .LVU4
> +       xorl    %eax, %eax
> +       call    bar
> +.LVL1:
> +       .loc 1 6 3 is_stmt 1 view .LVU5
> +       .loc 1 7 3 view .LVU6
> +       xorl    %eax, %eax
> +       .loc 1 9 1 is_stmt 0 view .LVU7
> +       addq    $8, %rsp
> +       .cfi_def_cfa_offset 8
> +       .loc 1 7 3 view .LVU8
> +       jmp     bar
> +.LVL2:
> +       .cfi_endproc
> +.LFE0:
> +       .size   foo, .-foo
> +.Letext0:
> +       .section        .debug_info,"",@progbits
> +.Ldebug_info0:
> +       .long   0x9e
> +       .value  0x4
> +       .long   .Ldebug_abbrev0
> +       .byte   0x8
> +       .uleb128 0x1
> +       .long   .LASF0
> +       .byte   0xc
> +       .long   .LASF1
> +       .long   .LASF2
> +       .quad   .Ltext0
> +       .quad   .Letext0-.Ltext0
> +       .long   .Ldebug_line0
> +       .uleb128 0x2
> +       .string "bar"
> +       .byte   0x1
> +       .byte   0x1
> +       .byte   0xd
> +       .long   0x3b
> +       .uleb128 0x3
> +       .byte   0
> +       .uleb128 0x4
> +       .string "foo"
> +       .byte   0x1
> +       .byte   0x3
> +       .byte   0x6
> +       .quad   .LFB0
> +       .quad   .LFE0-.LFB0
> +       .uleb128 0x1
> +       .byte   0x9c
> +       .long   0x9a
> +       .uleb128 0x5
> +       .string "p"
> +       .byte   0x1
> +       .byte   0x3
> +       .byte   0xe
> +       .long   0x9a
> +       .long   .LLST0
> +       .long   .LVUS0
> +       .uleb128 0x6
> +       .long   .LASF3
> +       .byte   0x1
> +       .byte   0x4
> +       .byte   0x7
> +       .long   0x9a
> +       .long   .LLST1
> +       .long   .LVUS1
> +       .uleb128 0x7
> +       .quad   .LVL1
> +       .long   0x2d
> +       .uleb128 0x8
> +       .quad   .LVL2
> +       .long   0x2d
> +       .byte   0
> +       .uleb128 0x9
> +       .byte   0x4
> +       .byte   0x5
> +       .string "int"
> +       .byte   0
> +       .section        .debug_abbrev,"",@progbits
> +.Ldebug_abbrev0:
> +       .uleb128 0x1
> +       .uleb128 0x11
> +       .byte   0x1
> +       .uleb128 0x25
> +       .uleb128 0xe
> +       .uleb128 0x13
> +       .uleb128 0xb
> +       .uleb128 0x3
> +       .uleb128 0xe
> +       .uleb128 0x1b
> +       .uleb128 0xe
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x12
> +       .uleb128 0x7
> +       .uleb128 0x10
> +       .uleb128 0x17
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x2
> +       .uleb128 0x2e
> +       .byte   0x1
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x3c
> +       .uleb128 0x19
> +       .uleb128 0x1
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0x18
> +       .byte   0
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x4
> +       .uleb128 0x2e
> +       .byte   0x1
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x27
> +       .uleb128 0x19
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x12
> +       .uleb128 0x7
> +       .uleb128 0x40
> +       .uleb128 0x18
> +       .uleb128 0x2117
> +       .uleb128 0x19
> +       .uleb128 0x1
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x5
> +       .uleb128 0x5
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .uleb128 0x2
> +       .uleb128 0x17
> +       .uleb128 0x2137
> +       .uleb128 0x17
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x6
> +       .uleb128 0x34
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0xe
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .uleb128 0x2
> +       .uleb128 0x17
> +       .uleb128 0x2137
> +       .uleb128 0x17
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x7
> +       .uleb128 0x4109
> +       .byte   0
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x31
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x8
> +       .uleb128 0x4109
> +       .byte   0
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x2115
> +       .uleb128 0x19
> +       .uleb128 0x31
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x9
> +       .uleb128 0x24
> +       .byte   0
> +       .uleb128 0xb
> +       .uleb128 0xb
> +       .uleb128 0x3e
> +       .uleb128 0xb
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .byte   0
> +       .byte   0
> +       .byte   0
> +       .section        .debug_loc,"",@progbits
> +.Ldebug_loc0:
> +.LVUS0:
> +       .uleb128 0
> +       .uleb128 .LVU5
> +       .uleb128 .LVU5
> +       .uleb128 0
> +.LLST0:
> +       .quad   .LVL0-.Ltext0
> +       .quad   .LVL1-1-.Ltext0
> +       .value  0x1
> +       .byte   0x55
> +       .quad   .LVL1-1-.Ltext0
> +       .quad   .LFE0-.Ltext0
> +       .value  0x4
> +       .byte   0xf3
> +       .uleb128 0x1
> +       .byte   0x55
> +       .byte   0x9f
> +       .quad   0
> +       .quad   0
> +.LVUS1:
> +       .uleb128 .LVU2
> +       .uleb128 .LVU5
> +       .uleb128 .LVU5
> +       .uleb128 .LVU6
> +       .uleb128 .LVU6
> +       .uleb128 0
> +.LLST1:
> +       .quad   .LVL0-.Ltext0
> +       .quad   .LVL1-1-.Ltext0
> +       .value  0x1
> +       .byte   0x55
> +       .quad   .LVL1-1-.Ltext0
> +       .quad   .LVL1-.Ltext0
> +       .value  0x4
> +       .byte   0xf3
> +       .uleb128 0x1
> +       .byte   0x55
> +       .byte   0x9f
> +       .quad   .LVL1-.Ltext0
> +       .quad   .LFE0-.Ltext0
> +       .value  0x3
> +       .byte   0x8
> +       .byte   0x7b
> +       .byte   0x9f
> +       .quad   0
> +       .quad   0
> +       .section        .debug_aranges,"",@progbits
> +       .long   0x2c
> +       .value  0x2
> +       .long   .Ldebug_info0
> +       .byte   0x8
> +       .byte   0
> +       .value  0
> +       .value  0
> +       .quad   .Ltext0
> +       .quad   .Letext0-.Ltext0
> +       .quad   0
> +       .quad   0
> +       .section        .debug_line,"",@progbits
> +.Ldebug_line0:
> +       .section        .debug_str,"MS",@progbits,1
> +.LASF0:
> +       .string "GNU C17 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee] -mtune=generic -march=x86-64 -g -gdwarf-4 -O2"
> +.LASF1:
> +       .string "dwarf4.c"
> +.LASF3:
> +       .string "local"
> +.LASF2:
> +       .string "."
> +       .ident  "GCC: (GNU) 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee]"
> +       .section        .note.GNU-stack,"",@progbits
> diff --git a/ld/testsuite/ld-x86-64/dwarf5a.s b/ld/testsuite/ld-x86-64/dwarf5a.s
> new file mode 100644
> index 00000000000..08ec46bde30
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/dwarf5a.s
> @@ -0,0 +1,377 @@
> +/* Assembly outputs of
> +
> +extern void foo(int);
> +
> +int global;
> +
> +int main() {
> +  int local = global;
> +  foo(1);
> +  local = 123;
> +  foo(2);
> +  local = 456;
> +  return 0;
> +}
> +
> +compiled by GCC 14.2.1 with -O2 -g -gdwarf-5.  */
> +
> +       .file   "dwarf5a.c"
> +       .text
> +.Ltext0:
> +       .file 0 "." "dwarf5a.c"
> +       .section        .text.startup,"ax",@progbits
> +       .p2align 4
> +       .globl  main
> +       .type   main, @function
> +main:
> +.LFB0:
> +       .file 1 "dwarf5a.c"
> +       .loc 1 5 12 view -0
> +       .cfi_startproc
> +       .loc 1 6 3 view .LVU1
> +.LVL0:
> +       .loc 1 7 3 view .LVU2
> +       .loc 1 5 12 is_stmt 0 view .LVU3
> +       subq    $8, %rsp
> +       .cfi_def_cfa_offset 16
> +       .loc 1 7 3 view .LVU4
> +       movl    $1, %edi
> +       call    foo
> +.LVL1:
> +       .loc 1 8 3 is_stmt 1 view .LVU5
> +       .loc 1 9 3 view .LVU6
> +       movl    $2, %edi
> +       call    foo
> +.LVL2:
> +       .loc 1 10 3 view .LVU7
> +       .loc 1 11 3 view .LVU8
> +       .loc 1 12 1 is_stmt 0 view .LVU9
> +       xorl    %eax, %eax
> +       addq    $8, %rsp
> +       .cfi_def_cfa_offset 8
> +       ret
> +       .cfi_endproc
> +.LFE0:
> +       .size   main, .-main
> +       .globl  global
> +       .bss
> +       .align 4
> +       .type   global, @object
> +       .size   global, 4
> +global:
> +       .zero   4
> +       .text
> +.Letext0:
> +       .section        .debug_info,"",@progbits
> +.Ldebug_info0:
> +       .long   0xb3
> +       .value  0x5
> +       .byte   0x1
> +       .byte   0x8
> +       .long   .Ldebug_abbrev0
> +       .uleb128 0x2
> +       .long   .LASF4
> +       .byte   0x1d
> +       .long   .LASF0
> +       .long   .LASF1
> +       .long   .LLRL1
> +       .quad   0
> +       .long   .Ldebug_line0
> +       .uleb128 0x3
> +       .long   .LASF2
> +       .byte   0x1
> +       .byte   0x3
> +       .byte   0x5
> +       .long   0x40
> +       .uleb128 0x9
> +       .byte   0x3
> +       .quad   global
> +       .uleb128 0x4
> +       .byte   0x4
> +       .byte   0x5
> +       .string "int"
> +       .uleb128 0x5
> +       .string "foo"
> +       .byte   0x1
> +       .byte   0x1
> +       .byte   0xd
> +       .long   0x59
> +       .uleb128 0x6
> +       .long   0x40
> +       .byte   0
> +       .uleb128 0x7
> +       .long   .LASF5
> +       .byte   0x1
> +       .byte   0x5
> +       .byte   0x5
> +       .long   0x40
> +       .quad   .LFB0
> +       .quad   .LFE0-.LFB0
> +       .uleb128 0x1
> +       .byte   0x9c
> +       .uleb128 0x8
> +       .long   .LASF3
> +       .byte   0x1
> +       .byte   0x6
> +       .byte   0x7
> +       .long   0x40
> +       .long   .LLST0
> +       .long   .LVUS0
> +       .uleb128 0x9
> +       .quad   .LVL1
> +       .long   0x47
> +       .long   0xa2
> +       .uleb128 0x1
> +       .uleb128 0x1
> +       .byte   0x55
> +       .uleb128 0x1
> +       .byte   0x31
> +       .byte   0
> +       .uleb128 0xa
> +       .quad   .LVL2
> +       .long   0x47
> +       .uleb128 0x1
> +       .uleb128 0x1
> +       .byte   0x55
> +       .uleb128 0x1
> +       .byte   0x32
> +       .byte   0
> +       .byte   0
> +       .byte   0
> +       .section        .debug_abbrev,"",@progbits
> +.Ldebug_abbrev0:
> +       .uleb128 0x1
> +       .uleb128 0x49
> +       .byte   0
> +       .uleb128 0x2
> +       .uleb128 0x18
> +       .uleb128 0x7e
> +       .uleb128 0x18
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x2
> +       .uleb128 0x11
> +       .byte   0x1
> +       .uleb128 0x25
> +       .uleb128 0xe
> +       .uleb128 0x13
> +       .uleb128 0xb
> +       .uleb128 0x3
> +       .uleb128 0x1f
> +       .uleb128 0x1b
> +       .uleb128 0x1f
> +       .uleb128 0x55
> +       .uleb128 0x17
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x10
> +       .uleb128 0x17
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0x34
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0xe
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x2
> +       .uleb128 0x18
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x4
> +       .uleb128 0x24
> +       .byte   0
> +       .uleb128 0xb
> +       .uleb128 0xb
> +       .uleb128 0x3e
> +       .uleb128 0xb
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x5
> +       .uleb128 0x2e
> +       .byte   0x1
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x27
> +       .uleb128 0x19
> +       .uleb128 0x3c
> +       .uleb128 0x19
> +       .uleb128 0x1
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x6
> +       .uleb128 0x5
> +       .byte   0
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x7
> +       .uleb128 0x2e
> +       .byte   0x1
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x3
> +       .uleb128 0xe
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x12
> +       .uleb128 0x7
> +       .uleb128 0x40
> +       .uleb128 0x18
> +       .uleb128 0x7a
> +       .uleb128 0x19
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x8
> +       .uleb128 0x34
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0xe
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .uleb128 0x2
> +       .uleb128 0x17
> +       .uleb128 0x2137
> +       .uleb128 0x17
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x9
> +       .uleb128 0x48
> +       .byte   0x1
> +       .uleb128 0x7d
> +       .uleb128 0x1
> +       .uleb128 0x7f
> +       .uleb128 0x13
> +       .uleb128 0x1
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0xa
> +       .uleb128 0x48
> +       .byte   0x1
> +       .uleb128 0x7d
> +       .uleb128 0x1
> +       .uleb128 0x7f
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .byte   0
> +       .section        .debug_loclists,"",@progbits
> +       .long   .Ldebug_loc3-.Ldebug_loc2
> +.Ldebug_loc2:
> +       .value  0x5
> +       .byte   0x8
> +       .byte   0
> +       .long   0
> +.Ldebug_loc0:
> +.LVUS0:
> +       .uleb128 .LVU2
> +       .uleb128 .LVU5
> +       .uleb128 .LVU6
> +       .uleb128 .LVU8
> +       .uleb128 .LVU8
> +       .uleb128 0
> +.LLST0:
> +       .byte   0x6
> +       .quad   .LVL0
> +       .byte   0x4
> +       .uleb128 .LVL0-.LVL0
> +       .uleb128 .LVL1-1-.LVL0
> +       .uleb128 0x9
> +       .byte   0x3
> +       .quad   global
> +       .byte   0x4
> +       .uleb128 .LVL1-.LVL0
> +       .uleb128 .LVL2-.LVL0
> +       .uleb128 0x3
> +       .byte   0x8
> +       .byte   0x7b
> +       .byte   0x9f
> +       .byte   0x4
> +       .uleb128 .LVL2-.LVL0
> +       .uleb128 .LFE0-.LVL0
> +       .uleb128 0x4
> +       .byte   0xa
> +       .value  0x1c8
> +       .byte   0x9f
> +       .byte   0
> +.Ldebug_loc3:
> +       .section        .debug_aranges,"",@progbits
> +       .long   0x2c
> +       .value  0x2
> +       .long   .Ldebug_info0
> +       .byte   0x8
> +       .byte   0
> +       .value  0
> +       .value  0
> +       .quad   .LFB0
> +       .quad   .LFE0-.LFB0
> +       .quad   0
> +       .quad   0
> +       .section        .debug_rnglists,"",@progbits
> +.Ldebug_ranges0:
> +       .long   .Ldebug_ranges3-.Ldebug_ranges2
> +.Ldebug_ranges2:
> +       .value  0x5
> +       .byte   0x8
> +       .byte   0
> +       .long   0
> +.LLRL1:
> +       .byte   0x7
> +       .quad   .LFB0
> +       .uleb128 .LFE0-.LFB0
> +       .byte   0
> +.Ldebug_ranges3:
> +       .section        .debug_line,"",@progbits
> +.Ldebug_line0:
> +       .section        .debug_str,"MS",@progbits,1
> +.LASF3:
> +       .string "local"
> +.LASF4:
> +       .string "GNU C17 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee] -mtune=generic -march=x86-64 -g -gdwarf-5 -O2"
> +.LASF2:
> +       .string "global"
> +.LASF5:
> +       .string "main"
> +       .section        .debug_line_str,"MS",@progbits,1
> +.LASF0:
> +       .string "dwarf5a.c"
> +.LASF1:
> +       .string "."
> +       .ident  "GCC: (GNU) 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee]"
> +       .section        .note.GNU-stack,"",@progbits
> diff --git a/ld/testsuite/ld-x86-64/dwarf5b.s b/ld/testsuite/ld-x86-64/dwarf5b.s
> new file mode 100644
> index 00000000000..2b105374911
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/dwarf5b.s
> @@ -0,0 +1,321 @@
> +/* Assembly outputs of
> +
> +extern void foo(int);
> +
> +extern int global;
> +
> +void
> +bar (void)
> +{
> +  int local = global;
> +  foo(local);
> +  local = 123;
> +  foo(local);
> +  local = 456;
> +}
> +
> +compiled by GCC 14.2.1 with -O2 -g -gdwarf-5.  */
> +
> +       .file   "dwarf5b.c"
> +       .text
> +.Ltext0:
> +       .file 0 "." "dwarf5b.c"
> +       .p2align 4
> +       .globl  bar
> +       .type   bar, @function
> +bar:
> +.LFB0:
> +       .file 1 "dwarf5b.c"
> +       .loc 1 7 1 view -0
> +       .cfi_startproc
> +       .loc 1 8 3 view .LVU1
> +.LVL0:
> +       .loc 1 9 3 view .LVU2
> +       .loc 1 7 1 is_stmt 0 view .LVU3
> +       subq    $8, %rsp
> +       .cfi_def_cfa_offset 16
> +       .loc 1 9 3 view .LVU4
> +       movl    global(%rip), %edi
> +       call    foo
> +.LVL1:
> +       .loc 1 10 3 is_stmt 1 view .LVU5
> +       .loc 1 11 3 view .LVU6
> +       movl    $123, %edi
> +       .loc 1 13 1 is_stmt 0 view .LVU7
> +       addq    $8, %rsp
> +       .cfi_def_cfa_offset 8
> +       .loc 1 11 3 view .LVU8
> +       jmp     foo
> +.LVL2:
> +       .cfi_endproc
> +.LFE0:
> +       .size   bar, .-bar
> +.Letext0:
> +       .section        .debug_info,"",@progbits
> +.Ldebug_info0:
> +       .long   0xa0
> +       .value  0x5
> +       .byte   0x1
> +       .byte   0x8
> +       .long   .Ldebug_abbrev0
> +       .uleb128 0x1
> +       .long   .LASF4
> +       .byte   0x1d
> +       .long   .LASF0
> +       .long   .LASF1
> +       .quad   .Ltext0
> +       .quad   .Letext0-.Ltext0
> +       .long   .Ldebug_line0
> +       .uleb128 0x2
> +       .long   .LASF2
> +       .byte   0x1
> +       .byte   0x3
> +       .byte   0xc
> +       .long   0x3a
> +       .uleb128 0x3
> +       .byte   0x4
> +       .byte   0x5
> +       .string "int"
> +       .uleb128 0x4
> +       .string "foo"
> +       .byte   0x1
> +       .byte   0x1
> +       .byte   0xd
> +       .long   0x53
> +       .uleb128 0x5
> +       .long   0x3a
> +       .byte   0
> +       .uleb128 0x6
> +       .string "bar"
> +       .byte   0x1
> +       .byte   0x6
> +       .byte   0x1
> +       .quad   .LFB0
> +       .quad   .LFE0-.LFB0
> +       .uleb128 0x1
> +       .byte   0x9c
> +       .uleb128 0x7
> +       .long   .LASF3
> +       .byte   0x1
> +       .byte   0x8
> +       .byte   0x7
> +       .long   0x3a
> +       .long   .LLST0
> +       .long   .LVUS0
> +       .uleb128 0x8
> +       .quad   .LVL1
> +       .long   0x41
> +       .uleb128 0x9
> +       .quad   .LVL2
> +       .long   0x41
> +       .uleb128 0xa
> +       .uleb128 0x1
> +       .byte   0x55
> +       .uleb128 0x2
> +       .byte   0x8
> +       .byte   0x7b
> +       .byte   0
> +       .byte   0
> +       .byte   0
> +       .section        .debug_abbrev,"",@progbits
> +.Ldebug_abbrev0:
> +       .uleb128 0x1
> +       .uleb128 0x11
> +       .byte   0x1
> +       .uleb128 0x25
> +       .uleb128 0xe
> +       .uleb128 0x13
> +       .uleb128 0xb
> +       .uleb128 0x3
> +       .uleb128 0x1f
> +       .uleb128 0x1b
> +       .uleb128 0x1f
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x12
> +       .uleb128 0x7
> +       .uleb128 0x10
> +       .uleb128 0x17
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x2
> +       .uleb128 0x34
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0xe
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x3c
> +       .uleb128 0x19
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0x24
> +       .byte   0
> +       .uleb128 0xb
> +       .uleb128 0xb
> +       .uleb128 0x3e
> +       .uleb128 0xb
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x4
> +       .uleb128 0x2e
> +       .byte   0x1
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x27
> +       .uleb128 0x19
> +       .uleb128 0x3c
> +       .uleb128 0x19
> +       .uleb128 0x1
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x5
> +       .uleb128 0x5
> +       .byte   0
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x6
> +       .uleb128 0x2e
> +       .byte   0x1
> +       .uleb128 0x3f
> +       .uleb128 0x19
> +       .uleb128 0x3
> +       .uleb128 0x8
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x27
> +       .uleb128 0x19
> +       .uleb128 0x11
> +       .uleb128 0x1
> +       .uleb128 0x12
> +       .uleb128 0x7
> +       .uleb128 0x40
> +       .uleb128 0x18
> +       .uleb128 0x7a
> +       .uleb128 0x19
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x7
> +       .uleb128 0x34
> +       .byte   0
> +       .uleb128 0x3
> +       .uleb128 0xe
> +       .uleb128 0x3a
> +       .uleb128 0xb
> +       .uleb128 0x3b
> +       .uleb128 0xb
> +       .uleb128 0x39
> +       .uleb128 0xb
> +       .uleb128 0x49
> +       .uleb128 0x13
> +       .uleb128 0x2
> +       .uleb128 0x17
> +       .uleb128 0x2137
> +       .uleb128 0x17
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x8
> +       .uleb128 0x48
> +       .byte   0
> +       .uleb128 0x7d
> +       .uleb128 0x1
> +       .uleb128 0x7f
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0x9
> +       .uleb128 0x48
> +       .byte   0x1
> +       .uleb128 0x7d
> +       .uleb128 0x1
> +       .uleb128 0x82
> +       .uleb128 0x19
> +       .uleb128 0x7f
> +       .uleb128 0x13
> +       .byte   0
> +       .byte   0
> +       .uleb128 0xa
> +       .uleb128 0x49
> +       .byte   0
> +       .uleb128 0x2
> +       .uleb128 0x18
> +       .uleb128 0x7e
> +       .uleb128 0x18
> +       .byte   0
> +       .byte   0
> +       .byte   0
> +       .section        .debug_loclists,"",@progbits
> +       .long   .Ldebug_loc3-.Ldebug_loc2
> +.Ldebug_loc2:
> +       .value  0x5
> +       .byte   0x8
> +       .byte   0
> +       .long   0
> +.Ldebug_loc0:
> +.LVUS0:
> +       .uleb128 .LVU6
> +       .uleb128 0
> +.LLST0:
> +       .byte   0x4
> +       .uleb128 .LVL1-.Ltext0
> +       .uleb128 .LFE0-.Ltext0
> +       .uleb128 0x3
> +       .byte   0x8
> +       .byte   0x7b
> +       .byte   0x9f
> +       .byte   0
> +.Ldebug_loc3:
> +       .section        .debug_aranges,"",@progbits
> +       .long   0x2c
> +       .value  0x2
> +       .long   .Ldebug_info0
> +       .byte   0x8
> +       .byte   0
> +       .value  0
> +       .value  0
> +       .quad   .Ltext0
> +       .quad   .Letext0-.Ltext0
> +       .quad   0
> +       .quad   0
> +       .section        .debug_line,"",@progbits
> +.Ldebug_line0:
> +       .section        .debug_str,"MS",@progbits,1
> +.LASF3:
> +       .string "local"
> +.LASF4:
> +       .string "GNU C17 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee] -mtune=generic -march=x86-64 -g -gdwarf-5 -O2"
> +.LASF2:
> +       .string "global"
> +       .section        .debug_line_str,"MS",@progbits,1
> +.LASF1:
> +       .string "."
> +.LASF0:
> +       .string "dwarf5b.c"
> +       .ident  "GCC: (GNU) 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee]"
> +       .section        .note.GNU-stack,"",@progbits
> diff --git a/ld/testsuite/ld-x86-64/pr32809.d b/ld/testsuite/ld-x86-64/pr32809.d
> new file mode 100644
> index 00000000000..3affc23fa4c
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/pr32809.d
> @@ -0,0 +1,71 @@
> +#source: dwarf5a.s
> +#source: dwarf4.s
> +#source: dwarf5b.s
> +#as: --64
> +#ld: -r -m elf_x86_64
> +#readelf: --wide --debug-dump=loc
> +
> +Contents of the .*ebug_loc section:
> +
> +    Offset   Begin            End              Expression
> +
> +    00000000 v000000000000000 v000000000000000 location view pair
> +    00000002 v000000000000000 v000000000000000 location view pair
> +
> +    00000004 v000000000000000 v000000000000000 views at 00000000 for:
> +             0000000000000000 000000000000000a \(DW_OP_reg5 \(rdi\)\)
> +    00000017 v000000000000000 v000000000000000 views at 00000002 for:
> +             000000000000000a 0000000000000016 \(DW_OP_GNU_entry_value: \(DW_OP_reg5 \(rdi\)\); DW_OP_stack_value\)
> +    0000002d <End of list>
> +
> +    0000003d v000000000000002 v000000000000000 location view pair
> +    0000003f v000000000000000 v000000000000001 location view pair
> +    00000041 v000000000000001 v000000000000000 location view pair
> +
> +    00000043 v000000000000002 v000000000000000 views at 0000003d for:
> +             0000000000000000 000000000000000a \(DW_OP_reg5 \(rdi\)\)
> +    00000056 v000000000000000 v000000000000001 views at 0000003f for:
> +             000000000000000a 000000000000000b \(DW_OP_GNU_entry_value: \(DW_OP_reg5 \(rdi\)\); DW_OP_stack_value\)
> +    0000006c v000000000000001 v000000000000000 views at 00000041 for:
> +             000000000000000b 0000000000000016 \(DW_OP_const1u: 123; DW_OP_stack_value\)
> +    00000081 <End of list>
> +
> +Contents of the .*ebug_loclists section:
> +
> +Table at Offset 0
> +  Length:          0x34
> +  DWARF version:   5
> +  Address size:    8
> +  Segment size:    0
> +  Offset entries:  0
> +
> +    Offset   Begin            End              Expression
> +
> +    0000000c v000000000000002 v000000000000000 location view pair
> +    0000000e v000000000000001 v000000000000001 location view pair
> +    00000010 v000000000000001 v000000000000000 location view pair
> +
> +    00000012 0000000000000000 \(base address\)
> +    0000001b v000000000000002 v000000000000000 views at 0000000c for:
> +             0000000000000000 000000000000000d \(DW_OP_addr: 0\)
> +    00000028 v000000000000001 v000000000000001 views at 0000000e for:
> +             000000000000000e 0000000000000018 \(DW_OP_const1u: 123; DW_OP_stack_value\)
> +    0000002f v000000000000001 v000000000000000 views at 00000010 for:
> +             0000000000000018 000000000000001f \(DW_OP_const2u: 456; DW_OP_stack_value\)
> +    00000037 <End of list>
> +Table at Offset 0x38
> +  Length:          0x12
> +  DWARF version:   5
> +  Address size:    8
> +  Segment size:    0
> +  Offset entries:  0
> +
> +    Offset   Begin            End              Expression
> +
> +    00000044 v000000000000001 v000000000000000 location view pair
> +
> +    00000046 v000000000000001 v000000000000000 views at 00000044 for:
> +             000000000000002f 000000000000003d \(DW_OP_const1u: 123; DW_OP_stack_value\)
> +    0000004d <End of list>
> +
> +#pass
> diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
> index 01d6459b5d7..7fe3d224ad2 100644
> --- a/ld/testsuite/ld-x86-64/x86-64.exp
> +++ b/ld/testsuite/ld-x86-64/x86-64.exp
> @@ -563,6 +563,7 @@ run_dump_test "pr32591-3"
>  run_dump_test "pr32591-3-x32"
>  run_dump_test "pr32591-4"
>  run_dump_test "pr32591-4-x32"
> +run_dump_test "pr32809"
>
>  if { ![skip_sframe_tests] } {
>      run_dump_test "sframe-simple-1"
> --
> 2.49.0
>

PING

-- 
H.J.


More information about the Binutils mailing list