This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: Add -N to readelf to display section name
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Thu, 31 Mar 2005 13:06:39 -0800
- Subject: PATCH: Add -N to readelf to display section name
It is very annoying that readelf won't display full section names. This
patch adds -N to do that.
H.J.
----
2005-03-31 H.J. Lu <hongjiu.lu@intel.com>
* readelf.c (do_section_names): New.
(options): Add "section-names"/'N'.
(usage): Add -N/--section-name.
(parse_args): Handle 'N'.
(process_section_headers): Print out the full section name if
do_section_names isn't 0.
--- binutils/readelf.c.name 2005-03-31 11:14:58.767785224 -0800
+++ binutils/readelf.c 2005-03-31 13:01:29.275946072 -0800
@@ -145,6 +145,7 @@ int do_syms;
int do_reloc;
int do_sections;
int do_section_groups;
+int do_section_names;
int do_segments;
int do_unwind;
int do_using_dynamic;
@@ -2590,6 +2591,7 @@ struct option options[] =
{"sections", no_argument, 0, 'S'},
{"section-headers", no_argument, 0, 'S'},
{"section-groups", no_argument, 0, 'g'},
+ {"section-names", no_argument, 0, 'N'},
{"symbols", no_argument, 0, 's'},
{"syms", no_argument, 0, 's'},
{"relocs", no_argument, 0, 'r'},
@@ -2624,6 +2626,7 @@ usage (void)
-S --section-headers Display the sections' header\n\
--sections An alias for --section-headers\n\
-g --section-groups Display the section groups\n\
+ -N --section-names Display the section names\n\
-e --headers Equivalent to: -h -l -S\n\
-s --syms Display the symbol table\n\
--symbols An alias for --syms\n\
@@ -2696,7 +2699,7 @@ parse_args (int argc, char **argv)
usage ();
while ((c = getopt_long
- (argc, argv, "ersuahnldSDAIgw::x:i:vVWH", options, NULL)) != EOF)
+ (argc, argv, "ersuahnldSDAINgw::x:i:vVWH", options, NULL)) != EOF)
{
char *cp;
int section;
@@ -2727,6 +2730,9 @@ parse_args (int argc, char **argv)
case 'g':
do_section_groups++;
break;
+ case 'N':
+ do_section_names++;
+ break;
case 'e':
do_header++;
do_sections++;
@@ -3851,25 +3857,60 @@ process_section_headers (FILE *file)
printf (_("\nSection Header:\n"));
if (is_32bit_elf)
- printf
- (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
+ {
+ if (do_section_names)
+ {
+ printf (_(" [Nr] Name\n"));
+ printf (_(" Type Addr Off Size ES Flg Lk Inf Al\n"));
+ }
+ else
+ printf
+ (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
+ }
else if (do_wide)
- printf
- (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
+ {
+ if (do_section_names)
+ {
+ printf (_(" [Nr] Name\n"));
+ printf (_(" Type Address Off Size ES Flg Lk Inf Al\n"));
+ }
+ else
+ printf
+ (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
+ }
else
{
- printf (_(" [Nr] Name Type Address Offset\n"));
- printf (_(" Size EntSize Flags Link Info Align\n"));
+ if (do_section_names)
+ {
+ printf (_(" [Nr] Name\n"));
+ printf (_(" Flags Type Address Offset\n"));
+ printf (_(" Size EntSize Link Info Align\n"));
+ }
+ else
+ {
+ printf (_(" [Nr] Name Type Address Offset\n"));
+ printf (_(" Size EntSize Flags Link Info Align\n"));
+ }
}
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
i++, section++)
{
- printf (" [%2u] %-17.17s %-15.15s ",
- SECTION_HEADER_NUM (i),
- SECTION_NAME (section),
- get_section_type_name (section->sh_type));
+ if (do_section_names)
+ {
+ printf (" [%2u] %s\n",
+ SECTION_HEADER_NUM (i),
+ SECTION_NAME (section));
+ if (is_32bit_elf || do_wide)
+ printf (" %-15.15s ",
+ get_section_type_name (section->sh_type));
+ }
+ else
+ printf (" [%2u] %-17.17s %-15.15s ",
+ SECTION_HEADER_NUM (i),
+ SECTION_NAME (section),
+ get_section_type_name (section->sh_type));
if (is_32bit_elf)
{
@@ -3929,6 +3970,30 @@ process_section_headers (FILE *file)
putchar ('\n');
}
}
+ else if (do_section_names)
+ {
+ printf (" %-15.15s %-15.15s ",
+ get_elf_section_flags (section->sh_flags),
+ get_section_type_name (section->sh_type));
+ putchar (' ');
+ print_vma (section->sh_addr, LONG_HEX);
+ if ((long) section->sh_offset == section->sh_offset)
+ printf (" %8.8lx", (unsigned long) section->sh_offset);
+ else
+ {
+ printf (" ");
+ print_vma (section->sh_offset, LONG_HEX);
+ }
+ printf ("\n ");
+ print_vma (section->sh_size, LONG_HEX);
+ printf (" ");
+ print_vma (section->sh_entsize, LONG_HEX);
+
+ printf (" %2ld %3lu %ld\n",
+ (unsigned long) section->sh_link,
+ (unsigned long) section->sh_info,
+ (unsigned long) section->sh_addralign);
+ }
else
{
putchar (' ');