merge_gnu_build_notes reloc deletion
authorAlan Modra <amodra@gmail.com>
Mon, 1 May 2017 04:41:27 +0000 (14:11 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 1 May 2017 04:43:31 +0000 (14:13 +0930)
If moving relocs, the next reloc to look at is at the same location.

* objcopy.c (merge_gnu_build_notes): Correct code deleting
relocs.

binutils/ChangeLog
binutils/objcopy.c

index 9eea3a050b4341b77419fe8814d6e4b0a79ff950..ae8defb4dd300d29f158a4c5c31698ce9566bbaf 100644 (file)
@@ -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
index 9bad4b70f2c07f4fcaa8cfc8925ebd22cce88671..42c7775234dd70a84a959686769a6e39f8f5c30c 100644 (file)
@@ -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);
        }