Use stable sort for ld -r relocs

Alan Modra amodra@gmail.com
Wed Aug 26 15:18:00 GMT 2015


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



More information about the Binutils mailing list