This is the mail archive of the binutils@sourceware.org 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: Use stable sort for ld -r relocs


On Wed, Aug 26, 2015 at 04:52:09PM +0200, Michael Matz wrote:
> Instead of implementing your own sorting algorithm you could also have 
> adjusted the comparison functions to provide a stable sort (never return 
> zero for different arguments), ala:
> 
>   cmp (void *a, void *b) {
>     if (a == b)
>       return 0;
>     if (contents of a and b differ)
>       return -1/1;
>     /* Contents same, but pointers differ, leave them in original
>        order.  */
>     return (a < b) ? -1 : 1;
>   }

I don't believe this is sufficient.  You need to also set up an array
of pointers to the elements, and sort with a level of indirection for
this to work.  See explanation at
http://stackoverflow.com/questions/584683/stabilizing-the-standard-library-qsort

-- 
Alan Modra
Australia Development Lab, IBM


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