This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Use stable sort for ld -r relocs
- From: Alan Modra <amodra at gmail dot com>
- To: Michael Matz <matz at suse dot de>
- Cc: binutils at sourceware dot org
- Date: Thu, 27 Aug 2015 00:47:52 +0930
- Subject: Re: Use stable sort for ld -r relocs
- Authentication-results: sourceware.org; auth=none
- References: <20150826140258 dot GB24814 at bubble dot grove dot modra dot org> <alpine dot LSU dot 2 dot 20 dot 1508261648230 dot 30229 at wotan dot suse dot de>
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