]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix stripping relocs in a file with mergeable notes.
authorNick Clifton <nickc@redhat.com>
Fri, 8 Dec 2017 10:07:14 +0000 (10:07 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 8 Dec 2017 10:07:14 +0000 (10:07 +0000)
  A recent Fedora bug (1520805) exposed a problem with objcopy's reloc
  copying code, when a binary also contains mergeable notes.  The note
  merging code would delete some relocs, but then the reloc copying code
  would try to put them back again, which did not work.

  So I am checking in the patch below to fix the problem.  The patch
  also tweaks one of the binutils note merging tests so that it is
  skipped for the Sparc64 target, since this has funky relocs.

binutils * objcopy.c (copy_relocations_in_section): Use the orelocations
field of the input section, if it has been initialised.
* testsuite/binutils-all/note-2-64.d: Skip test on Sparc64.

bfd * elfcode.h (elf_write_relocs): Check for an empty howto field.

bfd/ChangeLog
bfd/elfcode.h
binutils/ChangeLog
binutils/objcopy.c
binutils/testsuite/binutils-all/note-2-64.d

index 455153c22a76a5874321806f835f1625f6d58a0f..7f59fa01a1d8b6a174c6b7770f9ef8fa9ddd4a73 100644 (file)
@@ -1,3 +1,7 @@
+2017-12-08  Nick Clifton  <nickc@redhat.com>
+
+       * elfcode.h (elf_write_relocs): Check for an empty howto field.
+
 2017-12-08  Sangamesh Mallayya  <sangamesh.swamy@in.ibm.com>
 
        * bfd.c (bfd_get_sign_extend_vma): Handle aix5coff64-rs6000.
index 80b26aa803a50457c9c03bcf49cd4f62754c604e..00684d596076759cb33cccf11da1b9832e95c2b8 100644 (file)
@@ -958,6 +958,12 @@ elf_write_relocs (bfd *abfd, asection *sec, void *data)
          return;
        }
 
+      if (ptr->howto == NULL)
+       {
+         *failedp = TRUE;
+         return;
+       }
+
       src_rela.r_offset = ptr->address + addr_offset;
       src_rela.r_info = ELF_R_INFO (n, ptr->howto->type);
       src_rela.r_addend = ptr->addend;
index 058ebf38bec29f8d9c9a82cc4e3e259b23e00584..4f29d19c3156b19009de1c0acba7526f83f29e88 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-08  Nick Clifton  <nickc@redhat.com>
+
+       * objcopy.c (copy_relocations_in_section): Use the orelocations
+       field of the input section, if it has been initialised.
+       * testsuite/binutils-all/note-2-64.d: Skip test on Sparc64.
+
 2017-12-06  Jim Wilson  <jimw@sifive.com>
 
        PR 22465
index f40b355c14b58f3ec04c860dad615ba452b0a585..5026fd8af21d2817ced48a52af2a1ecf88c0580a 100644 (file)
@@ -3785,14 +3785,24 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
     }
   else
     {
-      relpp = (arelent **) xmalloc (relsize);
-      relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
-      if (relcount < 0)
+      if (isection->orelocation != NULL)
        {
-         status = 1;
-         bfd_nonfatal_message (NULL, ibfd, isection,
-                               _("relocation count is negative"));
-         return;
+         /* Some other function has already set up the output relocs
+            for us, so scan those instead of the default relocs.  */
+         relcount = isection->reloc_count;
+         relpp = isection->orelocation;
+       }
+      else
+       {
+         relpp = (arelent **) xmalloc (relsize);
+         relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
+         if (relcount < 0)
+           {
+             status = 1;
+             bfd_nonfatal_message (NULL, ibfd, isection,
+                                   _("relocation count is negative"));
+             return;
+           }
        }
 
       if (strip_symbols == STRIP_ALL)
@@ -3815,7 +3825,8 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
                  temp_relpp [temp_relcount++] = relpp [i];
            }
          relcount = temp_relcount;
-         free (relpp);
+         if (isection->orelocation == NULL)
+           free (relpp);
          relpp = temp_relpp;
        }
 
index 85358213a2c7721fcce357e9e684fe8d5b6a51c6..f9be89756aee329b690cabfef8c1372d974fb5ec 100644 (file)
@@ -3,6 +3,10 @@
 #objcopy: --merge-notes
 #name: merge notes section (64-bits)
 #source: note-2-64.s
+#not-target: sparc64-*-*
+# Internally the Sparc64 backend uses two relocs for every one reloc visible externally.
+# Unfortunately the BFD library does not provide a target specific way to delete individual
+# relocs, so the note merging feature fails.
 
 #...
   Owner                 Data size      Description