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: pointer comparison breaks Solaris' qsort


On Jun  9, 2004, Alan Modra <amodra@bigpond.net.au> wrote:

> On Wed, Jun 09, 2004 at 12:35:03PM +0100, Dave Korn wrote:
>> > -----Original Message-----
>> > From: binutils-owner On Behalf Of Alexandre Oliva
>> > Sent: 09 June 2004 12:29
>> 
>> > Maybe if you can point me at the other chunk of code you have in mind,
>> > I could volunteer to fix this other bug, but conditioning the
>> > acceptance of a correct patch that fixes a bug on fixing some other
>> > bug is not reasonable IMHO.
>> 
>> .... unless consistency between the two pieces of code is a vital
>> requirement, n'est-ce pas?

> Exactly.  Alex, the other chunk of code is in the block immediately
> after the qsort that uses elf_sort_symbol.

Aah!  I was looking for another qsort compare function.  Sorry.
Somehow I missed the `binary search' reference in your e-mail.  Please
accept my apologies for the tone of my previous e-mail.  It was not
called for.

> If you sort the array differently (your change to elf_sort_symbol),
> you'd better also do the binary search in the same way.

Certainly.

Here's the patch I'm testing atm.  I'll check it in if testing
succeeds.

Thanks for pointing out my mistake.

Index: bfd/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* elflink.c (elf_sort_symbol): Compare section id, not pointers.
	(elf_link_add_object_symbols): Likewise.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.71
diff -u -p -r1.71 elflink.c
--- bfd/elflink.c 25 May 2004 06:33:46 -0000 1.71
+++ bfd/elflink.c 9 Jun 2004 13:35:40 -0000
@@ -2728,7 +2728,7 @@ elf_sort_symbol (const void *arg1, const
     return vdiff > 0 ? 1 : -1;
   else
     {
-      long sdiff = h1->root.u.def.section - h2->root.u.def.section;
+      long sdiff = h1->root.u.def.section->id - h2->root.u.def.section->id;
       if (sdiff != 0)
 	return sdiff > 0 ? 1 : -1;
     }
@@ -3982,7 +3982,7 @@ elf_link_add_object_symbols (bfd *abfd, 
 		i = idx + 1;
 	      else
 		{
-		  long sdiff = slook - h->root.u.def.section;
+		  long sdiff = slook->id - h->root.u.def.section->id;
 		  if (sdiff < 0)
 		    j = idx;
 		  else if (sdiff > 0)
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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