]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Restore readelf's warnings that describe real problems with the file being examined...
authorNick Clifton <nickc@redhat.com>
Tue, 5 May 2020 15:16:03 +0000 (16:16 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 5 May 2020 15:16:03 +0000 (16:16 +0100)
binutils* dwarf.c (do_checks): New global variable.
(display_formatted_table): Warn about an unexpected number of
columns in the table, if checks are enabled.  Do not complain
about the lack of data following the number of entries in the
table if the table is empty.
(display_debug_lines_decoded): Only warn about an unexpected
number of columns in a table if checks are enabled.
* dwarf.h (do_checks): Add a prototype.
* elfcomm.c (error): Remove weak attribute.
(warn): Likewise.
* readelf.c (do_checks): Delete.
(warn): Delete.
(process_section_headers): Only warn about empty sections if
checks are enabled.

gas * dwarf2dbg.c (out_dir_and_file_list): Add comments describing the
construction of a DWARF-5 directory name table.
* testsuite/gas/elf/pr25917.d: Update expected output.

binutils/ChangeLog
binutils/dwarf.c
binutils/dwarf.h
binutils/elfcomm.c
binutils/elfcomm.h
binutils/readelf.c
gas/ChangeLog
gas/dwarf2dbg.c
gas/testsuite/gas/elf/pr25917.d

index 8da40977e1e6a589558a9a346c8fe1ba6e39ff0e..7d00344eb0d3160cf2087bec5697cec5c405b7d9 100644 (file)
@@ -1,3 +1,20 @@
+2020-05-05  Nick Clifton  <nickc@redhat.com>
+
+       * dwarf.c (do_checks): New global variable.
+       (display_formatted_table): Warn about an unexpected number of
+       columns in the table, if checks are enabled.  Do not complain
+       about the lack of data following the number of entries in the
+       table if the table is empty.
+       (display_debug_lines_decoded): Only warn about an unexpected
+       number of columns in a table if checks are enabled.
+       * dwarf.h (do_checks): Add a prototype.
+       * elfcomm.c (error): Remove weak attribute.
+       (warn): Likewise.
+       * readelf.c (do_checks): Delete.
+       (warn): Delete.
+       (process_section_headers): Only warn about empty sections if
+       checks are enabled.
+
 2020-05-04  Fangrui Song   <maskray@google.com>
 
        * objcopy.c (copy_object): Allow empty section.
index 61373bf44a2c6411921b64fa6c95917053a0883b..7b5f7af8a1e2f0bd19a4a32f3fe954e45221c873 100644 (file)
@@ -98,6 +98,7 @@ int do_debug_cu_index;
 int do_wide;
 int do_debug_links;
 int do_follow_links;
+bfd_boolean do_checks;
 
 int dwarf_cutoff_level = -1;
 unsigned long dwarf_start_die;
@@ -3739,6 +3740,10 @@ display_formatted_table (unsigned char *                   data,
   const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table");
   
   SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
+  if (do_checks && format_count > 5)
+    warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
+         table_name, format_count);
+
   format_start = data;
   for (formati = 0; formati < format_count; formati++)
     {
@@ -3752,17 +3757,18 @@ display_formatted_table (unsigned char *                   data,
     }
 
   READ_ULEB (data_count, data, end);
-  if (data == end)
+  if (data_count == 0)
     {
-      warn (_("%s: Corrupt entry count\n"), table_name);
+      printf (_("\n The %s is empty.\n"), table_name);
       return data;
     }
-
-  if (data_count == 0)
+  else if (data == end)
     {
-      printf (_("\n The %s is empty.\n"), table_name);
+      warn (_("%s: Corrupt entry count - expected %s but none found\n"),
+           table_name, dwarf_vmatoa ("x", data_count));
       return data;
     }
+
   else if (format_count == 0)
     {
       warn (_("%s: format count is zero, but the table is not empty\n"),
@@ -4343,8 +4349,9 @@ 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);
+             if (do_checks && 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++)
                {
@@ -4416,9 +4423,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;
+             if (do_checks && format_count > 5)
+               warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
+                     format_count);
              format_start = data;
              for (formati = 0; formati < format_count; formati++)
                {
index 27f8a51521e3f66208f00a5d817e13ffad6be918..0c9f3661073991ddfafda9b593bd47a600377105 100644 (file)
@@ -221,6 +221,7 @@ extern int do_debug_cu_index;
 extern int do_wide;
 extern int do_debug_links;
 extern int do_follow_links;
+extern bfd_boolean do_checks;
 
 extern int dwarf_cutoff_level;
 extern unsigned long dwarf_start_die;
index fc47b40757f2db1b5f48224862b428bccddbc3eb..5ec4690e13234b6eeed7ac45e2d32672cb9a21d0 100644 (file)
 
 extern char *program_name;
 
-/* FIXME:  This definition really ought to be in ansidecl.h.  */
-#ifndef ATTRIBUTE_WEAK
-#define ATTRIBUTE_WEAK __attribute__((weak))
-#endif
-
-/* Allow the following two functions to be overridden if desired.  */
-void error (const char *, ...) ATTRIBUTE_WEAK;
-void warn (const char *, ...) ATTRIBUTE_WEAK;
-
 void
 error (const char *message, ...)
 {
index abc7611fe3fda882c84495b738c9c6bd4fcd1e39..abf84b5cb9e8d7edf6c40d5c2eafd6fa664a7136 100644 (file)
@@ -26,8 +26,8 @@
 
 #include "aout/ar.h"
 
-void error (const char *, ...) ATTRIBUTE_PRINTF_1;
-void warn (const char *, ...) ATTRIBUTE_PRINTF_1;
+extern void error (const char *, ...) ATTRIBUTE_PRINTF_1;
+extern void warn (const char *, ...) ATTRIBUTE_PRINTF_1;
 
 typedef unsigned HOST_WIDEST_INT elf_vma;
 
index 25c2cce21ae8ecbc84a3519d5e01d6310a664ffa..6bf6d5294ccfc746c9c0d66bfc058969b7f6571e 100644 (file)
@@ -231,7 +231,6 @@ static bfd_boolean do_ctf = FALSE;
 static bfd_boolean do_arch = FALSE;
 static bfd_boolean do_notes = FALSE;
 static bfd_boolean do_archive_index = FALSE;
-static bfd_boolean do_checks = FALSE;
 static bfd_boolean check_all = FALSE;
 static bfd_boolean is_32bit_elf = FALSE;
 static bfd_boolean decompress_dumps = FALSE;
@@ -387,25 +386,6 @@ bfd_vmatoa (char *fmtch, bfd_vma value)
   return ret;
 }
 
-/* A version of the warn() function that is disabled if do_checks is not active.  */
-
-void
-warn (const char *message, ...)
-{
-  va_list args;
-
-  if (!do_checks)
-    return;
-
-  /* Try to keep warning messages in sync with the program's normal output.  */
-  fflush (stdout);
-
-  va_start (args, message);
-  fprintf (stderr, _("%s: Warning: "), program_name);
-  vfprintf (stderr, message, args);
-  va_end (args);
-}
-
 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
    OFFSET + the offset of the current archive member, if we are examining an
    archive.  Put the retrieved data into VAR, if it is not NULL.  Otherwise
@@ -6378,21 +6358,22 @@ process_section_headers (Filedata * filedata)
 
        case SHT_REL:
          CHECK_ENTSIZE (section, i, Rel);
-         if (section->sh_size == 0)
+         if (do_checks && section->sh_size == 0)
            warn (_("Section '%s': zero-sized relocation section\n"), name);
          break;
 
        case SHT_RELA:
          CHECK_ENTSIZE (section, i, Rela);
-         if (section->sh_size == 0)
+         if (do_checks && section->sh_size == 0)
            warn (_("Section '%s': zero-sized relocation section\n"), name);
          break;
 
        case SHT_NOTE:
        case SHT_PROGBITS:
-         if (section->sh_size == 0)
-           /* This is not illegal according to the ELF standard, but
-              it might be an indication that something is wrong.  */
+         /* Having a zero sized section is not illegal according to the
+            ELF standard, but it might be an indication that something
+            is wrong.  So issue a warning if we are running in lint mode.  */
+         if (do_checks && section->sh_size == 0)
            warn (_("Section '%s': has a size of zero - is this intended ?\n"), name);
          break;
 
index 1a4f01ace39beb3ff2474cb4ddd0d045de3cf8cb..3ad9fb33d916ddaf619b7049f3a6eb5a643dc3d5 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-05  Nick Clifton  <nickc@redhat.com>
+
+       * dwarf2dbg.c (out_dir_and_file_list): Add comments describing the
+       construction of a DWARF-5 directory name table.
+       * testsuite/gas/elf/pr25917.d: Update expected output.
+
 2020-05-05  Gunther Nikl <gnikl@justmail.de>
 
        * config/tc-rx.c (elf_flags): Initialize for non-linux targets.
index 071450e19a182d69fdf8b8f5434b6df8ce976b3d..69955fea5bfb5cf0f21b0460cc8f0e154722eb3d 100644 (file)
@@ -1983,11 +1983,16 @@ out_dir_and_file_list (void)
   /* Output the Directory Table.  */
   if (DWARF2_LINE_VERSION >= 5)
     {
+      /* We only have one column in the directory table.  */
       out_byte (1);
+
+      /* Describe the purpose and format of the column.  */
       out_uleb128 (DW_LNCT_path);
       /* FIXME: it would be better to store these strings in
         the .debug_line_str section and reference them here.  */
       out_uleb128 (DW_FORM_string);
+
+      /* Now state how many rows there are in the table.  */
       out_uleb128 (dirs_in_use);
     }
       
index 6f83bbb5c5d5fa0a29a3a33a6831560a70b22a65..ce031e7186033f8ce8850079cd4dc87f225235c3 100644 (file)
@@ -1,9 +1,9 @@
 #as: --gdwarf-5
-#name: DWARF5: no files or directories
+#name: DWARF5: no files or directories (PR 25917)
 #readelf: -wl
 
 #...
  The Directory Table is empty.
 
No Line Number Statements.
The File Name Table is empty.
 #pass