[readelf] Handle unknown name of main in .gdb_index section

When compiling hello world and adding a v9 .gdb-index section:
...
$ gcc -g hello.c
$ gdb-add-index a.out
...
readelf shows it as:
...
Shortcut table:
Language of main: unknown: 0
Name of main: ^A
...

The documentation of gdb says about the "Name of main" that:
...
This value must be ignored if the value for the language of main is zero.
...

Implement this approach in display_gdb_index, such that we have instead:
...
Shortcut table:
Language of main: unknown: 0
Name of main: <unknown>
...

Tested on x86_64-linux.

Approved-By: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Tom de Vries 2023-10-24 12:35:08 +02:00
parent f87cf663af
commit 07a9e70911
2 changed files with 17 additions and 8 deletions

View File

@ -1,3 +1,7 @@
2023-10-24 Tom de Vries <tdevries@suse.de>
* dwarf.c (display_gdb_index): Handle unknown name of main.
2023-10-10 Tom de Vries <tdevries@suse.de>
* dwarf.c (display_lang): New function, factored out of ...

View File

@ -10949,8 +10949,12 @@ display_gdb_index (struct dwarf_section *section,
display_lang (lang);
printf ("\n");
uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4);
printf (_("Name of main: "));
if (lang == 0)
printf (_("<unknown>\n"));
else
{
uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4);
if (name_offset >= section->size - constant_pool_offset)
{
printf (_("<corrupt offset: %x>\n"), name_offset);
@ -10960,6 +10964,7 @@ display_gdb_index (struct dwarf_section *section,
else
printf ("%s\n", constant_pool + name_offset);
}
}
return 1;
}