public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [BUG] nm --size-sort doesn't print the size
@ 2003-03-16  6:56 Bradley Baetz
  2003-03-16  8:27 ` Elias Athanasopoulos
  0 siblings, 1 reply; 3+ messages in thread
From: Bradley Baetz @ 2003-03-16  6:56 UTC (permalink / raw)
  To: binutils

The nm manpage says:

  --size-sort
      Sort  symbols  by  size.   The  size  is computed as the difference
      between the value of the symbol and the value of  the  symbol  with
      the  next  higher value.  The size of the symbol is printed, rather
      than the value.

This last sentence appears to not be true, with |GNU nm 2.13.90.0.16
20021126| (redhat binutils-2.13.90.0.16-5 from rawhide) or |GNU nm
2.13.90.0.18 20030121 Debian GNU/Linux| (2.13.90.0.18-1.1 from debian
unstable).

test.c:

void test() {
  int hello_world=1;
}

~$ gcc -c -o test.o test.c

~$ nm test.o
00000000 T test
~$ nm -S test.o
00000000 0000000f T test

So the size is 0xf, at location 0x0

~$ nm --size-sort test.o
00000000 T test

which isn't the size.

On GNU nm 2.11.90.0.8 (redhat 7.2 binutils-2.11.90.0.8-12):

~$ nm --size-sort test.o
00000010 T test

(Its a different machine/compiler, which explains the different size)

mozilla uses this as part of some tools to determine the size of various
subroutines. -S doesn't work in 2.11.90, so we can't use that - is there
an alternative workarround for this bug? Alternativly, is there a way to
use -S (in 2.13.90) to only print the size, without printing the address?

Looking at cvs logs, this appears to have been done in:

http://sources.redhat.com/ml/binutils/2002-06/msg00495.html

and reverting that patch fixes this problem. Was this change in behaviour
done on purpose?

Thanks,

Bradley

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

* Re: [BUG] nm --size-sort doesn't print the size
  2003-03-16  6:56 [BUG] nm --size-sort doesn't print the size Bradley Baetz
@ 2003-03-16  8:27 ` Elias Athanasopoulos
  2003-03-17 10:12   ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: Elias Athanasopoulos @ 2003-03-16  8:27 UTC (permalink / raw)
  To: Bradley Baetz; +Cc: binutils

On Sun, Mar 16, 2003 at 05:56:38PM +1100, Bradley Baetz wrote:
> The nm manpage says:
> 
>   --size-sort
>       Sort  symbols  by  size.   The  size  is computed as the difference
>       between the value of the symbol and the value of  the  symbol  with
>       the  next  higher value.  The size of the symbol is printed, rather
>       than the value.

The documentation has been changed, but it is still wrong. I have attached
a patch that makes nm to behave as the current documentation states.

> mozilla uses this as part of some tools to determine the size of various
> subroutines. -S doesn't work in 2.11.90, so we can't use that - is there

2.11.90 embeds the old behaviour of nm, which is workable for you.

> and reverting that patch fixes this problem. Was this change in behaviour
> done on purpose?

The change was made so as all the formats operate in a cosistent way; dump
the symbol's value : size.

I think the patch below fixes your problem, but IMHO this kind of behaviour
is not logical; the documentation part should be changed instead.

Elias

ChangeLog

2003-03-16  Elias Athanasopoulos  <elathan@phys.uoa.gr>

	nm.c (print_symbol_info_bsd): Print the symbol's size instead of the
	symbol's value when --size-sort is used, unless -S is used.
	

===================================================================
RCS file: /home/anteater/bucvs/src/binutils/nm.c,v
retrieving revision 1.3
diff -u -r1.3 /home/anteater/bucvs/src/binutils/nm.c
--- /home/anteater/bucvs/src/binutils/nm.c	2003/03/16 07:36:41	1.3
+++ /home/anteater/bucvs/src/binutils/nm.c	2003/03/16 08:18:39
@@ -1538,8 +1538,13 @@
       printf ("        ");
     }
   else
-    {
-      print_value (abfd, SYM_VALUE (info));
+    { 
+      /* When we sort by size we print the size of the 
+         symbol instead of its value, unless -S is used.  */ 
+      if (sort_by_size && !print_size)
+        print_value (abfd, SYM_SIZE (info));
+      else
+        print_value (abfd, SYM_VALUE (info));
 
       if (print_size && SYM_SIZE (info))
 	{

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

* Re: [BUG] nm --size-sort doesn't print the size
  2003-03-16  8:27 ` Elias Athanasopoulos
@ 2003-03-17 10:12   ` Nick Clifton
  0 siblings, 0 replies; 3+ messages in thread
From: Nick Clifton @ 2003-03-17 10:12 UTC (permalink / raw)
  To: Bradley Baetz, Elias Athanasopoulos; +Cc: binutils

Hi Elias, Hi Bradley,

> > The nm manpage says:
> > 
> >   --size-sort
> >       Sort  symbols  by  size.   The  size  is computed as the difference
> >       between the value of the symbol and the value of  the  symbol  with
> >       the  next  higher value.  The size of the symbol is printed, rather
> >       than the value.

I am going to apply Elias's patch with two small additions - a
slightly more wordy comment, and a change to the documenation to
reflect the fact that for non-bsd formats both the size and the value
are printed when --size-sort is used.

Cheers
        Nick

Index: binutils/nm.c
===================================================================
RCS file: /cvs/src/src/binutils/nm.c,v
retrieving revision 1.35
diff -c -3 -p -w -r1.35 nm.c
*** binutils/nm.c	4 Mar 2003 16:23:46 -0000	1.35
--- binutils/nm.c	17 Mar 2003 10:10:05 -0000
*************** print_symbol_info_bsd (info, abfd)
*** 1539,1544 ****
--- 1539,1551 ----
      }
    else
      {
+       /* Normally we print the value of the symbol.  If we are printing the
+ 	 size or sorting by size then we print its size, execpt for the
+ 	 (weird) special case where both flags are defined, in which case we
+ 	 print both values.  This conforms to documented behaviour.  */
+       if (sort_by_size && !print_size)
+ 	print_value (abfd, SYM_SIZE (info));
+       else
  	print_value (abfd, SYM_VALUE (info));
  
        if (print_size && SYM_SIZE (info))

Index: binutils/doc/binutils.texi
===================================================================
RCS file: /cvs/src/src/binutils/doc/binutils.texi,v
retrieving revision 1.30
diff -c -3 -p -w -r1.30 binutils.texi
*** binutils/doc/binutils.texi	24 Feb 2003 16:20:28 -0000	1.30
--- binutils/doc/binutils.texi	17 Mar 2003 10:10:09 -0000
*************** Equivalent to @samp{-f posix}.
*** 857,863 ****
  
  @item -S
  @itemx --print-size
! Print size of defined symbols for the @code{bsd} output format.
  
  @item -s
  @itemx --print-armap
--- 857,863 ----
  
  @item -S
  @itemx --print-size
! Print size, not the value, of defined symbols for the @code{bsd} output format.
  
  @item -s
  @itemx --print-armap
*************** last come first.
*** 874,881 ****
  @item --size-sort
  Sort symbols by size.  The size is computed as the difference between
  the value of the symbol and the value of the symbol with the next higher
! value.  The size of the symbol is printed, rather than the value.
! structure.  If the @code{bsd} output format is used the size of the symbol 
  is printed, rather than the value, and @samp{-S} must be used in order 
  both size and value to be printed.
  
--- 874,880 ----
  @item --size-sort
  Sort symbols by size.  The size is computed as the difference between
  the value of the symbol and the value of the symbol with the next higher
! value.  If the @code{bsd} output format is used the size of the symbol 
  is printed, rather than the value, and @samp{-S} must be used in order 
  both size and value to be printed.
  

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

end of thread, other threads:[~2003-03-17 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-16  6:56 [BUG] nm --size-sort doesn't print the size Bradley Baetz
2003-03-16  8:27 ` Elias Athanasopoulos
2003-03-17 10:12   ` 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).