From: Ulrich Drepper Date: Thu, 22 Jan 2009 01:03:31 +0000 (-0800) Subject: Cleanup of loop to write out section content. X-Git-Tag: elfutils-0.139~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23fba7582ad1e9f383dc0519635ac1bfe2acba48;p=thirdparty%2Felfutils.git Cleanup of loop to write out section content. --- diff --git a/libelf/ChangeLog b/libelf/ChangeLog index be259e620..2f8ff2be6 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,5 +1,9 @@ 2009-01-21 Ulrich Drepper + * elf32_updatefile.c (elfXX_updatemmap): Skip most of the loop to + handle sections for NOBITS sections. + (elfXX_updatefile): Likewise. + * elf32_updatefile.c (elfXX_updatemmap): When skipping non-NOBITS sections we haven't loaded, update last_position based on scn_start, not based on old value. Don't run the loop for the dummy section 0. diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c index 111e1d2bb..f23035a52 100644 --- a/libelf/elf32_updatefile.c +++ b/libelf/elf32_updatefile.c @@ -292,12 +292,14 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) } ElfW2(LIBELFBITS,Shdr) *shdr = scn->shdr.ELFW(e,LIBELFBITS); + if (shdr->sh_type == SHT_NOBITS) + goto next; char *scn_start = ((char *) elf->map_address + elf->start_offset + shdr->sh_offset); Elf_Data_List *dl = &scn->data_list; - if (shdr->sh_type != SHT_NOBITS && scn->data_list_rear != NULL) + if (scn->data_list_rear != NULL) do { assert (dl->data.d.d_off >= 0); @@ -369,10 +371,11 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) dl = dl->next; } while (dl != NULL); - else if (shdr->sh_type != SHT_NOBITS) + else /* We have to trust the existing section header information. */ last_position = scn_start + shdr->sh_size; + next: scn->flags &= ~ELF_F_DIRTY; } @@ -632,12 +635,13 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) } ElfW2(LIBELFBITS,Shdr) *shdr = scn->shdr.ELFW(e,LIBELFBITS); + if (shdr->sh_type == SHT_NOBITS) + goto next; off_t scn_start = elf->start_offset + shdr->sh_offset; Elf_Data_List *dl = &scn->data_list; - if (shdr->sh_type != SHT_NOBITS && scn->data_list_rear != NULL - && scn->index != 0) + if (scn->data_list_rear != NULL) do { if ((scn->flags | dl->flags | elf->flags) & ELF_F_DIRTY) @@ -709,9 +713,10 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) dl = dl->next; } while (dl != NULL); - else if (shdr->sh_type != SHT_NOBITS) + else last_offset = scn_start + shdr->sh_size; + next: /* Collect the section header table information. */ if (unlikely (change_bo)) (*shdr_fctp) (&shdr_data[scn->index],