896e01d
commit 73e83285fbeac648edb60a0c4767fad9d470cf0a
896e01d
Author: Mark Wielaard <mark@klomp.org>
896e01d
Date:   Sat Jul 21 23:40:11 2018 +0200
896e01d
896e01d
    unstrip: Handle SHT_GROUP sections in ET_REL files.
896e01d
    
896e01d
    SHT_GROUP sections are put in both the stripped and debug file.
896e01d
    Handle correcting the symbol table/name entry of the group only once.
896e01d
    
896e01d
    The testfile was generated with the gcc annobin plugin.
896e01d
    
896e01d
    Signed-off-by: Mark Wielaard <mark@klomp.org>
896e01d
896e01d
diff --git a/src/unstrip.c b/src/unstrip.c
896e01d
index 057efef..cb1f7dc 100644
896e01d
--- a/src/unstrip.c
896e01d
+++ b/src/unstrip.c
896e01d
@@ -563,7 +563,11 @@ adjust_all_relocs (Elf *elf, Elf_Scn *symtab, const GElf_Shdr *symshdr,
896e01d
 	GElf_Shdr shdr_mem;
896e01d
 	GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
896e01d
 	ELF_CHECK (shdr != NULL, _("cannot get section header: %s"));
896e01d
-	if (shdr->sh_type != SHT_NOBITS && shdr->sh_link == new_sh_link)
896e01d
+	/* Don't redo SHT_GROUP, groups are in both the stripped and debug,
896e01d
+	   it will already have been done by adjust_relocs for the
896e01d
+	   stripped_symtab.  */
896e01d
+	if (shdr->sh_type != SHT_NOBITS && shdr->sh_type != SHT_GROUP
896e01d
+	    && shdr->sh_link == new_sh_link)
896e01d
 	  adjust_relocs (scn, scn, shdr, map, symshdr);
896e01d
       }
896e01d
 }
153c7ba
commit 47092416243d54e4cff3cd2558ece8b93695d54e
153c7ba
Author: Mark Wielaard <mark@klomp.org>
153c7ba
Date:   Tue Jul 24 23:34:19 2018 +0200
153c7ba
153c7ba
    unstrip: Also check sh_size in compare_unalloc_sections.
153c7ba
    
153c7ba
    compare_unalloc_sections only checked sh_flags and the section names.
153c7ba
    This would cause stripped/debug section mismatches when there were
153c7ba
    multiple sections with the same name and flags. Fix this by also checking
153c7ba
    the size of the section matches.
153c7ba
    
153c7ba
    Add a testcase that has two ".group" sections created on i386 with the
153c7ba
    gcc annobin plugin.
153c7ba
    
153c7ba
    Signed-off-by: Mark Wielaard <mark@klomp.org>
153c7ba
153c7ba
diff --git a/src/unstrip.c b/src/unstrip.c
153c7ba
index cb1f7dc..ec46c95 100644
153c7ba
--- a/src/unstrip.c
153c7ba
+++ b/src/unstrip.c
153c7ba
@@ -709,6 +709,12 @@ compare_unalloc_sections (const GElf_Shdr *shdr1, const GElf_Shdr *shdr2,
153c7ba
   if (shdr1->sh_flags > shdr2->sh_flags)
153c7ba
     return 1;
153c7ba
 
153c7ba
+  /* Sizes should be the same.  */
153c7ba
+  if (shdr1->sh_size < shdr2->sh_size)
153c7ba
+    return -1;
153c7ba
+  if (shdr1->sh_size > shdr2->sh_size)
153c7ba
+    return 1;
153c7ba
+
153c7ba
   /* Sort by name as last resort.  */
153c7ba
   return strcmp (name1, name2);
153c7ba
 }