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, 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


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