[PATCH] nm size/value output fix.

Elias Athanasopoulos eathan@otenet.gr
Fri May 31 10:51:00 GMT 2002


Hi,

Here is the full patch.

The size is not printed if it is 0. This is used when we don't sort by 
size (we pass 0 in print_symbols()). If this patch is applied, I'll go on
and make another one in order to count the symbol's size even if the
--size-sort is not used. I wanted to do this in this patch, but I was
puzzled by the fact that nm reports different size than objdump and
readelf.

Elias

-- 
http://gnewtellium.sourceforge.net			MP3 is not a crime.	
-------------- next part --------------
--- nm.c.orig	Thu May 16 18:18:33 2002
+++ nm.c	Fri May 31 20:52:01 2002
@@ -49,6 +49,20 @@
   asymbol **syms;
 };
 
+struct extended_symbol_info 
+{
+  symbol_info *sinfo;
+  bfd_vma ssize;
+#define SYM_NAME(sym)        (sym->sinfo->name)
+#define SYM_VALUE(sym)       (sym->sinfo->value)
+#define SYM_TYPE(sym)        (sym->sinfo->type)
+#define SYM_STAB_NAME(sym)   (sym->sinfo->stab_name)
+#define SYM_STAB_DESC(sym)   (sym->sinfo->stab_desc)
+#define SYM_STAB_OTHER(sym)  (sym->sinfo->stab_other)
+#define SYM_SIZE(sym)        (sym->ssize)
+  /* FIXME: we should add more fields for Type, Line, Section */
+};
+
 static void
 usage PARAMS ((FILE *, int));
 
@@ -84,7 +98,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 +169,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 +197,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 +1152,7 @@
       if (sym == NULL)
 	bfd_fatal (bfd_get_filename (abfd));
 
-      print_symbol (abfd, sym, archive_bfd);
+      print_symbol (abfd, sym, 0, archive_bfd);
     }
 }
 
@@ -1164,25 +1178,25 @@
   for (; from < fromend; from++)
     {
       asymbol *sym;
+      bfd_vma ssize;
 
       sym = bfd_minisymbol_to_symbol (abfd, dynamic, from->minisym, store);
       if (sym == NULL)
 	bfd_fatal (bfd_get_filename (abfd));
 
-      /* 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 +1211,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,66 +1503,81 @@
 
 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 (SYM_TYPE (info)))
     {
       if (print_width == 16)
 	printf ("        ");
       printf ("        ");
     }
-  else
-    print_value (abfd, info->value);
-  printf (" %c", info->type);
-  if (info->type == '-')
+  else {
+    print_value (abfd, SYM_VALUE (info));
+    if (SYM_SIZE (info)) {
+      printf(" ");
+      print_value (abfd, SYM_SIZE (info));
+    }
+  }
+  printf (" %c", SYM_TYPE (info));
+  if (SYM_TYPE (info) == '-')
     {
       /* A stab.  */
       printf (" ");
-      printf (other_format, info->stab_other);
+      printf (other_format, SYM_STAB_OTHER (info));
       printf (" ");
-      printf (desc_format, info->stab_desc);
-      printf (" %5s", info->stab_name);
+      printf (desc_format, SYM_STAB_DESC (info));
+      printf (" %5s", SYM_STAB_NAME (info));
     }
-  print_symname (" %s", info->name, abfd);
+  print_symname (" %s", SYM_NAME (info), 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|", SYM_NAME (info), abfd);	/* Name */
+  if (bfd_is_undefined_symclass (SYM_TYPE (info)))
     printf ("        ");	/* Value */
   else
-    print_value (abfd, info->value);
-  printf ("|   %c  |", info->type);	/* Class */
-  if (info->type == '-')
+    print_value (abfd, SYM_VALUE (info));
+  printf ("|   %c  |", SYM_TYPE (info));	/* Class */
+  if (SYM_TYPE (info) == '-')
     {
       /* A stab.  */
-      printf ("%18s|  ", info->stab_name);	/* (C) Type */
-      printf (desc_format, info->stab_desc);	/* Size */
+      printf ("%18s|  ", SYM_STAB_NAME (info));	/* (C) Type */
+      printf (desc_format, SYM_STAB_DESC (info));	/* Size */
       printf ("|     |");	/* Line, Section */
     }
   else
-    printf ("                  |      |     |");	/* Type, Size, Line, Section */
+    {	
+      /* Type, Size, Line, Section */
+      printf ("                  |");
+      if (SYM_SIZE (info))
+	print_value(abfd, SYM_SIZE (info));
+      else
+	printf("        ");
+      printf("|     |");	
+    }
 }
 
 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 ", SYM_NAME (info), abfd);
+  printf ("%c ", SYM_TYPE (info));
+  if (bfd_is_undefined_symclass (SYM_TYPE (info)))
     printf ("        ");
   else
-    print_value (abfd, info->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.  */
+    {
+    print_value (abfd, SYM_VALUE (info));
+    printf(" ");
+    if (SYM_SIZE (info))
+      print_value (abfd, SYM_SIZE (info));
+    }
 }
 
 static void


More information about the Binutils mailing list