Extend elf-parse to be able to read the symbol table of vmlinux in
kallsyms.
This requires the ability to open ELF files in read-only mode, so provide
elf_map_ro() to do so.
It also requires accessors for section flags and symbol bindings, so
provide these via shdr_flags() and sym_bind().
It's useful to be able to open an ELF file, map it, and then have easy
access to its section headers, names and symbol table, so introduce struct
elf_file to store this.
In order to obtain this data also provide elf_open_ro() and elf_close().
Also, check for the file being an ELF file first in elf_parse(). This is
the logical thing to check for first, but additionally prevents kallsyms
from having to check this it self.
Assisted-by: LLM
Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Link: https://patch.msgid.link/20260923-build-speedup-v4-7-73128809a4a4@kernel.org
Signed-off-by: Nathan Chancellor <nathan@kernel.org>