[PATCH] nm size/value output fixes.

Elias Athanasopoulos eathan@otenet.gr
Wed May 22 05:41:00 GMT 2002


Hi,

This patch is not final, it is supposed to demostrate my thoughts
regarding some modifications to nm(1) in order to output the value
and the size of the symbols when the --size-sort is used.

Right now, nm outputs the size of the symbol in the value field, which
is not so elegant. You can test this patch using the sysv format to
see the new functionality:

 % ./nm-new --size-sort -fsysv  ~/foo.o
 
Name                  Value   Class        Type         Size   Line  Section

symbol_one          |00000000|   R  |                  |00000004|     |
symbol_two          |00000004|   R  |                  |00000008|     |
main                |00000028|   T  |                  |0000001c|     |
foo                 |00000000|   T  |                  |00000044|     |

Of course, there are more to be done. I would like to have a code review
from the maintainers, in order to proceed and change the other formats,
too, which, using my patch, are misfunctional.

Elias

-- 
http://gnewtellium.sourceforge.net			MP3 is not a crime.	
-------------- next part --------------
--- nm.c.orig	Thu May 16 18:18:33 2002
+++ nm.c	Wed May 22 15:42:38 2002
@@ -49,6 +49,13 @@
   asymbol **syms;
 };
 
+struct extended_symbol_info 
+{
+  symbol_info *sinfo;
+  bfd_vma ssize;
+  /* FIXME: we should add more fields for Type, Line, Section */
+};
+
 static void
 usage PARAMS ((FILE *, int));
 
@@ -84,7 +91,7 @@
 print_symname PARAMS ((const char *, const char *, bfd *));
 
 static void
-print_symbol PARAMS ((bfd *, asymbol *, bfd *));
+print_symbol PARAMS ((bfd *, asymbol *, bfd_vma ssize, bfd *));
 
 static void
 print_symdef_entry PARAMS ((bfd * abfd));
@@ -155,13 +162,13 @@
 print_value PARAMS ((bfd *, bfd_vma));
 
 static void
-print_symbol_info_bsd PARAMS ((symbol_info * info, bfd * abfd));
+print_symbol_info_bsd PARAMS ((struct extended_symbol_info * info, bfd * abfd));
 
 static void
-print_symbol_info_sysv PARAMS ((symbol_info * info, bfd * abfd));
+print_symbol_info_sysv PARAMS ((struct extended_symbol_info * info, bfd * abfd));
 
 static void
-print_symbol_info_posix PARAMS ((symbol_info * info, bfd * abfd));
+print_symbol_info_posix PARAMS ((struct extended_symbol_info * info, bfd * abfd));
 
 static void
 get_relocs PARAMS ((bfd *, asection *, PTR));
@@ -183,7 +190,7 @@
     void (*print_symbol_filename) PARAMS ((bfd * archive_bfd, bfd * abfd));
 
     /* Print a line of information about a symbol.  */
-    void (*print_symbol_info) PARAMS ((symbol_info * info, bfd * abfd));
+    void (*print_symbol_info) PARAMS ((struct extended_symbol_info * info, bfd * abfd));
   };
 static struct output_fns formats[] =
 {
@@ -1138,7 +1145,7 @@
       if (sym == NULL)
 	bfd_fatal (bfd_get_filename (abfd));
 
-      print_symbol (abfd, sym, archive_bfd);
+      print_symbol (abfd, sym, 0, archive_bfd);
     }
 }
 
@@ -1164,6 +1171,7 @@
   for (; from < fromend; from++)
     {
       asymbol *sym;
+      bfd_vma ssize;
 
       sym = bfd_minisymbol_to_symbol (abfd, dynamic, from->minisym, store);
       if (sym == NULL)
@@ -1171,18 +1179,19 @@
 
       /* Set the symbol value so that we actually display the symbol
          size.  */
-      sym->value = from->size - bfd_section_vma (abfd, bfd_get_section (sym));
+      ssize = from->size - bfd_section_vma (abfd, bfd_get_section (sym));
 
-      print_symbol (abfd, sym, archive_bfd);
+      print_symbol (abfd, sym, ssize, archive_bfd);
     }
 }
 
 /* Print a single symbol.  */
 
 static void
-print_symbol (abfd, sym, archive_bfd)
+print_symbol (abfd, sym, ssize, archive_bfd)
      bfd *abfd;
      asymbol *sym;
+     bfd_vma ssize;
      bfd *archive_bfd;
 {
   PROGRESS (1);
@@ -1197,9 +1206,12 @@
   else
     {
       symbol_info syminfo;
+      struct extended_symbol_info info;
 
       bfd_get_symbol_info (abfd, sym, &syminfo);
-      (*format->print_symbol_info) (&syminfo, abfd);
+      info.sinfo = &syminfo;
+      info.ssize = ssize;
+      (*format->print_symbol_info) (&info, abfd);
     }
 
   if (line_numbers)
@@ -1486,63 +1498,67 @@
 
 static void
 print_symbol_info_bsd (info, abfd)
-     symbol_info *info;
+     struct extended_symbol_info *info;
      bfd *abfd;
 {
-  if (bfd_is_undefined_symclass (info->type))
+  if (bfd_is_undefined_symclass (info->sinfo->type))
     {
       if (print_width == 16)
 	printf ("        ");
       printf ("        ");
     }
   else
-    print_value (abfd, info->value);
-  printf (" %c", info->type);
-  if (info->type == '-')
+    print_value (abfd, info->sinfo->value);
+  printf (" %c", info->sinfo->type);
+  if (info->sinfo->type == '-')
     {
       /* A stab.  */
       printf (" ");
-      printf (other_format, info->stab_other);
+      printf (other_format, info->sinfo->stab_other);
       printf (" ");
-      printf (desc_format, info->stab_desc);
-      printf (" %5s", info->stab_name);
+      printf (desc_format, info->sinfo->stab_desc);
+      printf (" %5s", info->sinfo->stab_name);
     }
-  print_symname (" %s", info->name, abfd);
+  print_symname (" %s", info->sinfo->name, abfd);
 }
 
 static void
 print_symbol_info_sysv (info, abfd)
-     symbol_info *info;
+     struct extended_symbol_info *info;
      bfd *abfd;
 {
-  print_symname ("%-20s|", info->name, abfd);	/* Name */
-  if (bfd_is_undefined_symclass (info->type))
+  print_symname ("%-20s|", info->sinfo->name, abfd);	/* Name */
+  if (bfd_is_undefined_symclass (info->sinfo->type))
     printf ("        ");	/* Value */
   else
-    print_value (abfd, info->value);
-  printf ("|   %c  |", info->type);	/* Class */
-  if (info->type == '-')
+    print_value (abfd, info->sinfo->value);
+  printf ("|   %c  |", info->sinfo->type);	/* Class */
+  if (info->sinfo->type == '-')
     {
       /* A stab.  */
-      printf ("%18s|  ", info->stab_name);	/* (C) Type */
-      printf (desc_format, info->stab_desc);	/* Size */
+      printf ("%18s|  ", info->sinfo->stab_name);	/* (C) Type */
+      printf (desc_format, info->sinfo->stab_desc);	/* Size */
       printf ("|     |");	/* Line, Section */
     }
   else
-    printf ("                  |      |     |");	/* Type, Size, Line, Section */
+    {
+      printf ("                  |");
+      print_value(abfd, info->ssize);
+      printf("|     |");	/* Type, Size, Line, Section */
+    }
 }
 
 static void
 print_symbol_info_posix (info, abfd)
-     symbol_info *info;
+     struct extended_symbol_info *info;
      bfd *abfd;
 {
-  print_symname ("%s ", info->name, abfd);
-  printf ("%c ", info->type);
-  if (bfd_is_undefined_symclass (info->type))
+  print_symname ("%s ", info->sinfo->name, abfd);
+  printf ("%c ", info->sinfo->type);
+  if (bfd_is_undefined_symclass (info->sinfo->type))
     printf ("        ");
   else
-    print_value (abfd, info->value);
+    print_value (abfd, info->sinfo->value);
   /* POSIX.2 wants the symbol size printed here, when applicable;
      BFD currently doesn't provide it, so we take the easy way out by
      considering it to never be applicable.  */


More information about the Binutils mailing list