]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Make readelf -x/-a handle SHT_NOBITS gracefully as -p already does.
authorRoland McGrath <roland@redhat.com>
Mon, 16 Nov 2009 09:50:58 +0000 (01:50 -0800)
committerRoland McGrath <roland@redhat.com>
Mon, 16 Nov 2009 09:50:58 +0000 (01:50 -0800)
src/ChangeLog
src/readelf.c

index d59072a3a91be3e8f8f3c148a650aca14031ecc8..c0e277a96b911f762bd27314b2d2687ed212d42d 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-16  Roland McGrath  <roland@redhat.com>
+
+       * readelf.c (print_string_section): Punt SHT_NOBITS like empty
+       sections, just as dump_data_section already does.
+
 2009-09-21  Ulrich Drepper  <drepper@redhat.com>
 
        * elflint.c (special_sections): Allow MERGE and STRINGS flags to be
index 521fe262018c18353af444c14cb82bf03b75308c..345656793b7af9bfb2b9e679b2f7086a8a4f5741 100644 (file)
@@ -7429,36 +7429,38 @@ dump_data_section (Elf_Scn *scn, const GElf_Shdr *shdr, const char *name)
 static void
 print_string_section (Elf_Scn *scn, const GElf_Shdr *shdr, const char *name)
 {
-  if (shdr->sh_size == 0)
-    printf (gettext ("\nSection [%Zu] '%s' is empty.\n"),
+  if (shdr->sh_size == 0 || shdr->sh_type == SHT_NOBITS)
+    printf (gettext ("\nSection [%Zu] '%s' has no strings to dump.\n"),
            elf_ndxscn (scn), name);
-
-  Elf_Data *data = elf_rawdata (scn, NULL);
-  if (data == NULL)
-    error (0, 0, gettext ("cannot get data for section [%Zu] '%s': %s"),
-          elf_ndxscn (scn), name, elf_errmsg (-1));
   else
     {
-      printf (gettext ("\nString section [%Zu] '%s' contains %" PRIu64
-                      " bytes at offset %#0" PRIx64 ":\n"),
-             elf_ndxscn (scn), name,
-             shdr->sh_size, shdr->sh_offset);
-
-      const char *start = data->d_buf;
-      const char *const limit = start + data->d_size;
-      do
+      Elf_Data *data = elf_rawdata (scn, NULL);
+      if (data == NULL)
+       error (0, 0, gettext ("cannot get data for section [%Zu] '%s': %s"),
+              elf_ndxscn (scn), name, elf_errmsg (-1));
+      else
        {
-         const char *end = memchr (start, '\0', limit - start);
-         const size_t pos = start - (const char *) data->d_buf;
-         if (unlikely (end == NULL))
+         printf (gettext ("\nString section [%Zu] '%s' contains %" PRIu64
+                          " bytes at offset %#0" PRIx64 ":\n"),
+                 elf_ndxscn (scn), name,
+                 shdr->sh_size, shdr->sh_offset);
+
+         const char *start = data->d_buf;
+         const char *const limit = start + data->d_size;
+         do
            {
-             printf ("  [%6Zx]- %.*s\n",
-                     pos, (int) (limit - start), start);
-             break;
-           }
-         printf ("  [%6Zx]  %s\n", pos, start);
-         start = end + 1;
-       } while (start < limit);
+             const char *end = memchr (start, '\0', limit - start);
+             const size_t pos = start - (const char *) data->d_buf;
+             if (unlikely (end == NULL))
+               {
+                 printf ("  [%6Zx]- %.*s\n",
+                         pos, (int) (limit - start), start);
+                 break;
+               }
+             printf ("  [%6Zx]  %s\n", pos, start);
+             start = end + 1;
+           } while (start < limit);
+       }
     }
 }