]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf: Remove zero-sized relocation section from section group
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 4 Apr 2020 02:06:29 +0000 (19:06 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 4 Apr 2020 02:06:39 +0000 (19:06 -0700)
Remove zero-sized relocation section from a section group since it has
been removed from the output.

PR ld/25767
* elf.c (_bfd_elf_fixup_group_sections): Remove zero-sized
relocation section from section group.

bfd/ChangeLog
bfd/elf.c

index 64c3dde475424dda681c0ac5e2992711976ba8c2..57cf0f139c9fce70cbca7adb02aed037284b60da 100644 (file)
@@ -1,3 +1,9 @@
+2020-04-03  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/25767
+       * elf.c (_bfd_elf_fixup_group_sections): Remove zero-sized
+       relocation section from section group.
+
 2020-04-02  Jan W. Jagersma  <jwjagersma@gmail.com>
 
        * bfdio.c (bfd_bread, bfd_tell, bfd_seek, bfd_mmap): Always add
index 86dadea05caff48339c36872f1bff867f711fd17..1780074f5ab89139b2f1b833c0862e0bb1d0af18 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7929,19 +7929,34 @@ _bfd_elf_fixup_group_sections (bfd *ibfd, asection *discarded)
                elf_section_flags (s->output_section) &= ~SHF_GROUP;
                elf_group_name (s->output_section) = NULL;
              }
-           /* Conversely, if the member section is not being output
-              but the SHT_GROUP section is, then adjust its size.  */
-           else if (s->output_section == discarded
-                    && isec->output_section != discarded)
+           else
              {
                struct bfd_elf_section_data *elf_sec = elf_section_data (s);
-               removed += 4;
-               if (elf_sec->rel.hdr != NULL
-                   && (elf_sec->rel.hdr->sh_flags & SHF_GROUP) != 0)
-                 removed += 4;
-               if (elf_sec->rela.hdr != NULL
-                   && (elf_sec->rela.hdr->sh_flags & SHF_GROUP) != 0)
-                 removed += 4;
+               if (s->output_section == discarded
+                   && isec->output_section != discarded)
+                 {
+                   /* Conversely, if the member section is not being
+                      output but the SHT_GROUP section is, then adjust
+                      its size.  */
+                   removed += 4;
+                   if (elf_sec->rel.hdr != NULL
+                       && (elf_sec->rel.hdr->sh_flags & SHF_GROUP) != 0)
+                     removed += 4;
+                   if (elf_sec->rela.hdr != NULL
+                       && (elf_sec->rela.hdr->sh_flags & SHF_GROUP) != 0)
+                     removed += 4;
+                 }
+               else
+                 {
+                   /* Also adjust for zero-sized relocation member
+                      section.  */
+                   if (elf_sec->rel.hdr != NULL
+                       && elf_sec->rel.hdr->sh_size == 0)
+                     removed += 4;
+                   if (elf_sec->rela.hdr != NULL
+                       && elf_sec->rela.hdr->sh_size == 0)
+                     removed += 4;
+                 }
              }
            s = elf_next_in_group (s);
            if (s == first)