This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] nm size/value output fix.


Hi Nick,

The full patch, as promised.

Nick, if you have the time, can you verify that the modification below is
not nonsense?

+      /* For elf we have already computed the correct symbol size */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+       ssize = from->size;
+      else
+       ssize = from->size - bfd_section_vma (abfd, bfd_get_section (sym));


Elias


2002-6-13  Elias Athanasopoulos  <eathan@otenet.gr>

	* nm.c: Introduce extended_symbol_info structure, in order to hold
	the size of symbols. Print not only the size of the symbols when we 
	sort by size, but both size and value.


--- nm.c.orig	Sat Jun  8 12:30:11 2002
+++ nm.c	Thu Jun 13 12:30:22 2002
@@ -50,6 +50,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));
 
@@ -85,7 +99,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));
@@ -156,13 +170,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));
@@ -184,7 +198,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[] =
 {
@@ -1126,6 +1140,7 @@
 {
   asymbol *store;
   bfd_byte *from, *fromend;
+  bfd_vma ssize;
 
   store = bfd_make_empty_symbol (abfd);
   if (store == NULL)
@@ -1141,7 +1156,12 @@
       if (sym == NULL)
 	bfd_fatal (bfd_get_filename (abfd));
 
-      print_symbol (abfd, sym, archive_bfd);
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) 
+	ssize = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
+      else
+	ssize = 0;
+
+      print_symbol (abfd, sym, ssize, archive_bfd);
     }
 }
 
@@ -1167,25 +1187,29 @@
   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));
+      /* For elf we have already computed the correct symbol size */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	ssize = from->size;
+      else
+	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);
@@ -1200,9 +1224,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)
@@ -1489,66 +1516,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
 












Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]