Retrieve class-dependent section header
cc [flag...]
file... -lelf
[library]...
#include <libelf.h>
Elf32_Shdr *elf32_getshdr(elf_Scn * scn);
Elf64_Shdr *elf64_getshdr(Elf * elf);
For a 32-bit class file, elf32_getshdr returns a pointer to a section header for the section descriptor scn. Otherwise, the file is not a 32-bit class file, scn was null, or an error occurred; elf32_getshdr then returns NULL.
The header includes the following members:
Elf32_Word sh_name; Elf32_Word sh_type; Elf32_Word sh_flags; Elf32_Addr sh_addr; Elf32_Off sh_offset; Elf32_Word sh_size; Elf32_Word sh_link; Elf32_Word sh_info; Elf32_Word sh_addralign; Elf32_Word sh_entsize;
elf64_getshdr provides the same functionality for 64-bit class files using the section descriptor elf. The header includes the following members:
Elf64_Word sh_name; Elf64_Word sh_type; Elf64_Word sh_flags; Elf64_Addr sh_addr; Elf64_Off sh_offset; Elf64_Xword sh_size; Elf64_Word sh_link; Elf64_Word sh_info; Elf64_Xword sh_addralign; Elf64_Xword sh_entsize;
If the program is building a new file, it is responsible for creating the file's ELF header before creating sections.
The elf_flagdata (elf_flagdata, elf_flagehdr, elf_flagelf, elf_flagphdr, elf_flagscn, elf_flagshdr Subroutine) subroutine, elf_getscn (elf_getscn, elf_ndxscn, elf_newscn, elf_nextscn Subroutine) subroutine, elf_strptr (elf_strptr Subroutine) subroutine.
Introduction to ELF Subroutines.