libelf: Fix shnum and section zero handling.
authorMark Wielaard <mark@klomp.org>
Wed, 12 Sep 2018 21:38:28 +0000 (23:38 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 13 Sep 2018 12:30:30 +0000 (14:30 +0200)
commit34534cc1740b198b8999dcf97222940a130905ce
treeef28e793954155f6a5de14e4e49b0dd30b3c8226
parentbe4ea50a689dcfdb46079f8f5ce616107a77cdc4
libelf: Fix shnum and section zero handling.

For ELF files with more than SHN_LOWRESERVE sections we always need
section zero to store the section number (it doesn't just fit in the
Ehdr e_shnum field). Make sure to create it if it doesn't exist yet
in elf_getscn. Also fix handling on shnum in updatefile for the mmap
case (we already got this correct for the non-mmap case).

This adds a new test run-copymany-sections.sh which is like
run-copyadd-sections.sh but tries to add two times 65535 sections.
It makes sure libelf can copy the whole file and elfcmp checks they
are the same. It doesn't use mmap for addsections since that doesn't
work yet. ELF_C_RDWR_MMAP needs mremap which will fail since it needs
too much space and the original mmap cannot move.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/elf32_updatefile.c
libelf/elf_getscn.c
tests/ChangeLog
tests/Makefile.am
tests/run-copymany-sections.sh [new file with mode: 0755]