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: deleting relocs, objcopy and BFD


On Thu, Apr 27, 2017 at 05:42:31PM +0200, Jose E. Marchesi wrote:
>   - The deletion logic in `merge_gnu_build_notes' then deletes two
>     internal relocs, leaving 7.  This sounds like a sequence of three
>     internal relocs gets broken.  I am not sure if this really a problem
>     (don't know much of mips64) but it is worth a check.

This part of the problem is simply an error in Nick's code, fixed as
follows.  I've read over your description of the reloc count problem
and am not too sure what to do, but my inclination would be to not
return a count from bfd_canonicalize_reloc and not set one in
bfd_set_reloc.  ie. rely on the sentinel.  That will mean rewriting
some code..

This patch doesn't fix the mips64 segfault which is caused by *3 reloc
count finding its way into section->reloc_count.

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 9eea3a0..ae8defb 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-01  Alan Modra  <amodra@gmail.com>
+
+	* objcopy.c (merge_gnu_build_notes): Correct code deleting
+	relocs.
+
 2017-04-28  Nick Clifton  <nickc@redhat.com>
 
 	PR binutils/21439
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 9bad4b7..42c7775 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2185,15 +2185,18 @@ merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte
 
       if (relcount > 0)
 	{
-	  arelent ** rel;
+	  arelent **rel = relpp;
 
-	  for (rel = relpp; rel < relpp + relcount; rel ++)
-	    if ((* rel)->howto == NULL)
+	  while (rel < relpp + relcount)
+	    if ((*rel)->howto != NULL)
+	      rel++;
+	    else
 	      {
 		/* Delete eliminated relocs.
 		   FIXME: There are better ways to do this.  */
-		memmove (rel, rel + 1, ((relcount - (rel - relpp)) - 1) * sizeof (* rel));
-		relcount --;
+		memmove (rel, rel + 1,
+			 ((relcount - (rel - relpp)) - 1) * sizeof (*rel));
+		relcount--;
 	      }
 	  bfd_set_reloc (abfd, sec, relpp, relcount);
 	}

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