Re: [PATCH] libelf: Fix some issues with ELF_C_RDWR_MMAP.

2018-09-13 Thread Mark Wielaard
On Wed, 2018-09-12 at 15:02 +0200, Mark Wielaard wrote: > When ELF_C_RDWR_MMAP is used libelf might have to write overlapping memory > when moving the section data or headers. Make sure to use memmove, not > memcpy. Also the size of the underlying file might have to change. That > means we will hav

Fix various issues with ELF files containing many sections

2018-09-13 Thread Mark Wielaard
Through an accident Fedora rawhide created various ELF files with thousands of sections. This showed various issues in libelf, libdw and some of the elfutils tools. When an ELF file has more than SHN_LORESERVE (0xff00, 65280) sections then the Ehdr e_shnum and e_shshstrndx fields are too small to h

[PATCH 05/10] libelf: Fix shnum and section zero handling.

2018-09-13 Thread Mark Wielaard
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

[PATCH 07/10] libdw: dwarf_begin_elf should use elf_getshdrstrndx to get section names.

2018-09-13 Thread Mark Wielaard
dwarf_begin_elf used the Ehdr e_shstrndx to get the shdr string table section. This does not work for ELF files with more than SHN_LORESERVE sections. Use elf_getshdrstrndx, and don't pass around the ehdr. Add a simple testcase that fails before the patch because dwarf_begin return an error. Sign

[PATCH 04/10] elfcmp: Get, check and shdrstrndx for section names.

2018-09-13 Thread Mark Wielaard
elfcmp would use the Ehdr e_shstrndx field to find the shdr string index table. Use elf_getshdrstrndx instead to be able to handle ELF files with more than SHN_LORESERVE sections. Signed-off-by: Mark Wielaard --- src/ChangeLog | 4 src/elfcmp.c | 20 ++-- 2 files changed,

[PATCH 02/10] backends: Use elf_getshdrstrndx to find .odp section in ppc64_init

2018-09-13 Thread Mark Wielaard
The .odp section is found by name. But ppc64_init used the e_shstrndx Ehdr field for that. This is wrong if the file contains more than SHN_LORESERVE sections. Use elf_getshdrstrndx instead to find the shstrtab section. Signed-off-by: Mark Wielaard --- backends/ChangeLog| 4 backends/pp

[PATCH 09/10] readelf: Use elf_getshdrnum in print_shdr and print_phdr.

2018-09-13 Thread Mark Wielaard
print_shdr didn't print the correct number of sections if there were more than SHN_LORESERVE sections. print_phdr wouldn't match up the (allocated) sections and segements if there were more than SHN_LORESERVE sections in the ELF file. Signed-off-by: Mark Wielaard --- src/ChangeLog | 5 + sr

[PATCH 08/10] strip,unstrip: Use and set shdrstrndx consistently.

2018-09-13 Thread Mark Wielaard
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

[PATCH 06/10] elflint: Use shnum and shstrndx instead of ehdr field directly.

2018-09-13 Thread Mark Wielaard
We already got the right shnum and shstrndx. But were still using e_shnum in one check for ELFCLASS64 (it was correct for ELFCLASS32). And when getting section names in check_symtab we still used e_shstrndx in two places. Signed-off-by: Mark Wielaard --- src/ChangeLog | 7 +++ src/elflint.c

[PATCH 10/10] libdwfl: Document core memory and remote memory ELF shdrs reading.

2018-09-13 Thread Mark Wielaard
There are two places, dwfl_segment_report_module and elf_from_remote_memory in libdwfl where we use the Ehdr e_shnum directly. Document why this is fine. Getting the shdrs in those two places is really just a nice bonus and if there are more than 0xff00 then it is unlikely we will get them all anyw

[PATCH 03/10] libebl: Use elf_getshdrstrndx in ebl_section_strip_p.

2018-09-13 Thread Mark Wielaard
The ebl_section_strip_p function used the Ehdr e_shstrndx field to get at the name of the (debug) sections. This is not correct if there are more than SHN_LORESERVE sections. Use elf_getshdrstrndx to get at the shstrtab section. And drop the Ehdr argument that isn't necessary anymore. Signed-off-b

[PATCH 01/10] backends: Always use elf_getshdrstrndx in check_special_symbol.

2018-09-13 Thread Mark Wielaard
The check_special_symbol backend functions used the Ehdr e_shstrndx field to get at the name of sections. This is not correct if there are more than SHN_LORESERVE sections. Always use elf_getshdrstrndx to get the shstrtab section. And drop the Ehdr argument that isn't necessary anymore. Signed-off