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

Message ID 20231024080132.1181-1-tdevries@suse.de
State New
Headers
Series [readelf] Handle unknown name of main in .gdb_index section |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 warning Patch is already merged

Commit Message

Tom de Vries Oct. 24, 2023, 8:01 a.m. UTC
  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.
---
 binutils/dwarf.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)


base-commit: 8bf3b48f72728208ad09989edfac9e010a62a703
  

Comments

Jan Beulich Oct. 24, 2023, 8:24 a.m. UTC | #1
On 24.10.2023 10:01, Tom de Vries wrote:
> 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.

Okay. Just to mention it, there's a small concern of testing having been
done on just one architecture. Plus of course a testcase to cover this
special case would have been nice.

Jan
  

Patch

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 584c737b9ec..544ba6dff50 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -10949,16 +10949,21 @@  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 (name_offset >= section->size - constant_pool_offset)
+      if (lang == 0)
+	printf (_("<unknown>\n"));
+      else
 	{
-	  printf (_("<corrupt offset: %x>\n"), name_offset);
-	  warn (_("Corrupt name offset of 0x%x found for name of main\n"),
-		name_offset);
+	  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);
+	      warn (_("Corrupt name offset of 0x%x found for name of main\n"),
+		    name_offset);
+	    }
+	  else
+	    printf ("%s\n", constant_pool + name_offset);
 	}
-      else
-	printf ("%s\n", constant_pool + name_offset);
     }
 
   return 1;