From efa649694df3dcdb6adf98e15f1e12e116b10063 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Mon, 16 Nov 2009 01:50:58 -0800 Subject: [PATCH] Make readelf -x/-a handle SHT_NOBITS gracefully as -p already does. --- src/ChangeLog | 5 +++++ src/readelf.c | 52 ++++++++++++++++++++++++++------------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d59072a3a..c0e277a96 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2009-11-16 Roland McGrath + + * readelf.c (print_string_section): Punt SHT_NOBITS like empty + sections, just as dump_data_section already does. + 2009-09-21 Ulrich Drepper * elflint.c (special_sections): Allow MERGE and STRINGS flags to be diff --git a/src/readelf.c b/src/readelf.c index 521fe2620..345656793 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -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); + } } } -- 2.47.2