This is the mail archive of the binutils@sourceware.cygnus.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]

nm --size-sort on .o files is buggy


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.  Testing was on
Red Hat Linux 6.0 but the bug probably happens on many/most platforms.

This is bug #5031 at http://developer.redhat.com/bugzilla/index.html
in case anyone cares.

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

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

int
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);



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