[binutils-gdb] dwarf: Dump .debug_loclists only for DWARF-5

H.J. Lu hjl@sourceware.org
Tue Apr 29 06:31:55 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=82bdc396a40e64ea17acdba072bafbb3f620518f

commit 82bdc396a40e64ea17acdba072bafbb3f620518f
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Mar 20 13:16:34 2025 -0700

    dwarf: Dump .debug_loclists only for DWARF-5
    
    .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>

Diff:
---
 binutils/dwarf.c                  |  14 +-
 ld/testsuite/ld-x86-64/dwarf4.s   | 346 +++++++++++++++++++++++++++++++++
 ld/testsuite/ld-x86-64/dwarf5a.s  | 400 ++++++++++++++++++++++++++++++++++++++
 ld/testsuite/ld-x86-64/dwarf5b.s  | 345 ++++++++++++++++++++++++++++++++
 ld/testsuite/ld-x86-64/pr32809.d  |  71 +++++++
 ld/testsuite/ld-x86-64/x86-64.exp |   1 +
 6 files changed, 1175 insertions(+), 2 deletions(-)

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..7f1a90dd75f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/dwarf4.s
@@ -0,0 +1,346 @@
+/* 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 -dA -gdwarf-4.  */
+
+	.file	"dwarf4.c"
+	.text
+.Ltext0:
+	.file 1 "dwarf4.c"
+	.p2align 4
+	.globl	foo
+	.type	foo, @function
+foo:
+.LVL0:
+	# DEBUG p => di
+.LFB0:
+	# dwarf4.c:3:17
+	.loc 1 3 17 view -0
+	.cfi_startproc
+# BLOCK 2, count:1073741824 (estimated locally) seq:0
+# PRED: ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU)
+	# dwarf4.c:4:3
+	.loc 1 4 3 view .LVU1
+	# DEBUG local => di
+	# dwarf4.c:5:3
+	.loc 1 5 3 view .LVU2
+	# dwarf4.c:3:17
+	.loc 1 3 17 is_stmt 0 view .LVU3
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 16
+	# dwarf4.c:5:3
+	.loc 1 5 3 view .LVU4
+	xorl	%eax, %eax
+	call	bar
+.LVL1:
+	# DEBUG local => entry_value#0
+	# DEBUG p => entry_value#0
+	# dwarf4.c:6:3
+	.loc 1 6 3 is_stmt 1 view .LVU5
+	# DEBUG local => 0x7b
+	# dwarf4.c:7:3
+	.loc 1 7 3 view .LVU6
+	xorl	%eax, %eax
+	# dwarf4.c:9:1
+	.loc 1 9 1 is_stmt 0 view .LVU7
+	addq	$8, %rsp
+	.cfi_def_cfa_offset 8
+# SUCC: EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (ABNORMAL,SIBCALL)
+	# dwarf4.c:7:3
+	.loc 1 7 3 view .LVU8
+	jmp	bar
+.LVL2:
+	.cfi_endproc
+.LFE0:
+	.size	foo, .-foo
+.Letext0:
+	.section	.debug_info,"",@progbits
+.Ldebug_info0:
+	.long	0x9e	# Length of Compilation Unit Info
+	.value	0x4	# DWARF version number
+	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
+	.byte	0x8	# Pointer Size (in bytes)
+	.uleb128 0x1	# (DIE (0xb) DW_TAG_compile_unit)
+	.long	.LASF0	# DW_AT_producer: "GNU C17 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee] -mtune=generic -march=x86-64 -g -gdwarf-4 -O2"
+	.byte	0xc	# DW_AT_language
+	.long	.LASF1	# DW_AT_name: "dwarf4.c"
+	.long	.LASF2	# DW_AT_comp_dir: "."
+	.quad	.Ltext0	# DW_AT_low_pc
+	.quad	.Letext0-.Ltext0	# DW_AT_high_pc
+	.long	.Ldebug_line0	# DW_AT_stmt_list
+	.uleb128 0x2	# (DIE (0x2d) DW_TAG_subprogram)
+			# DW_AT_external
+	.ascii "bar\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_decl_file (dwarf4.c)
+	.byte	0x1	# DW_AT_decl_line
+	.byte	0xd	# DW_AT_decl_column
+			# DW_AT_declaration
+	.long	0x3b	# DW_AT_sibling
+	.uleb128 0x3	# (DIE (0x39) DW_TAG_unspecified_parameters)
+	.byte	0	# end of children of DIE 0x2d
+	.uleb128 0x4	# (DIE (0x3b) DW_TAG_subprogram)
+			# DW_AT_external
+	.ascii "foo\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_decl_file (dwarf4.c)
+	.byte	0x3	# DW_AT_decl_line
+	.byte	0x6	# DW_AT_decl_column
+			# DW_AT_prototyped
+	.quad	.LFB0	# DW_AT_low_pc
+	.quad	.LFE0-.LFB0	# DW_AT_high_pc
+	.uleb128 0x1	# DW_AT_frame_base
+	.byte	0x9c	# DW_OP_call_frame_cfa
+			# DW_AT_GNU_all_call_sites
+	.long	0x9a	# DW_AT_sibling
+	.uleb128 0x5	# (DIE (0x59) DW_TAG_formal_parameter)
+	.ascii "p\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_decl_file (dwarf4.c)
+	.byte	0x3	# DW_AT_decl_line
+	.byte	0xe	# DW_AT_decl_column
+	.long	0x9a	# DW_AT_type
+	.long	.LLST0	# DW_AT_location
+	.long	.LVUS0	# DW_AT_GNU_locviews
+	.uleb128 0x6	# (DIE (0x6b) DW_TAG_variable)
+	.long	.LASF3	# DW_AT_name: "local"
+	.byte	0x1	# DW_AT_decl_file (dwarf4.c)
+	.byte	0x4	# DW_AT_decl_line
+	.byte	0x7	# DW_AT_decl_column
+	.long	0x9a	# DW_AT_type
+	.long	.LLST1	# DW_AT_location
+	.long	.LVUS1	# DW_AT_GNU_locviews
+	.uleb128 0x7	# (DIE (0x7f) DW_TAG_GNU_call_site)
+	.quad	.LVL1	# DW_AT_low_pc
+	.long	0x2d	# DW_AT_abstract_origin
+	.uleb128 0x8	# (DIE (0x8c) DW_TAG_GNU_call_site)
+	.quad	.LVL2	# DW_AT_low_pc
+			# DW_AT_GNU_tail_call
+	.long	0x2d	# DW_AT_abstract_origin
+	.byte	0	# end of children of DIE 0x3b
+	.uleb128 0x9	# (DIE (0x9a) DW_TAG_base_type)
+	.byte	0x4	# DW_AT_byte_size
+	.byte	0x5	# DW_AT_encoding
+	.ascii "int\0"	# DW_AT_name
+	.byte	0	# end of children of DIE 0xb
+	.section	.debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1	# (abbrev code)
+	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x25	# (DW_AT_producer)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x13	# (DW_AT_language)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x1b	# (DW_AT_comp_dir)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x12	# (DW_AT_high_pc)
+	.uleb128 0x7	# (DW_FORM_data8)
+	.uleb128 0x10	# (DW_AT_stmt_list)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.byte	0
+	.byte	0
+	.uleb128 0x2	# (abbrev code)
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3c	# (DW_AT_declaration)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x1	# (DW_AT_sibling)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x3	# (abbrev code)
+	.uleb128 0x18	# (TAG: DW_TAG_unspecified_parameters)
+	.byte	0	# DW_children_no
+	.byte	0
+	.byte	0
+	.uleb128 0x4	# (abbrev code)
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x27	# (DW_AT_prototyped)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x12	# (DW_AT_high_pc)
+	.uleb128 0x7	# (DW_FORM_data8)
+	.uleb128 0x40	# (DW_AT_frame_base)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.uleb128 0x2117	# (DW_AT_GNU_all_call_sites)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x1	# (DW_AT_sibling)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x5	# (abbrev code)
+	.uleb128 0x5	# (TAG: DW_TAG_formal_parameter)
+	.byte	0	# DW_children_no
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x2	# (DW_AT_location)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.uleb128 0x2137	# (DW_AT_GNU_locviews)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.byte	0
+	.byte	0
+	.uleb128 0x6	# (abbrev code)
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
+	.byte	0	# DW_children_no
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x2	# (DW_AT_location)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.uleb128 0x2137	# (DW_AT_GNU_locviews)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.byte	0
+	.byte	0
+	.uleb128 0x7	# (abbrev code)
+	.uleb128 0x4109	# (TAG: DW_TAG_GNU_call_site)
+	.byte	0	# DW_children_no
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x31	# (DW_AT_abstract_origin)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x8	# (abbrev code)
+	.uleb128 0x4109	# (TAG: DW_TAG_GNU_call_site)
+	.byte	0	# DW_children_no
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x2115	# (DW_AT_GNU_tail_call)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x31	# (DW_AT_abstract_origin)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x9	# (abbrev code)
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
+	.byte	0	# DW_children_no
+	.uleb128 0xb	# (DW_AT_byte_size)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3e	# (DW_AT_encoding)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_loc,"",@progbits
+.Ldebug_loc0:
+.LVUS0:
+	.uleb128 0	# View list begin (*.LVUS0)
+	.uleb128 .LVU5	# View list end (*.LVUS0)
+	.uleb128 .LVU5	# View list begin (*.LVUS0)
+	.uleb128 0	# View list end (*.LVUS0)
+.LLST0:
+	.quad	.LVL0-.Ltext0	# Location list begin address (*.LLST0)
+	.quad	.LVL1-1-.Ltext0	# Location list end address (*.LLST0)
+	.value	0x1	# Location expression size
+	.byte	0x55	# DW_OP_reg5
+	.quad	.LVL1-1-.Ltext0	# Location list begin address (*.LLST0)
+	.quad	.LFE0-.Ltext0	# Location list end address (*.LLST0)
+	.value	0x4	# Location expression size
+	.byte	0xf3	# DW_OP_GNU_entry_value
+	.uleb128 0x1
+	.byte	0x55	# DW_OP_reg5
+	.byte	0x9f	# DW_OP_stack_value
+	.quad	0	# Location list terminator begin (*.LLST0)
+	.quad	0	# Location list terminator end (*.LLST0)
+.LVUS1:
+	.uleb128 .LVU2	# View list begin (*.LVUS1)
+	.uleb128 .LVU5	# View list end (*.LVUS1)
+	.uleb128 .LVU5	# View list begin (*.LVUS1)
+	.uleb128 .LVU6	# View list end (*.LVUS1)
+	.uleb128 .LVU6	# View list begin (*.LVUS1)
+	.uleb128 0	# View list end (*.LVUS1)
+.LLST1:
+	.quad	.LVL0-.Ltext0	# Location list begin address (*.LLST1)
+	.quad	.LVL1-1-.Ltext0	# Location list end address (*.LLST1)
+	.value	0x1	# Location expression size
+	.byte	0x55	# DW_OP_reg5
+	.quad	.LVL1-1-.Ltext0	# Location list begin address (*.LLST1)
+	.quad	.LVL1-.Ltext0	# Location list end address (*.LLST1)
+	.value	0x4	# Location expression size
+	.byte	0xf3	# DW_OP_GNU_entry_value
+	.uleb128 0x1
+	.byte	0x55	# DW_OP_reg5
+	.byte	0x9f	# DW_OP_stack_value
+	.quad	.LVL1-.Ltext0	# Location list begin address (*.LLST1)
+	.quad	.LFE0-.Ltext0	# Location list end address (*.LLST1)
+	.value	0x3	# Location expression size
+	.byte	0x8	# DW_OP_const1u
+	.byte	0x7b
+	.byte	0x9f	# DW_OP_stack_value
+	.quad	0	# Location list terminator begin (*.LLST1)
+	.quad	0	# Location list terminator end (*.LLST1)
+	.section	.debug_aranges,"",@progbits
+	.long	0x2c	# Length of Address Ranges Info
+	.value	0x2	# DWARF aranges version
+	.long	.Ldebug_info0	# Offset of Compilation Unit Info
+	.byte	0x8	# Size of Address
+	.byte	0	# Size of Segment Descriptor
+	.value	0	# Pad to 16 byte boundary
+	.value	0
+	.quad	.Ltext0	# Address
+	.quad	.Letext0-.Ltext0	# Length
+	.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..eefaaf49c56
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/dwarf5a.s
@@ -0,0 +1,400 @@
+/* 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 -dA -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"
+	# dwarf5a.c:5:12
+	.loc 1 5 12 view -0
+	.cfi_startproc
+# BLOCK 2, count:1073741824 (estimated locally) seq:0
+# PRED: ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU)
+	# dwarf5a.c:6:3
+	.loc 1 6 3 view .LVU1
+.LVL0:
+	# DEBUG local => [`global']
+	# dwarf5a.c:7:3
+	.loc 1 7 3 view .LVU2
+	# dwarf5a.c:5:12
+	.loc 1 5 12 is_stmt 0 view .LVU3
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 16
+	# dwarf5a.c:7:3
+	.loc 1 7 3 view .LVU4
+	movl	$1, %edi
+	call	foo
+.LVL1:
+	# DEBUG local RESET
+	# dwarf5a.c:8:3
+	.loc 1 8 3 is_stmt 1 view .LVU5
+	# DEBUG local => 0x7b
+	# dwarf5a.c:9:3
+	.loc 1 9 3 view .LVU6
+	movl	$2, %edi
+	call	foo
+.LVL2:
+	# dwarf5a.c:10:3
+	.loc 1 10 3 view .LVU7
+	# DEBUG local => 0x1c8
+	# dwarf5a.c:11:3
+	.loc 1 11 3 view .LVU8
+	# dwarf5a.c:12:1
+	.loc 1 12 1 is_stmt 0 view .LVU9
+	xorl	%eax, %eax
+	addq	$8, %rsp
+	.cfi_def_cfa_offset 8
+# SUCC: EXIT [always]  count:1073741824 (estimated locally, freq 1.0000)
+	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	# Length of Compilation Unit Info
+	.value	0x5	# DWARF version number
+	.byte	0x1	# DW_UT_compile
+	.byte	0x8	# Pointer Size (in bytes)
+	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
+	.uleb128 0x2	# (DIE (0xc) DW_TAG_compile_unit)
+	.long	.LASF4	# DW_AT_producer: "GNU C17 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee] -mtune=generic -march=x86-64 -g -gdwarf-5 -O2"
+	.byte	0x1d	# DW_AT_language
+	.long	.LASF0	# DW_AT_name: "dwarf5a.c"
+	.long	.LASF1	# DW_AT_comp_dir: "."
+	.long	.LLRL1	# DW_AT_ranges
+	.quad	0	# DW_AT_low_pc
+	.long	.Ldebug_line0	# DW_AT_stmt_list
+	.uleb128 0x3	# (DIE (0x2a) DW_TAG_variable)
+	.long	.LASF2	# DW_AT_name: "global"
+	.byte	0x1	# DW_AT_decl_file (dwarf5a.c)
+	.byte	0x3	# DW_AT_decl_line
+	.byte	0x5	# DW_AT_decl_column
+	.long	0x40	# DW_AT_type
+			# DW_AT_external
+	.uleb128 0x9	# DW_AT_location
+	.byte	0x3	# DW_OP_addr
+	.quad	global
+	.uleb128 0x4	# (DIE (0x40) DW_TAG_base_type)
+	.byte	0x4	# DW_AT_byte_size
+	.byte	0x5	# DW_AT_encoding
+	.ascii "int\0"	# DW_AT_name
+	.uleb128 0x5	# (DIE (0x47) DW_TAG_subprogram)
+			# DW_AT_external
+	.ascii "foo\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_decl_file (dwarf5a.c)
+	.byte	0x1	# DW_AT_decl_line
+	.byte	0xd	# DW_AT_decl_column
+			# DW_AT_prototyped
+			# DW_AT_declaration
+	.long	0x59	# DW_AT_sibling
+	.uleb128 0x6	# (DIE (0x53) DW_TAG_formal_parameter)
+	.long	0x40	# DW_AT_type
+	.byte	0	# end of children of DIE 0x47
+	.uleb128 0x7	# (DIE (0x59) DW_TAG_subprogram)
+			# DW_AT_external
+	.long	.LASF5	# DW_AT_name: "main"
+	.byte	0x1	# DW_AT_decl_file (dwarf5a.c)
+	.byte	0x5	# DW_AT_decl_line
+	.byte	0x5	# DW_AT_decl_column
+	.long	0x40	# DW_AT_type
+	.quad	.LFB0	# DW_AT_low_pc
+	.quad	.LFE0-.LFB0	# DW_AT_high_pc
+	.uleb128 0x1	# DW_AT_frame_base
+	.byte	0x9c	# DW_OP_call_frame_cfa
+			# DW_AT_call_all_calls
+	.uleb128 0x8	# (DIE (0x77) DW_TAG_variable)
+	.long	.LASF3	# DW_AT_name: "local"
+	.byte	0x1	# DW_AT_decl_file (dwarf5a.c)
+	.byte	0x6	# DW_AT_decl_line
+	.byte	0x7	# DW_AT_decl_column
+	.long	0x40	# DW_AT_type
+	.long	.LLST0	# DW_AT_location
+	.long	.LVUS0	# DW_AT_GNU_locviews
+	.uleb128 0x9	# (DIE (0x8b) DW_TAG_call_site)
+	.quad	.LVL1	# DW_AT_call_return_pc
+	.long	0x47	# DW_AT_call_origin
+	.long	0xa2	# DW_AT_sibling
+	.uleb128 0x1	# (DIE (0x9c) DW_TAG_call_site_parameter)
+	.uleb128 0x1	# DW_AT_location
+	.byte	0x55	# DW_OP_reg5
+	.uleb128 0x1	# DW_AT_call_value
+	.byte	0x31	# DW_OP_lit1
+	.byte	0	# end of children of DIE 0x8b
+	.uleb128 0xa	# (DIE (0xa2) DW_TAG_call_site)
+	.quad	.LVL2	# DW_AT_call_return_pc
+	.long	0x47	# DW_AT_call_origin
+	.uleb128 0x1	# (DIE (0xaf) DW_TAG_call_site_parameter)
+	.uleb128 0x1	# DW_AT_location
+	.byte	0x55	# DW_OP_reg5
+	.uleb128 0x1	# DW_AT_call_value
+	.byte	0x32	# DW_OP_lit2
+	.byte	0	# end of children of DIE 0xa2
+	.byte	0	# end of children of DIE 0x59
+	.byte	0	# end of children of DIE 0xc
+	.section	.debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1	# (abbrev code)
+	.uleb128 0x49	# (TAG: DW_TAG_call_site_parameter)
+	.byte	0	# DW_children_no
+	.uleb128 0x2	# (DW_AT_location)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.uleb128 0x7e	# (DW_AT_call_value)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.byte	0
+	.byte	0
+	.uleb128 0x2	# (abbrev code)
+	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x25	# (DW_AT_producer)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x13	# (DW_AT_language)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x1f	# (DW_FORM_line_strp)
+	.uleb128 0x1b	# (DW_AT_comp_dir)
+	.uleb128 0x1f	# (DW_FORM_line_strp)
+	.uleb128 0x55	# (DW_AT_ranges)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x10	# (DW_AT_stmt_list)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.byte	0
+	.byte	0
+	.uleb128 0x3	# (abbrev code)
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
+	.byte	0	# DW_children_no
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x2	# (DW_AT_location)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.byte	0
+	.byte	0
+	.uleb128 0x4	# (abbrev code)
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
+	.byte	0	# DW_children_no
+	.uleb128 0xb	# (DW_AT_byte_size)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3e	# (DW_AT_encoding)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.byte	0
+	.byte	0
+	.uleb128 0x5	# (abbrev code)
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x27	# (DW_AT_prototyped)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3c	# (DW_AT_declaration)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x1	# (DW_AT_sibling)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x6	# (abbrev code)
+	.uleb128 0x5	# (TAG: DW_TAG_formal_parameter)
+	.byte	0	# DW_children_no
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x7	# (abbrev code)
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x12	# (DW_AT_high_pc)
+	.uleb128 0x7	# (DW_FORM_data8)
+	.uleb128 0x40	# (DW_AT_frame_base)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.uleb128 0x7a	# (DW_AT_call_all_calls)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.byte	0
+	.byte	0
+	.uleb128 0x8	# (abbrev code)
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
+	.byte	0	# DW_children_no
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x2	# (DW_AT_location)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.uleb128 0x2137	# (DW_AT_GNU_locviews)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.byte	0
+	.byte	0
+	.uleb128 0x9	# (abbrev code)
+	.uleb128 0x48	# (TAG: DW_TAG_call_site)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x7d	# (DW_AT_call_return_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x7f	# (DW_AT_call_origin)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x1	# (DW_AT_sibling)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0xa	# (abbrev code)
+	.uleb128 0x48	# (TAG: DW_TAG_call_site)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x7d	# (DW_AT_call_return_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x7f	# (DW_AT_call_origin)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_loclists,"",@progbits
+	.long	.Ldebug_loc3-.Ldebug_loc2	# Length of Location Lists
+.Ldebug_loc2:
+	.value	0x5	# DWARF version number
+	.byte	0x8	# Address Size
+	.byte	0	# Segment Size
+	.long	0	# Offset Entry Count
+.Ldebug_loc0:
+.LVUS0:
+	.uleb128 .LVU2	# View list begin (*.LVUS0)
+	.uleb128 .LVU5	# View list end (*.LVUS0)
+	.uleb128 .LVU6	# View list begin (*.LVUS0)
+	.uleb128 .LVU8	# View list end (*.LVUS0)
+	.uleb128 .LVU8	# View list begin (*.LVUS0)
+	.uleb128 0	# View list end (*.LVUS0)
+.LLST0:
+	.byte	0x6	# DW_LLE_base_address (*.LLST0)
+	.quad	.LVL0	# Base address (*.LLST0)
+	.byte	0x4	# DW_LLE_offset_pair (*.LLST0)
+	.uleb128 .LVL0-.LVL0	# Location list begin address (*.LLST0)
+	.uleb128 .LVL1-1-.LVL0	# Location list end address (*.LLST0)
+	.uleb128 0x9	# Location expression size
+	.byte	0x3	# DW_OP_addr
+	.quad	global
+	.byte	0x4	# DW_LLE_offset_pair (*.LLST0)
+	.uleb128 .LVL1-.LVL0	# Location list begin address (*.LLST0)
+	.uleb128 .LVL2-.LVL0	# Location list end address (*.LLST0)
+	.uleb128 0x3	# Location expression size
+	.byte	0x8	# DW_OP_const1u
+	.byte	0x7b
+	.byte	0x9f	# DW_OP_stack_value
+	.byte	0x4	# DW_LLE_offset_pair (*.LLST0)
+	.uleb128 .LVL2-.LVL0	# Location list begin address (*.LLST0)
+	.uleb128 .LFE0-.LVL0	# Location list end address (*.LLST0)
+	.uleb128 0x4	# Location expression size
+	.byte	0xa	# DW_OP_const2u
+	.value	0x1c8
+	.byte	0x9f	# DW_OP_stack_value
+	.byte	0	# DW_LLE_end_of_list (*.LLST0)
+.Ldebug_loc3:
+	.section	.debug_aranges,"",@progbits
+	.long	0x2c	# Length of Address Ranges Info
+	.value	0x2	# DWARF aranges version
+	.long	.Ldebug_info0	# Offset of Compilation Unit Info
+	.byte	0x8	# Size of Address
+	.byte	0	# Size of Segment Descriptor
+	.value	0	# Pad to 16 byte boundary
+	.value	0
+	.quad	.LFB0	# Address
+	.quad	.LFE0-.LFB0	# Length
+	.quad	0
+	.quad	0
+	.section	.debug_rnglists,"",@progbits
+.Ldebug_ranges0:
+	.long	.Ldebug_ranges3-.Ldebug_ranges2	# Length of Range Lists
+.Ldebug_ranges2:
+	.value	0x5	# DWARF version number
+	.byte	0x8	# Address Size
+	.byte	0	# Segment Size
+	.long	0	# Offset Entry Count
+.LLRL1:
+	.byte	0x7	# DW_RLE_start_length (*.LLRL1)
+	.quad	.LFB0	# Range begin address (*.LLRL1)
+	.uleb128 .LFE0-.LFB0	# Range length (*.LLRL1)
+	.byte	0	# DW_RLE_end_of_list (*.LLRL1)
+.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..4d344692280
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/dwarf5b.s
@@ -0,0 +1,345 @@
+/* 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 -dA -gdwarf-5.  */
+
+	.file	"dwarf5b.c"
+	.text
+.Ltext0:
+	.file 0 "." "dwarf5b.c"
+	.p2align 4
+	.globl	bar
+	.type	bar, @function
+bar:
+.LFB0:
+	.file 1 "dwarf5b.c"
+	# dwarf5b.c:7:1
+	.loc 1 7 1 view -0
+	.cfi_startproc
+# BLOCK 2, count:1073741824 (estimated locally) seq:0
+# PRED: ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU)
+	# dwarf5b.c:8:3
+	.loc 1 8 3 view .LVU1
+.LVL0:
+	# DEBUG local => [`global']
+	# dwarf5b.c:9:3
+	.loc 1 9 3 view .LVU2
+	# dwarf5b.c:7:1
+	.loc 1 7 1 is_stmt 0 view .LVU3
+	subq	$8, %rsp
+	.cfi_def_cfa_offset 16
+	# dwarf5b.c:9:3
+	.loc 1 9 3 view .LVU4
+	movl	global(%rip), %edi
+	call	foo
+.LVL1:
+	# DEBUG local RESET
+	# dwarf5b.c:10:3
+	.loc 1 10 3 is_stmt 1 view .LVU5
+	# DEBUG local => 0x7b
+	# dwarf5b.c:11:3
+	.loc 1 11 3 view .LVU6
+	movl	$123, %edi
+	# dwarf5b.c:13:1
+	.loc 1 13 1 is_stmt 0 view .LVU7
+	addq	$8, %rsp
+	.cfi_def_cfa_offset 8
+# SUCC: EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (ABNORMAL,SIBCALL)
+	# dwarf5b.c:11:3
+	.loc 1 11 3 view .LVU8
+	jmp	foo
+.LVL2:
+	.cfi_endproc
+.LFE0:
+	.size	bar, .-bar
+.Letext0:
+	.section	.debug_info,"",@progbits
+.Ldebug_info0:
+	.long	0xa0	# Length of Compilation Unit Info
+	.value	0x5	# DWARF version number
+	.byte	0x1	# DW_UT_compile
+	.byte	0x8	# Pointer Size (in bytes)
+	.long	.Ldebug_abbrev0	# Offset Into Abbrev. Section
+	.uleb128 0x1	# (DIE (0xc) DW_TAG_compile_unit)
+	.long	.LASF4	# DW_AT_producer: "GNU C17 14.2.1 20240906 [releases/gcc-14 r14-10649-gaedf6f810ee] -mtune=generic -march=x86-64 -g -gdwarf-5 -O2"
+	.byte	0x1d	# DW_AT_language
+	.long	.LASF0	# DW_AT_name: "dwarf5b.c"
+	.long	.LASF1	# DW_AT_comp_dir: "."
+	.quad	.Ltext0	# DW_AT_low_pc
+	.quad	.Letext0-.Ltext0	# DW_AT_high_pc
+	.long	.Ldebug_line0	# DW_AT_stmt_list
+	.uleb128 0x2	# (DIE (0x2e) DW_TAG_variable)
+	.long	.LASF2	# DW_AT_name: "global"
+	.byte	0x1	# DW_AT_decl_file (dwarf5b.c)
+	.byte	0x3	# DW_AT_decl_line
+	.byte	0xc	# DW_AT_decl_column
+	.long	0x3a	# DW_AT_type
+			# DW_AT_external
+			# DW_AT_declaration
+	.uleb128 0x3	# (DIE (0x3a) DW_TAG_base_type)
+	.byte	0x4	# DW_AT_byte_size
+	.byte	0x5	# DW_AT_encoding
+	.ascii "int\0"	# DW_AT_name
+	.uleb128 0x4	# (DIE (0x41) DW_TAG_subprogram)
+			# DW_AT_external
+	.ascii "foo\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_decl_file (dwarf5b.c)
+	.byte	0x1	# DW_AT_decl_line
+	.byte	0xd	# DW_AT_decl_column
+			# DW_AT_prototyped
+			# DW_AT_declaration
+	.long	0x53	# DW_AT_sibling
+	.uleb128 0x5	# (DIE (0x4d) DW_TAG_formal_parameter)
+	.long	0x3a	# DW_AT_type
+	.byte	0	# end of children of DIE 0x41
+	.uleb128 0x6	# (DIE (0x53) DW_TAG_subprogram)
+			# DW_AT_external
+	.ascii "bar\0"	# DW_AT_name
+	.byte	0x1	# DW_AT_decl_file (dwarf5b.c)
+	.byte	0x6	# DW_AT_decl_line
+	.byte	0x1	# DW_AT_decl_column
+			# DW_AT_prototyped
+	.quad	.LFB0	# DW_AT_low_pc
+	.quad	.LFE0-.LFB0	# DW_AT_high_pc
+	.uleb128 0x1	# DW_AT_frame_base
+	.byte	0x9c	# DW_OP_call_frame_cfa
+			# DW_AT_call_all_calls
+	.uleb128 0x7	# (DIE (0x6d) DW_TAG_variable)
+	.long	.LASF3	# DW_AT_name: "local"
+	.byte	0x1	# DW_AT_decl_file (dwarf5b.c)
+	.byte	0x8	# DW_AT_decl_line
+	.byte	0x7	# DW_AT_decl_column
+	.long	0x3a	# DW_AT_type
+	.long	.LLST0	# DW_AT_location
+	.long	.LVUS0	# DW_AT_GNU_locviews
+	.uleb128 0x8	# (DIE (0x81) DW_TAG_call_site)
+	.quad	.LVL1	# DW_AT_call_return_pc
+	.long	0x41	# DW_AT_call_origin
+	.uleb128 0x9	# (DIE (0x8e) DW_TAG_call_site)
+	.quad	.LVL2	# DW_AT_call_return_pc
+			# DW_AT_call_tail_call
+	.long	0x41	# DW_AT_call_origin
+	.uleb128 0xa	# (DIE (0x9b) DW_TAG_call_site_parameter)
+	.uleb128 0x1	# DW_AT_location
+	.byte	0x55	# DW_OP_reg5
+	.uleb128 0x2	# DW_AT_call_value
+	.byte	0x8	# DW_OP_const1u
+	.byte	0x7b
+	.byte	0	# end of children of DIE 0x8e
+	.byte	0	# end of children of DIE 0x53
+	.byte	0	# end of children of DIE 0xc
+	.section	.debug_abbrev,"",@progbits
+.Ldebug_abbrev0:
+	.uleb128 0x1	# (abbrev code)
+	.uleb128 0x11	# (TAG: DW_TAG_compile_unit)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x25	# (DW_AT_producer)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x13	# (DW_AT_language)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x1f	# (DW_FORM_line_strp)
+	.uleb128 0x1b	# (DW_AT_comp_dir)
+	.uleb128 0x1f	# (DW_FORM_line_strp)
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x12	# (DW_AT_high_pc)
+	.uleb128 0x7	# (DW_FORM_data8)
+	.uleb128 0x10	# (DW_AT_stmt_list)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.byte	0
+	.byte	0
+	.uleb128 0x2	# (abbrev code)
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
+	.byte	0	# DW_children_no
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3c	# (DW_AT_declaration)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.byte	0
+	.byte	0
+	.uleb128 0x3	# (abbrev code)
+	.uleb128 0x24	# (TAG: DW_TAG_base_type)
+	.byte	0	# DW_children_no
+	.uleb128 0xb	# (DW_AT_byte_size)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3e	# (DW_AT_encoding)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.byte	0
+	.byte	0
+	.uleb128 0x4	# (abbrev code)
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x27	# (DW_AT_prototyped)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3c	# (DW_AT_declaration)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x1	# (DW_AT_sibling)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x5	# (abbrev code)
+	.uleb128 0x5	# (TAG: DW_TAG_formal_parameter)
+	.byte	0	# DW_children_no
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x6	# (abbrev code)
+	.uleb128 0x2e	# (TAG: DW_TAG_subprogram)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x3f	# (DW_AT_external)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0x8	# (DW_FORM_string)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x27	# (DW_AT_prototyped)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x11	# (DW_AT_low_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x12	# (DW_AT_high_pc)
+	.uleb128 0x7	# (DW_FORM_data8)
+	.uleb128 0x40	# (DW_AT_frame_base)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.uleb128 0x7a	# (DW_AT_call_all_calls)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.byte	0
+	.byte	0
+	.uleb128 0x7	# (abbrev code)
+	.uleb128 0x34	# (TAG: DW_TAG_variable)
+	.byte	0	# DW_children_no
+	.uleb128 0x3	# (DW_AT_name)
+	.uleb128 0xe	# (DW_FORM_strp)
+	.uleb128 0x3a	# (DW_AT_decl_file)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x3b	# (DW_AT_decl_line)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x39	# (DW_AT_decl_column)
+	.uleb128 0xb	# (DW_FORM_data1)
+	.uleb128 0x49	# (DW_AT_type)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.uleb128 0x2	# (DW_AT_location)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.uleb128 0x2137	# (DW_AT_GNU_locviews)
+	.uleb128 0x17	# (DW_FORM_sec_offset)
+	.byte	0
+	.byte	0
+	.uleb128 0x8	# (abbrev code)
+	.uleb128 0x48	# (TAG: DW_TAG_call_site)
+	.byte	0	# DW_children_no
+	.uleb128 0x7d	# (DW_AT_call_return_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x7f	# (DW_AT_call_origin)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0x9	# (abbrev code)
+	.uleb128 0x48	# (TAG: DW_TAG_call_site)
+	.byte	0x1	# DW_children_yes
+	.uleb128 0x7d	# (DW_AT_call_return_pc)
+	.uleb128 0x1	# (DW_FORM_addr)
+	.uleb128 0x82	# (DW_AT_call_tail_call)
+	.uleb128 0x19	# (DW_FORM_flag_present)
+	.uleb128 0x7f	# (DW_AT_call_origin)
+	.uleb128 0x13	# (DW_FORM_ref4)
+	.byte	0
+	.byte	0
+	.uleb128 0xa	# (abbrev code)
+	.uleb128 0x49	# (TAG: DW_TAG_call_site_parameter)
+	.byte	0	# DW_children_no
+	.uleb128 0x2	# (DW_AT_location)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.uleb128 0x7e	# (DW_AT_call_value)
+	.uleb128 0x18	# (DW_FORM_exprloc)
+	.byte	0
+	.byte	0
+	.byte	0
+	.section	.debug_loclists,"",@progbits
+	.long	.Ldebug_loc3-.Ldebug_loc2	# Length of Location Lists
+.Ldebug_loc2:
+	.value	0x5	# DWARF version number
+	.byte	0x8	# Address Size
+	.byte	0	# Segment Size
+	.long	0	# Offset Entry Count
+.Ldebug_loc0:
+.LVUS0:
+	.uleb128 .LVU6	# View list begin (*.LVUS0)
+	.uleb128 0	# View list end (*.LVUS0)
+.LLST0:
+	.byte	0x4	# DW_LLE_offset_pair (*.LLST0)
+	.uleb128 .LVL1-.Ltext0	# Location list begin address (*.LLST0)
+	.uleb128 .LFE0-.Ltext0	# Location list end address (*.LLST0)
+	.uleb128 0x3	# Location expression size
+	.byte	0x8	# DW_OP_const1u
+	.byte	0x7b
+	.byte	0x9f	# DW_OP_stack_value
+	.byte	0	# DW_LLE_end_of_list (*.LLST0)
+.Ldebug_loc3:
+	.section	.debug_aranges,"",@progbits
+	.long	0x2c	# Length of Address Ranges Info
+	.value	0x2	# DWARF aranges version
+	.long	.Ldebug_info0	# Offset of Compilation Unit Info
+	.byte	0x8	# Size of Address
+	.byte	0	# Size of Segment Descriptor
+	.value	0	# Pad to 16 byte boundary
+	.value	0
+	.quad	.Ltext0	# Address
+	.quad	.Letext0-.Ltext0	# Length
+	.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 52c4d5e0e6b..3bb88ff1c49 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"


More information about the Binutils-cvs mailing list