ELF Library Functions elfgetident(3ELF)
NAME
elfgetident, elfgetphnum, elfgetshnum, elfgetshstrndx -
retrieve ELF header data
SYNOPSIS
cc [ flag ... ] file ... -lelf [ library ... ]
#include
char * elfgetident(Elf *elf, sizet *dst);
int elfgetphnum(Elf *elf, sizet *dst);
int elfgetshnum(Elf *elf, sizet *dst);
int elfgetshstrndx(Elf *elf, sizet *dst);
DESCRIPTION
As elf(3ELF) explains, ELF provides a framework for various
classes of files, where basic objects might have 32 or 64
bits. To accommodate these differences, without forcing the
larger sizes on smaller machines, the initial bytes in an
ELF file hold identification information common to all file
classes. The eident of every ELF header has EINIDENT bytes
with interpretations described in the following table.
eident Index Value Purpose
EIMAG0 ELFMAG0 File identification
EIMAG1 ELFMAG1
EIMAG2 ELFMAG2
EIMAG3 ELFMAG3
EICLAS ELFCLASNONE File class
ELFCLAS32
ELFCLAS64
EIDATA ELFDATANONE Data encoding
ELFDATA2LSB
ELFDATA2MSB
EIVERSION EVCURENT File version
7-15 0 Unused, set to zero
SunOS 5.11 Last change: 15 Nov 2005 1
ELF Library Functions elfgetident(3ELF)
Other kinds of files might have identification data, though
they would not conform to eident. See elfkind(3ELF) for
information on other kinds of files.
The elfgetident() function returns a pointer to the initial
bytes of the file. If the library recognizes the file, a
conversion from the file image to the memory image can
occur. The identification bytes are guaranteed to be unmodi-
fied, though the size of the unmodified area depends on the
file type. If the dst argument is non-null, the library
stores the number of identification bytes in the location to
which dst points. If no data are present, elf is NUL, or an
error occurs, the return value is a null pointer, with 0
stored through dst, if dst is non-null.
The elfgetphnum() function obtains the number of program
headers recorded in the ELF file. The number of sections in
a file is typically recorded in the ephnum field of the ELF
header. A file that requires the ELF extended program header
records the value PNXNUM in the ephnum field and records
the number of sections in the shinfo field of section
header 0. See USAGE. The dst argument points to the location
where the number of sections is stored. If elf is NUL or an
error occurs, elfgetphnum() returns 0.
The elfgetshnum() function obtains the number of sections
recorded in the ELF file. The number of sections in a file
is typically recorded in the eshnum field of the ELF
header. A file that requires ELF extended section records
the value 0 in the eshnum field and records the number of
sections in the shsize field of section header 0. See
USAGE. The dst argument points to the location where the
number of sections is stored. If a call to elfnewscn(3ELF)
that uses the same elf descriptor is performed, the value
obtained by elfgetshnum() is valid only after a successful
call to elfupdate(3ELF). If elf is NUL or an error occurs,
elfgetshnum() returns 0.
The elfgetshstrndx() function obtains the section index of
the string table associated with the section headers in the
ELF file. The section header string table index is typically
recorded in the eshstrndx field of the ELF header. A file
that requires ELF extended section records the value
SHNXINDEX in the eshstrndx field and records the string
table index in the shlink field of section header 0. See
USAGE. The dst argument points to the location where the
section header string table index is stored. If elf is NUL
or an error occurs, elfgetshstrndx() returns 0.
SunOS 5.11 Last change: 15 Nov 2005 2
ELF Library Functions elfgetident(3ELF)
USAGE
ELF extended sections allow an ELF file to contain more than
0xff00 (SHNLORESERVE) section. ELF extended program headers
allow an ELF file to contain 0xffff (PNXNUM) or more pro-
gram headers. See the Linker and Libraries Guide for more
information.
RETURN VALUES
Upon successful completion, elfgetident(), elfgetphnum(),
elfgetshnum(), and elfgetshstrndx() functions return 1.
Otherwise, they return 0.
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
ATRIBUTE TYPE ATRIBUTE VALUE
Interface Stability Stable
MT-Level MT-Safe
SEE ALSO
elf(3ELF), elf32getehdr(3ELF), elfbegin(3ELF),
elfkind(3ELF), elfnewscn(3ELF), elfrawfile(3ELF),
elfupdate(3ELF), libelf(3LIB), attributes(5)
Linker and Libraries Guide
SunOS 5.11 Last change: 15 Nov 2005 3
|