Content-type: text/html Man page of elf_getident

elf_getident

Section: ELF Library Functions (3ELF)
Updated: 20 Jun 2002
Index Return to Main Contents
 

NAME

elf_getident, elf_getshnum, elf_getshstrndx - retrieve ELF header data  

SYNOPSIS

cc [ flag ... ] file ... -lelf [ library ... ]
#include <libelf.h>

char * elf_getident(Elf *elf, size_t *dst);

int elf_getshnum(Elf *elf, size_t *dst);

int elf_getshstrndx(Elf *elf, size_t *dst);  

DESCRIPTION

As elf(3ELF) explains, ELF provides a framework for various classes of files, where basic objects may have 32 bits, 64 bits, etc. 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. Every ELF header's e_ident has EI_NIDENT bytes with the following interpretation:

e_ident IndexValuePurpose

EI_MAG0ELFMAG0File identification
EI_MAG1ELFMAG1
EI_MAG2ELFMAG2
EI_MAG3ELFMAG3

EI_CLASSELFCLASSNONEFile class
ELFCLASS32
ELFCLASS64

EI_DATAELFDATANONEData encoding
ELFDATA2LSB
ELFDATA2MSB

EI_VERSIONEV_CURRENTFile version

7-150Unused, set to zero

Other kinds of files (see elf_kind(3ELF)) also may have identification data, though they would not conform to e_ident.

elf_getident() returns a pointer to the file's ``initial bytes.'' If the library recognizes the file, a conversion from the file image to the memory image may occur. In any case, the identification bytes are guaranteed not to have been modified, though the size of the unmodified area depends on the file type. If dst 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 null, or an error occurs, the return value is a null pointer, with 0 stored through dst, if dst is non-null.

The elf_getshnum() function obtains the number of sections recorded in the ELF file. The number of sections in a file is typically recorded in the e_shnum field of the ELF header, though a file that requires ELF Extended Sections records the value 0 in the e_shnum field and records the number of sections in the sh_size field of section header 0. See USAGE. dst points to the location where the number of sections will be stored. If a call to elf_newscn(3ELF) using the same elf descriptor has been performed, then the value obtained by elf_getshnum() is only valid after a successful call to elf_update(3ELF). If elf is NULL or an error occurs, elf_getshnum() returns -1.

The elf_getshstrndx() 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 e_shstrndx field of the ELF header, though a file that requires ELF Extended Sections records the value SHN_XINDEX in the e_shstrndx field and records the string table index in the sh_link 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 NULL or an error occurs, elf_getshstrndx() returns -1.  

USAGE

ELF Extended Sections are employed to allow an ELF file to contain more than 0xff00 (SHN_LORESERVE) section. See the Linker and Libraries Guide for more information.  

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPEATTRIBUTE VALUE
Interface StabilityStable
MT-LevelMT-Safe

 

SEE ALSO

elf(3ELF), elf32_getehdr(3ELF), elf_begin(3ELF), elf_kind(3ELF), elf_newscn(3ELF), elf_rawfile(3ELF), elf_update(3ELF), libelf(3LIB), attributes(5)

Linker and Libraries Guide


 

Index

NAME
SYNOPSIS
DESCRIPTION
USAGE
ATTRIBUTES
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 02:39:35 GMT, October 02, 2010