public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch] readelf -c dump archive index like nm -s
@ 2007-08-28  9:57 Shen Feng
  2007-08-31 14:33 ` Nick Clifton
  0 siblings, 1 reply; 6+ messages in thread
From: Shen Feng @ 2007-08-28  9:57 UTC (permalink / raw)
  To: binutils

Hi,

I made a patch which makes readelf -c dump archive index like nm -s.
The following is the changelog and the patch.

Changelog

binutils/
	* readelf.c (do_archive_index): New.
	(options): Add -c and --archive-index option.
	(usage): Add c option.
	(parse_args): Add c option parsing.
	(process_archive_index): New.
	(process_archive): Call process_archive_index.

Patch

--- readelf.old.c	2007-08-28 12:49:32.000000000 +0800
+++ readelf.c	2007-08-28 12:54:09.000000000 +0800
@@ -201,6 +201,7 @@ static int do_histogram;
 static int do_debugging;
 static int do_arch;
 static int do_notes;
+static int do_archive_index;
 static int is_32bit_elf;

 struct group_list
@@ -2727,6 +2728,7 @@ get_section_type_name (unsigned int sh_t
 static struct option options[] =
 {
   {"all",	       no_argument, 0, 'a'},
+  {"archive-index",   no_argument, 0, 'c'},
   {"file-header",      no_argument, 0, 'h'},
   {"program-headers",  no_argument, 0, 'l'},
   {"headers",	       no_argument, 0, 'e'},
@@ -2765,6 +2767,7 @@ usage (FILE *stream)
   fprintf (stream, _(" Display information about the contents of ELF format files\n"));
   fprintf (stream, _(" Options are:\n\
   -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n\
+  -c --archive-index     Display the archive file index\n\
   -h --file-header       Display the ELF file header\n\
   -l --program-headers   Display the program headers\n\
      --segments          An alias for --program-headers\n\
@@ -2868,7 +2871,7 @@ parse_args (int argc, char **argv)
     usage (stderr);

   while ((c = getopt_long
-	  (argc, argv, "ersuahnldSDAINtgw::x:i:vVWH", options, NULL)) != EOF)
+	  (argc, argv, "ersuachnldSDAINtgw::x:i:vVWH", options, NULL)) != EOF)
     {
       char *cp;
       int section;
@@ -2895,6 +2898,10 @@ parse_args (int argc, char **argv)
 	  do_histogram++;
 	  do_arch++;
 	  do_notes++;
+	  do_archive_index++;
+	  break;
+	case 'c':
+	  do_archive_index++;
 	  break;
 	case 'g':
 	  do_section_groups++;
@@ -3127,7 +3134,7 @@ parse_args (int argc, char **argv)
   if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
       && !do_segments && !do_header && !do_dump && !do_version
       && !do_histogram && !do_debugging && !do_arch && !do_notes
-      && !do_section_groups)
+      && !do_section_groups && !do_archive_index)
     usage (stderr);
   else if (argc < 3)
     {
@@ -9673,6 +9680,140 @@ process_object (char *file_name, FILE *f
   return 0;
 }

+static int
+process_archive_index (char *file_name, FILE *file, char *long_names,
+		       unsigned long longnames_size)
+{
+  struct ar_hdr arhdr;
+  unsigned long size;
+  size_t got;
+  unsigned int index_num;
+  unsigned int *index_array;
+  unsigned int i, j, k, l;
+  char elf_name[16];
+  char *sym_table;
+
+  /*move to the archive index header*/
+  if (fseek (file, SARMAG, SEEK_SET) != 0)
+    {
+      error (_("%s: failed to seek to archive header\n"), file_name);
+      return 1;
+    }
+
+  got = fread (&arhdr, 1, sizeof arhdr, file);
+  if (got != sizeof arhdr)
+    {
+      if (got == 0)
+	return 0;
+
+      error (_("%s: failed to read archive header\n"), file_name);
+      return 1;
+    }
+
+  if (memcmp (arhdr.ar_name, "/               ", 16) == 0)
+    {
+      /* We have the archive index table. */
+      size = strtoul (arhdr.ar_size, NULL, 10);
+      printf (_("Archive index:\n"));
+      size = size + (size & 1);
+      got = fread(&index_num, 1, sizeof (index_num), file);
+      if (got != sizeof (index_num))
+	{
+	  error (_("%s: failed to read archive index\n"), file_name);
+	  return 1;
+	}
+      index_num = byte_get_big_endian ((unsigned char*)&index_num,
+				       sizeof(index_num));
+      size -= sizeof(index_num);
+      index_array = (unsigned int*)malloc (index_num*sizeof(unsigned int));
+      if (index_array == NULL)
+	{
+	  error (_("Out of memory\n"));
+	  return 1;
+	}
+      got = fread (index_array, sizeof(unsigned int), index_num, file);
+      if (got != index_num)
+	{
+	  error (_("%s: failed to read archive index\n"), file_name);
+	  free (index_array);
+	  return 1;
+	}
+
+      size -= sizeof(unsigned int) * index_num;
+      sym_table = (char*)malloc (size);
+      if (sym_table == NULL)
+	{
+	  error (_("Out of memory\n"));
+	  free (index_array);
+	  return 1;
+	}
+      got = fread (sym_table, 1, size, file);
+      if (got != size)
+	{
+	  error (_("%s: failed to read archive index symbol table\n"), file_name);
+	  free (index_array);
+	  free (sym_table);
+	  return 1;
+	}
+
+      i = l = 0;
+      while(i < index_num)
+	{
+	  printf ("%s in ", sym_table+l);
+	  while ((l < size) && (sym_table[l] != '\0'))
+	    l++;
+	  l++;
+	
+	  index_array[i] = byte_get_big_endian ((unsigned char*)(index_array+i),
+						sizeof(unsigned int));
+	  if (fseek (file, index_array[i], SEEK_SET) != 0)
+	    {
+	      error (_("%s: failed to seek to next file name\n"), file_name);
+	      free (index_array);
+	      free (sym_table);
+	      return 1;
+	    }
+	  got = fread(elf_name, 1, 16, file);
+	  if ( got != 16)
+	    {
+	      error (_("%s: failed to read file name\n"), file_name);
+	      free (index_array);
+	      free (sym_table);
+	      return 1;
+	    }
+
+	  if (elf_name[0] == '/')
+	    {
+	      /*long name*/
+	      k = j = strtoul(elf_name+1, NULL, 10);
+	      while ((j<longnames_size) && (long_names[j] != '/'))
+		j++;
+	      long_names[j] = '\0';
+	      printf("%s\n", long_names+k);
+	      long_names[j] = '/';
+	    }
+	  else
+	    {
+	      j = 0;
+	      while ((elf_name[j] != '/') && (j < 16))
+		j++;
+	      elf_name[j] = '\0';
+	      printf("%s\n", elf_name);
+	
+	    }
+	  i++;
+	}
+      free (index_array);
+      free (sym_table);
+    }
+  else
+    {
+      printf(_("%s has no archive index\n"), file_name);
+    }
+
+    return 0;
+}
+
 /* Process an ELF archive.  The file is positioned just after the
    ARMAG string.  */

@@ -9681,7 +9822,7 @@ process_archive (char *file_name, FILE *
 {
   struct ar_hdr arhdr;
   size_t got;
-  unsigned long size;
+  unsigned long size, current_pos;
   char *longnames = NULL;
   unsigned long longnames_size = 0;
   size_t file_name_size;
@@ -9703,7 +9844,7 @@ process_archive (char *file_name, FILE *
       || const_strneq (arhdr.ar_name, "/SYM64/         "))
     {
       /* This is the archive symbol table.  Skip it.
-	 FIXME: We should have an option to dump it.  */
+	 We will dump in after long names is read.  */
       size = strtoul (arhdr.ar_size, NULL, 10);
       if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
 	{
@@ -9758,6 +9899,31 @@ process_archive (char *file_name, FILE *
 	  return 1;
 	}
     }
+
+  if (do_archive_index)
+    {
+      if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
+	  && !do_segments && !do_header && !do_dump && !do_version
+	  && !do_histogram && !do_debugging && !do_arch && !do_notes
+	  && !do_section_groups)
+	{
+	  /* archive index only*/
+	  return process_archive_index (file_name, file, longnames,
+					longnames_size);
+	}
+      else
+	{
+	  current_pos = ftell (file);
+	  if (process_archive_index (file_name, file, longnames,
+				     longnames_size) != 0)
+	    return 1;
+	  if( fseek (file, current_pos, SEEK_SET) != 0)
+	    {
+	      error (_("%s: failed to seek back\n"), file_name);
+	      return 1;
+	    }
+	}
+    }

   file_name_size = strlen (file_name);
   ret = 0;

-- 
Best Regards,


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch] readelf -c dump archive index like nm -s
  2007-08-28  9:57 [Patch] readelf -c dump archive index like nm -s Shen Feng
@ 2007-08-31 14:33 ` Nick Clifton
  2007-09-03  5:07   ` Shen Feng
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Clifton @ 2007-08-31 14:33 UTC (permalink / raw)
  To: Shen Feng; +Cc: binutils

Hi Shen,

> I made a patch which makes readelf -c dump archive index like nm -s.

Thanks very much for submitting this patch.  Do you have a binutils copyright 
assignment on file with the FSF ?  (I looked but did not find one).  Without 
one we unfortunately cannot accept the patch.

One question in particular comes to mind - why do you want this feature in 
readelf ?  Since it can already be done by "nm -s", as you have pointed out, 
what purpose is served by adding this ability to readelf ?

I do have a few comments on the patch as well:

   * When adding a new feature like this you should make sure that
     it is documented (in binutils/doc/binutils.texi in this case)
     and announced (in binutils/NEWS).

   * Comments should be formatted according to the GNU Coding Standard:
http://www.gnu.org/prep/standards/html_node/Comments.html#Comments
     In particular they should start with a capital letter and end
     with a period followed by two spaces.

     In addition the use of white space, especially around function
     calls, ought to be checked.

   * If the file being examined is not an archive then no error or
     warning message is produced.  It would be better to produce an
     informative message along the lines of "file foo is not an archive
     so its index cannot be displayed".

   * You go to a lot of trouble using fseek and ftell to remember the
     current file pointer location inside process_archive.  It would
     be much cleaner if you simply passed a pointer to the header that
     has already been read at the start of process_archive to
     process_archive_index and skipped all of this seeking about.

   * The format of the output is not particularly pretty.  I agree
     that it is the same format as provided by nm, but I am not sure
     that is such a good idea.  Maybe if the output was alpha sorted
     (on object file and then symbol name) and indented to some degree
     then it would be more useful.  eg:

      Index of archive foo.a:
        Binary bar.o contains:
          a_sym
          b_sym
          d_sym
        Binary baz.o contains:
          c_sym
          e_sym

Cheers
   Nick

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch] readelf -c dump archive index like nm -s
  2007-08-31 14:33 ` Nick Clifton
@ 2007-09-03  5:07   ` Shen Feng
  2007-09-03 10:32     ` Nick Clifton
  0 siblings, 1 reply; 6+ messages in thread
From: Shen Feng @ 2007-09-03  5:07 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

Hi Nick,

> 
> Thanks very much for submitting this patch.  Do you have a binutils 
> copyright assignment on file with the FSF ?  (I looked but did not find 
> one).  Without one we unfortunately cannot accept the patch.

I sent the information to fsf-records@gnu.org. Is that right?

> 
> One question in particular comes to mind - why do you want this feature 
> in readelf ?  Since it can already be done by "nm -s", as you have 
> pointed out, what purpose is served by adding this ability to readelf ?

nm uses BFD library but readelf doesn't.
I also found a FIXME about this when I read the readelf source code.

Thank you for your comments and I will fix it.
But I have one question.

> 
>   * The format of the output is not particularly pretty.  I agree
>     that it is the same format as provided by nm, but I am not sure
>     that is such a good idea.  Maybe if the output was alpha sorted
>     (on object file and then symbol name) and indented to some degree
>     then it would be more useful.  eg:
> 
>      Index of archive foo.a:
>        Binary bar.o contains:
>          a_sym
>          b_sym
>          d_sym
>        Binary baz.o contains:
>          c_sym
>          e_sym
> 

Now readelf rarely sorts any symbols. Does the archive index need to be sorted?
Maybe a text processing command such as sort can do it. So the format maybe
the same as you suggested, but without alpha sorted on object file and symbol
name. Do you think so?

Best Regards,
Shen Feng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch] readelf -c dump archive index like nm -s
  2007-09-03  5:07   ` Shen Feng
@ 2007-09-03 10:32     ` Nick Clifton
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2007-09-03 10:32 UTC (permalink / raw)
  To: Shen Feng; +Cc: binutils

Hi Shen Feng,

> I sent the information to fsf-records@gnu.org. Is that right?

Yes, thank you for doing this.


>>   * The format of the output is not particularly pretty.

> Now readelf rarely sorts any symbols. Does the archive index need to be 
> sorted?

No, it was just a suggestion.

> Maybe a text processing command such as sort can do it. So the format maybe
> the same as you suggested, but without alpha sorted on object file and 
> symbol name. Do you think so?

Certainly.  I just felt that the original format for the output was untidy 
(even though it mimicked the format used by nm) and that by rearranging it 
slightly you could improve over nm.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch] readelf -c dump archive index like nm -s
  2007-09-12 12:46 Shen Feng
@ 2007-09-17 16:31 ` Nick Clifton
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2007-09-17 16:31 UTC (permalink / raw)
  To: Shen Feng; +Cc: binutils

Hi Shen,

> The new patch is attached.

Thank you very much for submitting this revised patch.  I have applied it, 
together with a few tweaks of my own.  Basically all I did was to add some more 
error checking, so the running "readelf -c" on a corrupt archive should not 
cause readelf to crash.  I also changed some of the uses of sizeof in order to 
remove the assumption that "sizeof (unsigned int) == 4".  On some targets this 
is not true.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch] readelf -c dump archive index like nm -s
@ 2007-09-12 12:46 Shen Feng
  2007-09-17 16:31 ` Nick Clifton
  0 siblings, 1 reply; 6+ messages in thread
From: Shen Feng @ 2007-09-12 12:46 UTC (permalink / raw)
  To: binutils, nickc

[-- Attachment #1: Type: text/plain, Size: 293 bytes --]

Hi Nick,

The new patch is attached.

The Changelog is followed.

Changelog
binutils/
* readelf.c (do_archive_index): New.
(options): Add -c and --archive-index option.
(usage): Add c option.
(parse_args): Add c option parsing.
(process_archive): Dump archive index.

Best Regards,
Shen Feng


[-- Attachment #2: NEWS.diff --]
[-- Type: text/plain, Size: 435 bytes --]

Index: NEWS
===================================================================
RCS file: /cvs/src/src/binutils/NEWS,v
retrieving revision 1.65
diff -u -r1.65 NEWS
--- NEWS	30 Aug 2007 13:47:35 -0000	1.65
+++ NEWS	12 Sep 2007 10:04:03 -0000
@@ -1,4 +1,6 @@
 -*- text -*-
+* Added -c switch to readelf to allow string dumps of archive symbol index.
+
 * Added -p switch to readelf to allow string dumps of sections.
 
 Changes in 2.18:

[-- Attachment #3: readelf.diff --]
[-- Type: text/plain, Size: 8251 bytes --]

Index: readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.376
diff -u -p -r1.376 readelf.c
--- readelf.c	30 Aug 2007 13:47:35 -0000	1.376
+++ readelf.c	12 Sep 2007 09:56:03 -0000
@@ -202,6 +202,7 @@ static int do_histogram;
 static int do_debugging;
 static int do_arch;
 static int do_notes;
+static int do_archive_index;
 static int is_32bit_elf;
 
 struct group_list
@@ -2732,6 +2733,7 @@ get_section_type_name (unsigned int sh_t
 static struct option options[] =
 {
   {"all",	       no_argument, 0, 'a'},
+  {"archive-index",   no_argument, 0, 'c'},
   {"file-header",      no_argument, 0, 'h'},
   {"program-headers",  no_argument, 0, 'l'},
   {"headers",	       no_argument, 0, 'e'},
@@ -2771,6 +2773,7 @@ usage (FILE *stream)
   fprintf (stream, _(" Display information about the contents of ELF format files\n"));
   fprintf (stream, _(" Options are:\n\
   -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I\n\
+  -c --archive-index     Display the archive file index\n\
   -h --file-header       Display the ELF file header\n\
   -l --program-headers   Display the program headers\n\
      --segments          An alias for --program-headers\n\
@@ -2877,7 +2880,7 @@ parse_args (int argc, char **argv)
     usage (stderr);
 
   while ((c = getopt_long
-	  (argc, argv, "ersuahnldSDAINtgw::x:i:vVWHp:", options, NULL)) != EOF)
+	  (argc, argv, "ersuachnldSDAINtgw::x:i:vVWHp:", options, NULL)) != EOF)
     {
       char *cp;
       int section;
@@ -2905,6 +2908,9 @@ parse_args (int argc, char **argv)
 	  do_arch++;
 	  do_notes++;
 	  break;
+	case 'c':
+	  do_archive_index++;
+	  break;
 	case 'g':
 	  do_section_groups++;
 	  break;
@@ -3139,7 +3145,7 @@ parse_args (int argc, char **argv)
   if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
       && !do_segments && !do_header && !do_dump && !do_version
       && !do_histogram && !do_debugging && !do_arch && !do_notes
-      && !do_section_groups)
+      && !do_section_groups && !do_archive_index)
     usage (stderr);
   else if (argc < 3)
     {
@@ -9774,9 +9780,15 @@ process_archive (char *file_name, FILE *
 {
   struct ar_hdr arhdr;
   size_t got;
-  unsigned long size;
+  unsigned long size, current_pos;
+  unsigned int index_num;
+  unsigned int *index_array = NULL;
+  char *sym_table = NULL;
+  unsigned long sym_size =0;
   char *longnames = NULL;
   unsigned long longnames_size = 0;
+  char elf_name[16];
+  unsigned int i, j, k, l;
   size_t file_name_size;
   int ret;
 
@@ -9795,25 +9807,79 @@ process_archive (char *file_name, FILE *
   if (const_strneq (arhdr.ar_name, "/               ")
       || const_strneq (arhdr.ar_name, "/SYM64/         "))
     {
-      /* This is the archive symbol table.  Skip it.
-	 FIXME: We should have an option to dump it.  */
+      /* This is the archive symbol table.  */
       size = strtoul (arhdr.ar_size, NULL, 10);
-      if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
+      if (do_archive_index)
 	{
-	  error (_("%s: failed to skip archive symbol table\n"), file_name);
-	  return 1;
-	}
+	  /* Read the archive index table.  */
+	  size = size + (size & 1);
+	  got = fread(&index_num, 1, sizeof (index_num), file);
+	  if (got != sizeof (index_num))
+	    {
+	      error (_("%s: failed to read archive index\n"), file_name);
+	      return 1;
+	    }
+	  index_num = byte_get_big_endian ((unsigned char*)&index_num,
+				       sizeof(index_num));
+	  size -= sizeof(index_num);
+	  index_array = (unsigned int*)malloc (index_num*sizeof(unsigned int));
+	  if (index_array == NULL)
+	    {
+	      error (_("Out of memory\n"));
+	      return 1;
+	    }
+	  got = fread (index_array, sizeof(unsigned int), index_num, file);
+	  if (got != index_num)
+	    {
+	      error (_("%s: failed to read archive index\n"), file_name);
+	      ret = 1;
+	      goto out;
+	    }
 
+	  size -= sizeof(unsigned int) * index_num;
+	  sym_table = (char*)malloc (size);
+	  sym_size = size;
+	  if (sym_table == NULL)
+	    {
+	      error (_("Out of memory\n"));
+	      ret = 1;
+	      goto out;
+	    }
+	  got = fread (sym_table, 1, size, file);
+	  if (got != size)
+	    {
+	      error (_("%s: failed to read archive index symbol table\n"), file_name);
+	      ret = 1;
+	      goto out;
+	    }	  
+  	}
+      else
+	{
+	  if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
+	    {
+	      error (_("%s: failed to skip archive symbol table\n"), file_name);
+	      return 1;
+	    }
+	}
       got = fread (&arhdr, 1, sizeof arhdr, file);
       if (got != sizeof arhdr)
 	{
 	  if (got == 0)
-	    return 0;
+	    {
+	      ret = 0;
+	      goto out;
+	    }
 
 	  error (_("%s: failed to read archive header\n"), file_name);
-	  return 1;
+	  ret = 1;
+	  goto out;
 	}
     }
+  else
+    {
+      if (do_archive_index)
+	printf(_("%s has no archive index\n"), file_name);
+    }
 
   if (const_strneq (arhdr.ar_name, "//              "))
     {
@@ -9831,9 +9897,9 @@ process_archive (char *file_name, FILE *
 
       if (fread (longnames, longnames_size, 1, file) != 1)
 	{
-	  free (longnames);
 	  error (_("%s: failed to read string table\n"), file_name);
-	  return 1;
+	  ret = 1;
+	  goto out;
 	}
 
       if ((longnames_size & 1) != 0)
@@ -9842,16 +9908,87 @@ process_archive (char *file_name, FILE *
       got = fread (&arhdr, 1, sizeof arhdr, file);
       if (got != sizeof arhdr)
 	{
-	  free (longnames);
-
 	  if (got == 0)
-	    return 0;
+	    {
+	      ret = 0;
+	      goto out;
+	    }
 
 	  error (_("%s: failed to read archive header\n"), file_name);
+	  ret = 1;
+	  goto out;
+	}
+    }
+
+  if (do_archive_index)
+    {
+      /* Print index symbol from each object file.  */
+      printf(_("Index of archive %s:\n"), file_name);
+      current_pos = ftell (file);
+      i = l = 0;
+      while(i < index_num)
+	{
+	  index_array[i] = byte_get_big_endian ((unsigned char*)(index_array+i),
+						sizeof(unsigned int));
+	  if ((i == 0) || ((i>0) && (index_array[i] != index_array[i-1])))
+	    {
+	      if (fseek (file, index_array[i], SEEK_SET) != 0)
+		{
+		  error (_("%s: failed to seek to next file name\n"), file_name);
+		  ret = 1;
+		  goto out;
+		}
+	      got = fread(elf_name, 1, 16, file);
+	      if ( got != 16)
+		{
+		  error (_("%s: failed to read file name\n"), file_name);
+		  ret = 1;
+		  goto out;
+		}
+	      
+	      if (elf_name[0] == '/')
+		{
+		  /*long name*/
+		  k = j = strtoul(elf_name+1, NULL, 10);
+		  while ((j<longnames_size) && (longnames[j] != '/'))
+		    j++;
+		  longnames[j] = '\0';
+		  printf(_("Binary %s contains:\n"), longnames+k);
+		  longnames[j] = '/';
+		}
+	      else
+		{
+		  j = 0;
+		  while ((elf_name[j] != '/') && (j < 16))
+		    j++;
+		  elf_name[j] = '\0';
+		  printf(_("Binary %s contains:\n"), elf_name);
+		}
+	    }
+	  printf ("\t%s\n", sym_table+l);
+	  while ((l < sym_size) && (sym_table[l] != '\0'))
+	    l++;
+	  l++;
+	  i++;
+	}
+      free (index_array);
+      index_array = NULL;
+      free (sym_table);
+      sym_table = NULL;
+      if (fseek (file, current_pos, SEEK_SET) != 0)
+	{
+	  error (_("%s: failed to seek back to object file\n"), file_name);
 	  return 1;
 	}
     }
 
+
+  if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
+      && !do_segments && !do_header && !do_dump && !do_version
+      && !do_histogram && !do_debugging && !do_arch && !do_notes
+      && !do_section_groups)
+    return 0; /* Archive index only.  */
+
   file_name_size = strlen (file_name);
   ret = 0;
 
@@ -9933,7 +10070,12 @@ process_archive (char *file_name, FILE *
 	}
     }
 
-  if (longnames != 0)
+ out:
+  if (index_array != NULL)
+    free (index_array);
+  if (sym_table != NULL)
+    free (sym_table);
+  if (longnames != NULL)
     free (longnames);
 
   return ret;
@@ -9981,6 +10123,11 @@ process_file (char *file_name)
     ret = process_archive (file_name, file);
   else
     {
+      if (do_archive_index)
+	{
+	  error(_("File %s is not an archive so its index cannot be displayed.\n"),
+		file_name);
+	}
       rewind (file);
       archive_file_size = archive_file_offset = 0;
       ret = process_object (file_name, file);

[-- Attachment #4: binutils.texi.diff --]
[-- Type: text/plain, Size: 983 bytes --]

Index: binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.114
diff -u -r1.114 binutils.texi
--- binutils.texi	30 Aug 2007 13:47:35 -0000	1.114
+++ binutils.texi	12 Sep 2007 10:01:38 -0000
@@ -3586,6 +3586,7 @@
 @smallexample
 @c man begin SYNOPSIS readelf
 readelf [@option{-a}|@option{--all}]
+        [@option{-c}|@option{--archive-index}]
         [@option{-h}|@option{--file-header}]
         [@option{-l}|@option{--program-headers}|@option{--segments}]
         [@option{-S}|@option{--section-headers}|@option{--sections}]
@@ -3641,6 +3642,12 @@
 @option{--relocs}, @option{--dynamic}, @option{--notes} and
 @option{--version-info}.
 
+@item -c
+@itemx --archive-index
+@cindex Archive file symbol index information
+Displays the archive file symbol index infomation contained in the 
+archive header.
+
 @item -h
 @itemx --file-header
 @cindex ELF file header information

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-09-17 16:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-28  9:57 [Patch] readelf -c dump archive index like nm -s Shen Feng
2007-08-31 14:33 ` Nick Clifton
2007-09-03  5:07   ` Shen Feng
2007-09-03 10:32     ` Nick Clifton
2007-09-12 12:46 Shen Feng
2007-09-17 16:31 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).