--- libelf/elf32_updatenull.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) Index: b/libelf/elf32_updatenull.c =================================================================== --- a/libelf/elf32_updatenull.c +++ b/libelf/elf32_updatenull.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -144,7 +145,7 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf return -1; /* At least the ELF header is there. */ - off_t size = elf_typesize (LIBELFBITS, ELF_T_EHDR, 1); + off_t size = elf_typesize (LIBELFBITS, ELF_T_EHDR, 1), old_size; /* Set the program header position. */ if (elf->state.ELFW(elf,LIBELFBITS).phdr == NULL @@ -166,9 +167,12 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf { /* The user is supposed to fill out e_phoff. Use it and e_phnum to determine the maximum extend. */ + old_size = size; size = MAX ((size_t) size, ehdr->e_phoff + elf_typesize (LIBELFBITS, ELF_T_PHDR, ehdr->e_phnum)); + fprintf(stderr, "e_phoff: old=%ld, new=%ld\n", (long) old_size, + (long) size); } else { @@ -176,8 +180,11 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf elf_typesize (LIBELFBITS, ELF_T_EHDR, 1), ehdr_flags); + old_size = size; /* We need no alignment here. */ size += elf_typesize (LIBELFBITS, ELF_T_PHDR, ehdr->e_phnum); + fprintf(stderr, "e_phnum: old=%ld, new=%ld\n", (long) old_size, + (long) size); } } @@ -334,9 +341,13 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf /* Even the sh_offset is only the "conceptual" possition in the file. So completely ignore NOBITS sections. */ if (shdr->sh_type != SHT_NOBITS) - size = MAX ((GElf_Word) size, - shdr->sh_offset + shdr->sh_size); - + { + old_size = size; + size = MAX ((GElf_Word) size, + shdr->sh_offset + shdr->sh_size); + fprintf(stderr, "sh_offset: old=%ld, new=%ld\n", + (long) old_size, (long) size); + } /* The alignment must be a power of two. This is a requirement from the ELF specification. Additionally we test for the alignment of the section being large @@ -355,7 +366,11 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf update_if_changed (shdr->sh_addralign, sh_align, scn->shdr_flags); + old_size = size; size = (size + sh_align - 1) & ~(sh_align - 1); + fprintf(stderr, "sh_align: old=%ld, new=%ld\n", + (long) old_size, (long) size); + int offset_changed = 0; update_if_changed (shdr->sh_offset, (GElf_Word) size, offset_changed); @@ -373,8 +388,11 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf update_if_changed (shdr->sh_size, (GElf_Word) offset, changed); + old_size = size; if (shdr->sh_type != SHT_NOBITS) size += offset; + fprintf(stderr, "sh_size: old=%ld, new=%ld\n", + (long) old_size, (long) size); scn->flags |= changed; } @@ -401,9 +419,12 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf { /* The user is supposed to fill out e_phoff. Use it and e_phnum to determine the maximum extend. */ + old_size = size; size = MAX ((GElf_Word) size, (ehdr->e_shoff + (elf_typesize (LIBELFBITS, ELF_T_SHDR, shnum)))); + fprintf(stderr, "e_shoff: old=%ld, new=%ld\n", (long) old_size, + (long) size); } else { @@ -413,7 +434,10 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf want to be surprised by architectures with less strict alignment rules. */ #define SHDR_ALIGN sizeof (ElfW2(LIBELFBITS,Off)) + old_size = size; size = (size + SHDR_ALIGN - 1) & ~(SHDR_ALIGN - 1); + fprintf(stderr, "e_shoff(align): old=%ld, new=%ld\n", + (long) old_size, (long) size); update_if_changed (ehdr->e_shoff, (GElf_Word) size, elf->flags); update_if_changed (ehdr->e_shentsize, @@ -421,7 +445,10 @@ __elfw2(LIBELFBITS,updatenull) (Elf *elf ehdr_flags); /* Account for the section header size. */ + old_size = size; size += elf_typesize (LIBELFBITS, ELF_T_SHDR, shnum); + fprintf(stderr, "shnum: old=%ld, new=%ld\n", (long) old_size, + (long) size); } }