]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix test for sections with different VMA<->LMA relationships so that it only applies...
authorNick Clifton <nickc@redhat.com>
Tue, 16 Apr 2024 16:54:13 +0000 (17:54 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 16 Apr 2024 16:54:13 +0000 (17:54 +0100)
  PR 31450

bfd/elf.c

index 889078db097e38dc61b3c1b901f0a23a3f9a09ca..52a6a2f56c3837fe8955249850dca8318841e63d 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8427,7 +8427,7 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
                  || segment->p_type == PT_DYNAMIC))
            goto rewrite;
 
-         for (section = prev = ibfd->sections;
+         for (section = ibfd->sections, prev = NULL;
               section != NULL; section = section->next)
            {
              /* We mark the output section so that we know it comes
@@ -8448,13 +8448,20 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
                      || section->vma != osec->vma
                      || section->size != osec->size
                      || section->rawsize != osec->rawsize
-                     || section->alignment_power != osec->alignment_power
-                     /* PR 31450: Make sure this section's vma to lma
-                        relationship is the same as previous section's.  */
-                     || section->lma - section->vma != prev->lma - prev->vma)
+                     || section->alignment_power != osec->alignment_power)
                    goto rewrite;
+
+                 /* PR 31450: If this is an allocated section then make sure
+                    that this section's vma to lma relationship is the same
+                    as previous (allocated) section's.  */
+                 if (prev != NULL
+                     && section->flags & SEC_ALLOC
+                     && section->lma - section->vma != prev->lma - prev->vma)
+                   goto rewrite;
+
+                 if (section->flags & SEC_ALLOC)
+                   prev = section;
                }
-             prev = section;
            }
        }