diff options
| author | Mark Wielaard <[email protected]> | 2018-08-04 20:29:25 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2018-09-14 00:43:27 +0200 |
| commit | d5b050281e43754ac444e39d3e392831f4488c59 (patch) | |
| tree | 709e05fa8f0c15ae8b383ef51ec477f1d0898aa5 /src/unstrip.c | |
| parent | b14633d41673bb1903c887cb9ffd55fe700c4eb1 (diff) | |
strip,unstrip: Use and set shdrstrndx consistently.
In various places in strip we used e_shstrndx instead of shdrstrndx and we
didn't setup the shdrstrndx for the debug file. In unstrip we forgot to copy
the shdrstrndx in case the -o output option was used.
Added a new testcase that adds many sections to a testfile and runs strip, elflint,
unstrip and elfcmp.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'src/unstrip.c')
| -rw-r--r-- | src/unstrip.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/unstrip.c b/src/unstrip.c index ec46c952..e6f09478 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -239,8 +239,27 @@ copy_elf (Elf *outelf, Elf *inelf) ELF_CHECK (gelf_newehdr (outelf, gelf_getclass (inelf)), _("cannot create ELF header: %s")); + size_t shstrndx; + ELF_CHECK (elf_getshdrstrndx (inelf, &shstrndx) == 0, + _("cannot get shdrstrndx:%s")); + GElf_Ehdr ehdr_mem; GElf_Ehdr *ehdr = gelf_getehdr (inelf, &ehdr_mem); + if (shstrndx < SHN_LORESERVE) + ehdr->e_shstrndx = shstrndx; + else + { + ehdr->e_shstrndx = SHN_XINDEX; + Elf_Scn *scn0 = elf_getscn (outelf, 0); + GElf_Shdr shdr0_mem; + GElf_Shdr *shdr0 = gelf_getshdr (scn0, &shdr0_mem); + ELF_CHECK (shdr0 != NULL, + _("cannot get new zero section: %s")); + shdr0->sh_link = shstrndx; + ELF_CHECK (gelf_update_shdr (scn0, shdr0), + _("cannot update new zero section: %s")); + } + ELF_CHECK (gelf_update_ehdr (outelf, ehdr), _("cannot copy ELF header: %s")); @@ -1025,7 +1044,7 @@ find_alloc_sections_prelink (Elf *debug, Elf_Data *debug_shstrtab, _("cannot read '.gnu.prelink_undo' section: %s")); uint_fast16_t phnum; - uint_fast16_t shnum; + uint_fast16_t shnum; /* prelink doesn't handle > SHN_LORESERVE. */ if (ehdr.e32.e_ident[EI_CLASS] == ELFCLASS32) { phnum = ehdr.e32.e_phnum; |
