]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
mmo.c: Fix ld testsuite regression "objcopy executable (pr25662)".
authorHans-Peter Nilsson <hp@bitrange.com>
Wed, 1 Apr 2020 02:03:46 +0000 (04:03 +0200)
committerHans-Peter Nilsson <hp@bitrange.com>
Wed, 1 Apr 2020 02:03:46 +0000 (04:03 +0200)
* mmo.c (mmo_scan): Create .text section only when needed, not
from the start.

For the test-case at hand, the .data section is created and output
first by the linker, but the mmo input-reader mmo_scan always creates
a .text section.  Since sections are output in the order in which
they're created, it's output first, breaking the assumption that
obcopy without options (or with -p) creates output identical to its
input.  The point of creating it at the top of mmo_scan is a trivial
default assignment for the current section variable "sec".  Instead we
now defer the default, creating it only when needed and sec is NULL.

bfd/ChangeLog
bfd/mmo.c

index 4c2bb14f6ccb99accce826655ba03659528e8639..d11421f6a2fcf7ff2fe6e350b91e4e2e98c3c229 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-01  Hans-Peter Nilsson  <hp@bitrange.com>
+
+       * mmo.c (mmo_scan): Create .text section only when needed, not
+       from the start.
+
 2020-03-31  Alan Modra  <amodra@gmail.com>
 
        * coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Correct bfd_bread
index 3b7e5c0c33fcb72a33bd111046a655c94ff16ec0..ea7c4c66b549e519915442dbe853848af9c55dfc 100644 (file)
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -1588,7 +1588,7 @@ mmo_scan (bfd *abfd)
   unsigned int lineno = 1;
   bfd_boolean error = FALSE;
   bfd_vma vma = 0;
-  asection *sec = bfd_make_section_old_way (abfd, MMO_TEXT_SECTION_NAME);
+  asection *sec = NULL;
   asection *non_spec_sec = NULL;
   bfd_vma non_spec_vma = 0;
   bfd_size_type nbytes_read = 0;
@@ -1646,6 +1646,8 @@ mmo_scan (bfd *abfd)
                goto error_return;
 
              vma &= ~3;
+             if (sec == NULL)
+               sec = bfd_make_section_old_way (abfd, MMO_TEXT_SECTION_NAME);
              mmo_xore_32 (sec, vma, bfd_get_32 (abfd, buf));
              vma += 4;
              lineno++;
@@ -2038,6 +2040,8 @@ mmo_scan (bfd *abfd)
       else
        {
          /* This wasn't a lopcode, so store it in the current section.  */
+         if (sec == NULL)
+           sec = bfd_make_section_old_way (abfd, MMO_TEXT_SECTION_NAME);
          mmo_xore_32 (sec, vma & ~3, bfd_get_32 (abfd, buf));
          vma += 4;
          vma &= ~3;