Fix an abort triggered when objcopy is used to set the "share" section flag on an...
[deliverable/binutils-gdb.git] / binutils / readelf.c
index 4dcac968ddf02dece5685ff69fefe94e90f30ee0..d4756c93b3454965accc7797593cde66936e0eae 100644 (file)
@@ -1629,7 +1629,8 @@ dump_relocations (Filedata *          filedata,
        {
          if (symtab == NULL || symtab_index >= nsyms)
            {
-             error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index);
+             error (_(" bad symbol index: %08lx in reloc\n"),
+                    (unsigned long) symtab_index);
              res = FALSE;
            }
          else
@@ -1733,7 +1734,8 @@ dump_relocations (Filedata *          filedata,
                printf (_("<string table index: %3ld>"), psym->st_name);
              else if (psym->st_name >= strtablen)
                {
-                 error (_("<corrupt string table index: %3ld>"), psym->st_name);
+                 error (_("<corrupt string table index: %3ld>\n"),
+                        psym->st_name);
                  res = FALSE;
                }
              else
@@ -3767,6 +3769,7 @@ get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
            case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break;
            case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break;
            case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break;
+           case EF_Z80_MACH_Z80N: strcat (buf, ", Z80N"); break;
            default:
              strcat (buf, _(", unknown")); break;
            }
@@ -7101,6 +7104,7 @@ dump_ia64_vms_dynamic_fixups (Filedata *                  filedata,
             (unsigned long) fixup->needed);
       lib_name = "???";
     }
+
   printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
          (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
   printf
@@ -7200,6 +7204,8 @@ process_ia64_vms_dynamic_relocs (Filedata * filedata)
           if (strtab == NULL)
             strtab = get_data (NULL, filedata, dynamic_addr + strtab_off,
                                1, strtab_sz, _("dynamic string section"));
+         if (strtab == NULL)
+           strtab_sz = 0;
           break;
 
         case DT_IA_64_VMS_NEEDED_IDENT:
@@ -8786,7 +8792,7 @@ decode_arm_unwind_bytecode (Filedata *                 filedata,
            }
          if (i == sizeof (buf))
            {
-             error (_("corrupt change to vsp"));
+             error (_("corrupt change to vsp\n"));
              res = FALSE;
            }
          else
@@ -9877,7 +9883,8 @@ process_dynamic_section (Filedata * filedata)
          if ((bfd_size_type) section.sh_offset > filedata->file_size)
            {
              /* See PR 21379 for a reproducer.  */
-             error (_("Invalid DT_SYMTAB entry: %lx"), (long) section.sh_offset);
+             error (_("Invalid DT_SYMTAB entry: %lx\n"),
+                    (long) section.sh_offset);
              return FALSE;
            }
 
@@ -11176,7 +11183,7 @@ get_symbol_visibility (unsigned int visibility)
     case STV_HIDDEN:   return "HIDDEN";
     case STV_PROTECTED: return "PROTECTED";
     default:
-      error (_("Unrecognized visibility value: %u"), visibility);
+      error (_("Unrecognized visibility value: %u\n"), visibility);
       return _("<unknown>");
     }
 }
@@ -11189,7 +11196,7 @@ get_alpha_symbol_other (unsigned int other)
     case STO_ALPHA_NOPV:       return "NOPV";
     case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD";
     default:
-      error (_("Unrecognized alpha specific other value: %u"), other);
+      error (_("Unrecognized alpha specific other value: %u\n"), other);
       return _("<unknown>");
     }
 }
@@ -13725,6 +13732,14 @@ dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
   end  = start + num_bytes;
   some_strings_shown = FALSE;
 
+#ifdef HAVE_MBSTATE_T
+  mbstate_t state;
+  /* Initialise the multibyte conversion state.  */
+  memset (& state, 0, sizeof (state));
+#endif
+
+  bfd_boolean continuing = FALSE;
+
   while (data < end)
     {
       while (!ISPRINT (* data))
@@ -13735,18 +13750,76 @@ dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
        {
          size_t maxlen = end - data;
 
+         if (continuing)
+           {
+             printf ("            ");
+             continuing = FALSE;
+           }
+         else
+           {
 #ifndef __MSVCRT__
-         /* PR 11128: Use two separate invocations in order to work
-             around bugs in the Solaris 8 implementation of printf.  */
-         printf ("  [%6tx]  ", data - start);
+             /* PR 11128: Use two separate invocations in order to work
+                around bugs in the Solaris 8 implementation of printf.  */
+             printf ("  [%6tx]  ", data - start);
 #else
-         printf ("  [%6Ix]  ", (size_t) (data - start));
+             printf ("  [%6Ix]  ", (size_t) (data - start));
 #endif
+           }
+
          if (maxlen > 0)
            {
-             print_symbol ((int) maxlen, (const char *) data);
-             putchar ('\n');
-             data += strnlen ((const char *) data, maxlen);
+             char c;
+
+             while (maxlen)
+               {
+                 c = *data++;
+
+                 if (c == 0)
+                   break;
+
+                 /* PR 25543: Treat new-lines as string-ending characters.  */
+                 if (c == '\n')
+                   {
+                     printf ("\\n\n");
+                     if (*data != 0)
+                       continuing = TRUE;
+                     break;
+                   }
+
+                 /* Do not print control characters directly as they can affect terminal
+                    settings.  Such characters usually appear in the names generated
+                    by the assembler for local labels.  */
+                 if (ISCNTRL (c))
+                   {
+                     printf ("^%c", c + 0x40);
+                   }
+                 else if (ISPRINT (c))
+                   {
+                     putchar (c);
+                   }
+                 else
+                   {
+                     size_t  n;
+#ifdef HAVE_MBSTATE_T
+                     wchar_t w;
+#endif
+                     /* Let printf do the hard work of displaying multibyte characters.  */
+                     printf ("%.1s", data - 1);
+#ifdef HAVE_MBSTATE_T
+                     /* Try to find out how many bytes made up the character that was
+                        just printed.  Advance the symbol pointer past the bytes that
+                        were displayed.  */
+                     n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state);
+#else
+                     n = 1;
+#endif
+                     if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
+                       data += (n - 1);
+                   }
+               }
+
+             if (c != '\n')
+               putchar ('\n');
            }
          else
            {
@@ -14122,7 +14195,7 @@ load_specific_debug_section (enum dwarf_section_display_enum  debug,
                      ? sizeof (Elf32_External_Chdr)
                      : sizeof (Elf64_External_Chdr)))
            {
-             warn (_("compressed section %s is too small to contain a compression header"),
+             warn (_("compressed section %s is too small to contain a compression header\n"),
                    section->name);
              return FALSE;
            }
@@ -14204,7 +14277,8 @@ get_build_id (void * data)
   Elf_Internal_Shdr * shdr;
   unsigned long i;
 
-  /* Iterate through notes to find note.gnu.build-id.  */
+  /* Iterate through notes to find note.gnu.build-id.
+     FIXME: Only the first note in any note section is examined.  */
   for (i = 0, shdr = filedata->section_headers;
        i < filedata->file_header.e_shnum && shdr != NULL;
        i++, shdr++)
@@ -14240,13 +14314,10 @@ get_build_id (void * data)
           min_notesz = offsetof (Elf_External_Note, name);
           if (data_remaining < min_notesz)
             {
-              warn (ngettext ("debuginfod: Corrupt note: only %ld byte remains, "
-                              "not enough for a full note\n",
-                              "Corrupt note: only %ld bytes remain, "
-                              "not enough for a full note\n",
-                              data_remaining),
-                    (long) data_remaining);
-              break;
+             warn (_("\
+malformed note encountered in section %s whilst scanning for build-id note\n"),
+                   printable_section_name (filedata, shdr));
+              continue;
             }
           data_remaining -= min_notesz;
 
@@ -14269,13 +14340,10 @@ get_build_id (void * data)
           min_notesz = offsetof (Elf64_External_VMS_Note, name);
           if (data_remaining < min_notesz)
             {
-              warn (ngettext ("debuginfod: Corrupt note: only %ld byte remains, "
-                              "not enough for a full note\n",
-                              "Corrupt note: only %ld bytes remain, "
-                              "not enough for a full note\n",
-                              data_remaining),
-                    (long) data_remaining);
-              break;
+             warn (_("\
+malformed note encountered in section %s whilst scanning for build-id note\n"),
+                   printable_section_name (filedata, shdr));
+              continue;
             }
           data_remaining -= min_notesz;
 
@@ -14296,9 +14364,9 @@ get_build_id (void * data)
           || ((size_t) (next - inote.descdata)
               > data_remaining - (size_t) (inote.descdata - inote.namedata)))
         {
-          warn (_("debuginfod: note with invalid namesz and/or descsz found\n"));
-          warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
-                inote.type, inote.namesz, inote.descsz, (int) align);
+         warn (_("\
+malformed note encountered in section %s whilst scanning for build-id note\n"),
+               printable_section_name (filedata, shdr));
           continue;
         }
 
@@ -14313,13 +14381,13 @@ get_build_id (void * data)
 
           build_id = malloc (inote.descsz * 2 + 1);
           if (build_id == NULL)
-              return NULL;
+           return NULL;
 
           for (j = 0; j < inote.descsz; ++j)
             sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff);
           build_id[inote.descsz * 2] = '\0';
 
-          return (unsigned char *)build_id;
+          return (unsigned char *) build_id;
         }
     }
 
@@ -18062,7 +18130,7 @@ print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
        printf ("%02x ", ptr[j] & 0xff);
       printf (">");
 
-next:
+    next:
       ptr += ((datasz + (size - 1)) & ~ (size - 1));
       if (ptr == ptr_end)
        break;
This page took 0.033598 seconds and 4 git commands to generate.