Bug 5031 - nm --size-sort can report bogus sizes on .o files.
Summary: nm --size-sort can report bogus sizes on .o files.
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: binutils
Version: 6.0
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Cristian Gafton
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 1999-09-09 19:53 UTC by Nalin Dahyabhai
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2000-02-04 17:39:36 UTC

Attachments (Terms of Use)

Description Jim Kingdon 1999-09-09 19:53:45 UTC
(reported by Bill Nottingham).

This is a bug whereby nm --size-sort will sometimes
think that a symbol extends to the end of the current
section, when it really is smaller than that.
Enclosed is a test case and a fix.

[kingdon@porky tmp]$ cat hello.c
int y = 50;

static int bar (void) { printf ("hello, world\n"); return 0;

main (int argc, char **argv)
  return bar ();
[kingdon@porky tmp]$ gcc -c -o hello.o hello.c
[kingdon@porky tmp]$ nm --size-sort hello.o
00000004 D y
00000010 T main
00000028 t bar
[kingdon@porky tmp]$ nm-new --size-sort hello.o
00000004 D y
00000010 T main
00000018 t bar
[kingdon@porky tmp]$

1999-09-09  Jim Kingdon  <http://developer.redhat.com>

        * nm.c (size_forward1): Only sort by address if the
symbols are in
        the same section.

--- nm.c~       Sat Feb 20 19:56:56 1999
+++ nm.c        Thu Sep  9 15:33:12 1999
@@ -726,11 +726,19 @@
   if (bfd_is_und_section (ys))
     abort ();

-  if (valueof (x) != valueof (y))
-    return valueof (x) < valueof (y) ? -1 : 1;
   if (xs->vma != ys->vma)
     return xs->vma < ys->vma ? -1 : 1;
+  /* We want to sort by address (or symbol name or
whatever) only
+     within a given section (e.g. in .o files several
sections will be
+     mapped to address zero and we want all the symbols in
one section
+     to be together when we go to compute sizes).  */
+  if (xs != ys)
+    return strcmp (bfd_section_name (sort_bfd, xs),
+                  bfd_section_name (sort_bfd, ys));
+  if (valueof (x) != valueof (y))
+    return valueof (x) < valueof (y) ? -1 : 1;

   xn = bfd_asymbol_name (x);
   yn = bfd_asymbol_name (y);

Comment 1 Jim Kingdon 1999-09-10 15:24:59 UTC
Submitted to binutils maintainers at

This isn't important enough to need a new RPM before it makes it
into a binutils release.

Comment 2 Cristian Gafton 2000-02-04 17:39:59 UTC
Fixed in the current devel tree (patch applied, I have no idea why the binutils
dudes have not integrate it yet)

Note You need to log in before you can comment on or make changes to this bug.