Fix bug merging notes with objcopy when no merging results in zeroes being written...
authorNick Clifton <nickc@redhat.com>
Thu, 7 Nov 2019 11:36:06 +0000 (11:36 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 7 Nov 2019 11:36:06 +0000 (11:36 +0000)
* objcopy.c (copy_object): Skip note sections that do not have
an output section.  Always copy note sections, even if no
changes are made.

binutils/ChangeLog
binutils/objcopy.c

index 61a2e0020ccf56e4e9b0fd32109b7e1dc32e2d2b..fb1a99d5ae41c056d661f8806e4f954ad307fcdf 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-07  Nick Clifton  <nickc@redhat.com>
+
+       * objcopy.c (copy_object): Skip note sections that do not have
+       an output section.  Always copy note sections, even if no
+       changes are made.
+
 2019-11-06  Christian Eggers  <ceggers@gmx.de>
 
        * readelf.c (IN_RANGE): Rename parameter OFF to NELEM. Add
index 56439700c229c4e501bb8b7f881bdb1cc6b1ceb8..ea6eb646b4f01077d474d3a7aef4e4965bc8e292 100644 (file)
@@ -2878,6 +2878,11 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
          if (! is_mergeable_note_section (ibfd, osec))
            continue;
 
+         /* If the section is going to be completly deleted then
+            do not bother to merge it.  */
+         if (osec->output_section == NULL)
+           continue;
+
          bfd_size_type size = bfd_section_size (osec);
 
          if (size == 0)
@@ -2893,25 +2898,19 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
            {
              bfd_nonfatal_message (NULL, ibfd, osec,
                                    _("warning: could not load note section"));
-             free (merged->contents);
              free (merged);
              continue;
            }
 
          merged->size = merge_gnu_build_notes (ibfd, osec, size,
                                                merged->contents);
-         if (merged->size == size)
-           {
-             /* Merging achieves nothing.  */
-             merge_debug ("Merge of section %s achieved nothing - skipping\n",
-                          bfd_section_name (osec));
-             free (merged->contents);
-             free (merged);
-             continue;
-           }
 
-         if (osec->output_section == NULL
-             || !bfd_set_section_size (osec->output_section, merged->size))
+         /* FIXME: Once we have read the contents in, we must write
+            them out again.  So even if the mergeing has achieved
+            nothing we still add this entry to the merge list.  */
+
+         if (size != merged->size
+             && !bfd_set_section_size (osec->output_section, merged->size))
            {
              bfd_nonfatal_message (NULL, obfd, osec,
                                    _("warning: failed to set merged notes size"));
@@ -3277,16 +3276,16 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
                {
                  bfd_nonfatal_message
                    (NULL, obfd, osec,
-                    _("error: failed to copy merged notes into output"));
+                    _("error: failed to locate merged notes"));
                  continue;
                }
            }
 
-         if (! is_mergeable_note_section (obfd, osec))
+         if (merged->contents == NULL)
            {
              bfd_nonfatal_message
                (NULL, obfd, osec,
-                _("error: failed to copy merged notes into output"));
+                _("error: failed to merge notes"));
              continue;
            }
 
This page took 0.028217 seconds and 4 git commands to generate.