]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
When mapping sections to segments ensure that we do not add sections whose VMA->LMA...
authorVijay Shankar <shank.vijay@yandex.com>
Mon, 15 Apr 2024 15:27:21 +0000 (16:27 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 15 Apr 2024 15:27:21 +0000 (16:27 +0100)
  PR 31540

bfd/elf.c
binutils/testsuite/binutils-all/pr25662.ld

index c305b40eca321cfe7296b7f54aaeb38b08cba140..889078db097e38dc61b3c1b901f0a23a3f9a09ca 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8394,7 +8394,9 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
       /* Check to see if any sections in the input BFD
         covered by ELF program header have changed.  */
       Elf_Internal_Phdr *segment;
-      asection *section, *osec;
+      asection * section;
+      asection * osec;
+      asection * prev;
       unsigned int i, num_segments;
       Elf_Internal_Shdr *this_hdr;
       const struct elf_backend_data *bed;
@@ -8425,7 +8427,7 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
                  || segment->p_type == PT_DYNAMIC))
            goto rewrite;
 
-         for (section = ibfd->sections;
+         for (section = prev = ibfd->sections;
               section != NULL; section = section->next)
            {
              /* We mark the output section so that we know it comes
@@ -8446,9 +8448,13 @@ 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)
+                     || 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)
                    goto rewrite;
                }
+             prev = section;
            }
        }
 
index 19ef1391f8d998ce1a8ce38d5498a6f5895f223d..4951184f88ef09f37b4132c4e9f272c710aaa6a1 100644 (file)
@@ -12,4 +12,6 @@ SECTIONS
   .text : { *(.text) } > ROM
 
   .bss : { *(.bss) } > RAM
+
+  /DISCARD/ : { *(.*) }
 }