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: Jiong Wang <jiong dot wang at arm dot com>
- Cc: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Fri, 18 Sep 2015 12:43:41 +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> <n99si6fu8kw dot fsf at arm dot com> <20150916084631 dot GF7224 at bubble dot grove dot modra dot org>
On Wed, Sep 16, 2015 at 06:16:31PM +0930, Alan Modra wrote:
> PR 18867
> * elflink.c (elf_link_adjust_relocs): Modify insertion sort to
> insert a run. Return status in case of malloc failure.
> Adjust callers.
I see I made the main insertion sort loop do one unnecessary iteration
with the last patch. Fixed as follows.
PR 18867
* elflink.c (elf_link_adjust_relocs): Correct start of insertion
sort main loop.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 8659099..4e52d7b 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -8313,7 +8313,7 @@ elf_link_adjust_relocs (bfd *abfd,
memcpy (base, onebuf, elt_size);
}
- for (p = base + elt_size; p < end; )
+ for (p = base + elt_size; (p += elt_size) < end; )
{
/* base to p is sorted, *p is next to insert. */
r_off = (*ext_r_off) (p);
@@ -8355,10 +8355,8 @@ elf_link_adjust_relocs (bfd *abfd,
memmove (loc, p, runlen);
memcpy (loc + runlen, buf, sortlen);
}
- p += runlen;
+ p += runlen - elt_size;
}
- else
- p += elt_size;
}
/* Hashes are no longer valid. */
free (reldata->hashes);
--
Alan Modra
Australia Development Lab, IBM