public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* nm --size-sort on .o files is buggy
@ 1999-09-10  8:16 Jim Kingdon
  0 siblings, 0 replies; only message in thread
From: Jim Kingdon @ 1999-09-10  8:16 UTC (permalink / raw)
  To: binutils

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-09-10  8:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-10  8:16 nm --size-sort on .o files is buggy Jim Kingdon

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).