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: Michael Matz <matz at suse dot de>
- To: Alan Modra <amodra at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Wed, 26 Aug 2015 16:52:09 +0200 (CEST)
- 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>
Hi,
On Wed, 26 Aug 2015, Alan Modra wrote:
> A number of targets emit multiple relocs at a given r_offset, and
> depend on those relocs staying in their original order. qsort doesn't
> satisfy this requirement, although it appears from my non-rigorous
> testing that glibc's msort.c implementation may in fact be stable.
>
> I made the mistake of backporting my PR 17666 fix to 2.25.1, thinking
> the code had enough time to settle on mainline, but for anyone with a
> system libc that provides an unstable qsort this will mean 2.25.1 ld -r
> may be broken on some targets.
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;
}
Ciao,
Michael.