GAS: Do not create an entry for the default directory if the directory table is empty...
authorNick Clifton <nickc@redhat.com>
Mon, 4 May 2020 12:50:05 +0000 (13:50 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 4 May 2020 12:50:05 +0000 (13:50 +0100)
PR 25917
* dwarf.c (display_debug_lines_decoded): Warn if encountering a
supicious number of entries for DWARF-5 format directory and file
name tables.  Do not display file name table header if the table
is empty.  Do not allocate space for empty tables.

binutils/ChangeLog
binutils/dwarf.c
gas/ChangeLog
gas/dwarf2dbg.c

index 7b0d1a0477ed0c08a0f7fda0919ca413aa0f8a3d..7cc692b3e5b9dddc91415f89bf248b24df4124ab 100644 (file)
@@ -1,3 +1,11 @@
+2020-05-04  Nick Clifton  <nickc@redhat.com>
+
+       PR 25917
+       * dwarf.c (display_debug_lines_decoded): Warn if encountering a
+       supicious number of entries for DWARF-5 format directory and file
+       name tables.  Do not display file name table header if the table
+       is empty.  Do not allocate space for empty tables.
+
 2020-05-04  Alan Modra  <amodra@gmail.com>
 
        * readelf.c (process_nds32_specific): Check size of .nds32_e_flags
index eb053ce1f15676d73647bab8879c0e49524da72e..61373bf44a2c6411921b64fa6c95917053a0883b 100644 (file)
@@ -4343,6 +4343,8 @@ display_debug_lines_decoded (struct dwarf_section *  section,
 
              /* Skip directories format.  */
              SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
+             if (format_count > 1)
+               warn ("Unexpectedly large number of columns in the directory name table (%u)\n", format_count);
              format_start = data;
              for (formati = 0; formati < format_count; formati++)
                {
@@ -4357,8 +4359,11 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                  break;
                }
 
-             directory_table = (unsigned char **)
-               xmalloc (n_directories * sizeof (unsigned char *));
+             if (n_directories == 0)
+               directory_table = NULL;
+             else
+               directory_table = (unsigned char **)
+                 xmalloc (n_directories * sizeof (unsigned char *));
 
              for (entryi = 0; entryi < n_directories; entryi++)
                {
@@ -4411,6 +4416,9 @@ display_debug_lines_decoded (struct dwarf_section *  section,
 
              /* Skip files format.  */
              SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
+             if (format_count > 5)
+               warn ("Unexpectedly large number of columns in the file name table (%u)\n", format_count);
+             format_count = 2;
              format_start = data;
              for (formati = 0; formati < format_count; formati++)
                {
@@ -4419,14 +4427,17 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                }
 
              READ_ULEB (n_files, data, end);
-             if (data == end)
+             if (data == end && n_files > 0)
                {
                  warn (_("Corrupt file name list\n"));
                  break;
                }
 
-             file_table = (File_Entry *) xcalloc (1, n_files
-                                                     * sizeof (File_Entry));
+             if (n_files == 0)
+               file_table = NULL;
+             else
+               file_table = (File_Entry *) xcalloc (1, n_files
+                                                    * sizeof (File_Entry));
 
              for (entryi = 0; entryi < n_files; entryi++)
                {
@@ -4582,7 +4593,7 @@ display_debug_lines_decoded (struct dwarf_section *  section,
 
          /* Print the Compilation Unit's name and a header.  */
          if (file_table == NULL)
-           ;
+           printf (_("CU: No directory table\n"));
          else if (directory_table == NULL)
            printf (_("CU: %s:\n"), file_table[0].name);
          else
@@ -4610,7 +4621,10 @@ display_debug_lines_decoded (struct dwarf_section *  section,
                printf ("%s:\n", file_table[0].name);
            }
 
-         printf (_("File name                            Line number    Starting address    View    Stmt\n"));
+         if (n_files > 0)
+           printf (_("File name                            Line number    Starting address    View    Stmt\n"));
+         else
+           printf (_("CU: Empty file name table\n"));
          saved_linfo = linfo;
        }
 
index 20ae817834024e3af32df5a420e7706113f15361..8d664f5aa197a8ef50c70def427b009b05d673fa 100644 (file)
@@ -1,3 +1,5 @@
+2020-05-04  Nick Clifton  <nickc@redhat.com>
+
 2020-05-04  Andre Vieira  <andre.simoesdiasvieira@arm.com>
 
        PR gas/25863
@@ -10,6 +12,9 @@
        PR 25917
        * dwarf2dbg.c (out_dir_and_file_list): Check for the directory
        table's existence before looking at its entries.
+       Also do not emit a default directory entry if there are no
+       directories in use.
+
        * testsuite/gas/elf/pr25917.s: New test source file.
        * testsuite/gas/elf/pr25917.d: New test driver.
        * testsuite/gas/elf/elf.exp (run_elf_list_test): Run the new test.
index 213f382887714c573af157481f33f57438dffae9..071450e19a182d69fdf8b8f5434b6df8ce976b3d 100644 (file)
@@ -1981,7 +1981,6 @@ out_dir_and_file_list (void)
   bfd_boolean emit_filesize = TRUE;
 
   /* Output the Directory Table.  */
-
   if (DWARF2_LINE_VERSION >= 5)
     {
       out_byte (1);
@@ -1993,7 +1992,7 @@ out_dir_and_file_list (void)
     }
       
   /* Emit directory list.  */
-  if (DWARF2_LINE_VERSION >= 5)
+  if (DWARF2_LINE_VERSION >= 5 && dirs_in_use > 0)
     {
       if (dirs == NULL || dirs[0] == NULL)
        dir = remap_debug_filename (".");
@@ -2017,7 +2016,6 @@ out_dir_and_file_list (void)
     out_byte ('\0');
 
   /* Output the File Name Table.  */
-
   if (DWARF2_LINE_VERSION >= 5)
     {
       unsigned int columns = 4;
@@ -2045,7 +2043,6 @@ out_dir_and_file_list (void)
       
       /* The number of format entries to follow.  */
       out_byte (columns);
-
       /* The format of the file name.  */
       out_uleb128 (DW_LNCT_path);
       /* FIXME: it would be better to store these strings in
This page took 0.032512 seconds and 4 git commands to generate.