unstrip: Renumber the group section indexes.
authorMark Wielaard <mark@klomp.org>
Sat, 13 Oct 2018 08:27:47 +0000 (10:27 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 19 Oct 2018 20:53:40 +0000 (22:53 +0200)
When unstripping we might need to renumber the group section indexes.
Just like we do when stripping.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/unstrip.c

index d151e0d..5aa31fc 100644 (file)
@@ -1,3 +1,7 @@
+2018-10-19  Mark Wielaard  <mark@klomp.org>
+
+       * unstrip.c (copy_elided_sections): Renumber group section indexes.
+
 2018-10-12  Mark Wielaard  <mark@klomp.org>
 
        * strip.c (handle_elf): Don't remove SHF_GROUP flag from sections.
index 03a0346..2cfd3b3 100644 (file)
@@ -1708,6 +1708,20 @@ more sections in stripped file than debug file -- arguments reversed?"));
            if (shdr_mem.sh_type == SHT_DYNSYM)
              stripped_dynsym = sec;
          }
+
+       if (shdr_mem.sh_type == SHT_GROUP)
+         {
+           /* We must adjust all the section indices in the group.
+              Skip the first word, which is the section group flag.
+              Everything else is a section index.  */
+           Elf32_Word *shndx = (Elf32_Word *) outdata->d_buf;
+           for (size_t i = 1; i < shdr_mem.sh_size / sizeof (Elf32_Word); ++i)
+             if (shndx[i]  == SHN_UNDEF || shndx[i] >= stripped_shnum)
+               error (EXIT_FAILURE, 0,
+                      _("group has invalid section index [%zd]"), i);
+             else
+               shndx[i] = ndx_section[shndx[i] - 1];
+         }
       }
 
   /* We may need to update the symbol table.  */