Handle implicit const in .debug_names

Message ID 20260522121618.1460707-1-tdevries@suse.de
State New
Headers
Series Handle implicit const in .debug_names |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_check--master-arm fail Patch failed to apply

Commit Message

Tom de Vries May 22, 2026, 12:16 p.m. UTC
  I tried to use readelf to read the debug info for gdb test-case
gdb.dwarf2/debug-names-tu-dwarf5.exp, and ran into some trouble reading the
.debug_names section:
...
$ readelf -w debug-names-tu-dwarf5
  ...
Symbol table:
[  1] #eddb6232 _start: <0><1> DW_TAG_subprogram DW_IDX_compile_unit=0
[  2] #53a2ae86 struct_with_int_member:readelf: Warning: Unrecognized form: 0
readelf: Error: end of data encountered whilst reading LEB
 <0x3><2> DW_TAG_structure_type DW_IDX_type_unit=0 DW_IDX_GNU_language=0 DW_IDX_type_unitreadelf: Warning: Unrecognized form: 0
readelf: Error: end of data encountered whilst reading LEB
...

The .debug_names abbreviation table contains a DW_FORM_implicit_const entry:
...
.uleb128        0x2003          /* DW_IDX_GNU_language */
.uleb128        0x21            /* DW_FORM_implicit_const */
.sleb128        0x0002          /* DW_FORM_implicit_const value: DW_LANG_C */
...
and readelf doesn't support this.

Add support for DW_FORM_implicit_const in display_debug_names, such that we
get the expected:
...
Symbol table:
[  1] #eddb6232 _start: <0><1> DW_TAG_subprogram DW_IDX_compile_unit=0
[  2] #53a2ae86 struct_with_int_member: <0x3><2> DW_TAG_structure_type \
      DW_IDX_type_unit=0 DW_IDX_GNU_language=2
...
---
 binutils/dwarf.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)


base-commit: 6dc6342541de90fbe8726c11c5a45f9475ffb815
  

Comments

Jan Beulich May 22, 2026, 1:03 p.m. UTC | #1
On 22.05.2026 14:16, Tom de Vries wrote:
> I tried to use readelf to read the debug info for gdb test-case
> gdb.dwarf2/debug-names-tu-dwarf5.exp, and ran into some trouble reading the
> .debug_names section:
> ...
> $ readelf -w debug-names-tu-dwarf5
>   ...
> Symbol table:
> [  1] #eddb6232 _start: <0><1> DW_TAG_subprogram DW_IDX_compile_unit=0
> [  2] #53a2ae86 struct_with_int_member:readelf: Warning: Unrecognized form: 0
> readelf: Error: end of data encountered whilst reading LEB
>  <0x3><2> DW_TAG_structure_type DW_IDX_type_unit=0 DW_IDX_GNU_language=0 DW_IDX_type_unitreadelf: Warning: Unrecognized form: 0
> readelf: Error: end of data encountered whilst reading LEB
> ...
> 
> The .debug_names abbreviation table contains a DW_FORM_implicit_const entry:
> ...
> .uleb128        0x2003          /* DW_IDX_GNU_language */
> .uleb128        0x21            /* DW_FORM_implicit_const */
> .sleb128        0x0002          /* DW_FORM_implicit_const value: DW_LANG_C */
> ...
> and readelf doesn't support this.
> 
> Add support for DW_FORM_implicit_const in display_debug_names, such that we
> get the expected:
> ...
> Symbol table:
> [  1] #eddb6232 _start: <0><1> DW_TAG_subprogram DW_IDX_compile_unit=0
> [  2] #53a2ae86 struct_with_int_member: <0x3><2> DW_TAG_structure_type \
>       DW_IDX_type_unit=0 DW_IDX_GNU_language=2
> ...
> ---
>  binutils/dwarf.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)

Okay.

Jan
  

Patch

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 42386154b49..4720dd717fa 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -12132,6 +12132,12 @@  display_debug_names (struct dwarf_section *section, void *file)
 	      READ_ULEB (form, abbrevptr, abbrev_table_end);
 	      if (xindex == 0 && form == 0)
 		break;
+
+	      if (form == DW_FORM_implicit_const)
+		{
+		  int64_t implicit_const;
+		  READ_SLEB (implicit_const, abbrevptr, abbrev_table_end);
+		}
 	    }
 	}
 
@@ -12222,7 +12228,12 @@  display_debug_names (struct dwarf_section *section, void *file)
 
 		  if (tagno >= 0)
 		    printf (" %s", get_IDX_name (xindex));
-		  entryptr = read_and_display_attr_value (0, form, 0,
+
+		  int64_t implicit_const = 0;
+		  if (form == DW_FORM_implicit_const)
+		    READ_SLEB (implicit_const, abbrevptr, abbrev_table_end);
+
+		  entryptr = read_and_display_attr_value (0, form, implicit_const,
 							  unit_start, entryptr,
 							  unit_end, 0,
 							  offset_size,