From: Roland McGrath Date: Fri, 4 Jun 2010 09:29:08 +0000 (-0700) Subject: unstrip: Factor common code for shdr changes. X-Git-Tag: elfutils-0.148~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa32f9237f6ce0c25cbe53291467c305b6481abb;p=thirdparty%2Felfutils.git unstrip: Factor common code for shdr changes. --- diff --git a/src/ChangeLog b/src/ChangeLog index 90c78cb5d..ab33cbf20 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2010-06-04 Roland McGrath + * unstrip.c (update_shdr): New function. + (update_sh_size): Call it instead of gelf_update_shdr. + (adjust_relocs, add_new_section_symbols): Likewise. + (new_shstrtab, copy_elided_sections): Likewise. + * unstrip.c (copy_elided_sections): Bail if stripped file has more sections than unstripped file, rather than getting confused later. diff --git a/src/unstrip.c b/src/unstrip.c index 755c42a32..59d3ead57 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -368,6 +368,13 @@ symtab_count_leading_section_symbols (Elf *elf, Elf_Scn *scn, size_t shnum, return shnum; } +static void +update_shdr (Elf_Scn *outscn, GElf_Shdr *newshdr) +{ + ELF_CHECK (gelf_update_shdr (outscn, newshdr), + _("cannot update section header: %s")); +} + /* We expanded the output section, so update its header. */ static void update_sh_size (Elf_Scn *outscn, const Elf_Data *data) @@ -378,8 +385,7 @@ update_sh_size (Elf_Scn *outscn, const Elf_Data *data) newshdr->sh_size = data->d_size; - ELF_CHECK (gelf_update_shdr (outscn, newshdr), - _("cannot update section header: %s")); + update_shdr (outscn, newshdr); } /* Update relocation sections using the symbol table. */ @@ -428,8 +434,7 @@ adjust_relocs (Elf_Scn *outscn, Elf_Scn *inscn, const GElf_Shdr *shdr, if (newshdr->sh_info != STN_UNDEF) { newshdr->sh_info = map[newshdr->sh_info - 1]; - ELF_CHECK (gelf_update_shdr (outscn, newshdr), - _("cannot update section header: %s")); + update_shdr (outscn, newshdr); } break; } @@ -557,9 +562,7 @@ add_new_section_symbols (Elf_Scn *old_symscn, size_t old_shnum, shdr->sh_info += added; shdr->sh_size += added * shdr->sh_entsize; - - ELF_CHECK (gelf_update_shdr (symscn, shdr), - _("cannot update section header: %s")); + update_shdr (symscn, shdr); Elf_Data *symdata = elf_getdata (symscn, NULL); Elf_Data *shndxdata = NULL; /* XXX */ @@ -1205,8 +1208,7 @@ new_shstrtab (Elf *unstripped, size_t unstripped_shnum, shdr->sh_name = ebl_strtaboffset (unstripped_strent[i]); if (i + 1 == unstripped_shstrndx) shdr->sh_size = strtab_data->d_size; - ELF_CHECK (gelf_update_shdr (scn, shdr), - _("cannot update section header: %s")); + update_shdr (scn, shdr); } return strtab_data; @@ -1525,8 +1527,7 @@ more sections in stripped file than debug file -- arguments reversed?")); offset = end_offset; } - ELF_CHECK (gelf_update_shdr (sec->outscn, &shdr_mem), - _("cannot update section header: %s")); + update_shdr (sec->outscn, &shdr_mem); if (shdr_mem.sh_type == SHT_SYMTAB || shdr_mem.sh_type == SHT_DYNSYM) { @@ -1720,8 +1721,7 @@ more sections in stripped file than debug file -- arguments reversed?")); } elf_flagdata (symdata, ELF_C_SET, ELF_F_DIRTY); - ELF_CHECK (gelf_update_shdr (unstripped_symtab, shdr), - _("cannot update section header: %s")); + update_shdr (unstripped_symtab, shdr); if (stripped_symtab != NULL) { @@ -1791,8 +1791,7 @@ more sections in stripped file than debug file -- arguments reversed?")); if (shdr->sh_type != SHT_NOBITS) offset += shdr->sh_size; - ELF_CHECK (gelf_update_shdr (scn, shdr), - _("cannot update section header: %s")); + update_shdr (scn, shdr); if (unstripped_shstrndx == 1 + i) {