libdwfl: Make dwfl_report_offline_memory work with ELF_C_READ_MMAP
elf_memory open mode recently changed from ELF_C_READ to
ELF_C_READ_MMAP. This broken dwfl_report_offline_memory that changes
mode to ELF_C_READ_MMAP_PRIVATE to be compatible with subsequent
elf_begin on embedded ELF files.
The proper implementation of dwfl_report_offline_memory doesn't change
open mode and subsequent elf_begin invocations simply use cmd from the
reference Elf*.
Add tests to exercise Elf* to trigger the bug caused by incorrect cmd
set to Elf*.
* libdwfl/offline.c (process_archive): Use archive->cmd
instead of hardcoded ELF_C_READ_MMAP_PRIVATE.
* libdwfl/open.c (libdw_open_elf): Use elf->cmd instead of
hardcoded ELF_C_READ_MMAP_PRIVATE.
(__libdw_open_elf_memory): Don't override (*elfp)->cmd.
* tests/Makefile.am (dwfl_report_offline_memory): Add libelf
as dependency.
* tests/dwfl-report-offline-memory.c: Add count_sections to
exercise Elf* from dwfl_report_offline_memory.
* tests/run-dwfl-report-offline-memory.sh: Add expected number
of sections to test invocations.