elf_getdata.3e (2010 09)

e
elf_getdata(3E) elf_getdata(3E)
NAME
elf_getdata, elf_newdata, elf_rawdata - get section data
SYNOPSIS
cc [flag... ] file...
-lelf [library ] ...
#include <libelf.h>
Elf_Data *elf_getdata(Elf_Scn *scn, Elf_Data *data);
Elf_Data *elf_newdata(Elf_Scn *scn);
Elf_Data *elf_rawdata(Elf_Scn *scn, Elf_Data *data);
DESCRIPTION
These functions access and manipulate the data associated with a section descriptor, scn. When reading
an existing file, a section will have a single data buffer associated with it. A program may build a new
section in pieces, however, composing the new data from multiple data buffers. For this reason, ‘‘the’’
data for a section should be viewed as a list of buffers, each of which is available through a data descrip-
tor.
elf_getdata lets a program step through a section’s data list. If the incoming data descriptor, data ,is
null, the function returns the first buffer associated with the section. Otherwise, data should be a data
descriptor associated with scn , and the function gives the program access to the next data element for the
section. If scn is null or an error occurs,
elf_getdata returns a null pointer.
elf_getdata translates the data from file representations into memory representations (see
elf_xlate (3E)) and presents objects with memory data types to the program, based on the file’s class (see
elf(3E)). The working library version (see elf_version (3E)) specifies what version of the memory struc-
tures the program wishes
elf_getdata to present.
elf_newdata creates a new data descriptor for a section, appending it to any data elements already
associated with the section. As described below, the new data descriptor appears empty, indicating the
element holds no data. For convenience, the descriptor’s type (
d_type below) is set to ELF_T_BYTE,
and the version (
d_version below) is set to the working version. The program is responsible for setting
(or changing) the descriptor members as needed. This function implicitly sets the ELF_F_DIRTY bit for
the section’s data (see elf_flag(3E)). If scn is null or an error occurs,
elf_newdata returns a null
pointer.
elf_rawdata differs from elf_getdata by returning only uninterpreted bytes, regardless of the sec-
tion type. This function typically should be used only to retrieve a section image from a file being read,
and then only when a program must avoid the automatic data translation described below. Moreover, a
program may not close or disable (see elf_cntl (3E)) the file descriptor associated with elf before the initial
raw operation, because
elf_rawdata might read the data from the file to ensure it doesnt interfere
with elf_getdata. See elf_rawfile(3E) for a related facility that applies to the entire file. When
elf_getdata provides the right translation, its use is recommended over elf_rawdata.Ifscn is null
or an error occurs, elf_rawdata returns a null pointer.
The
Elf_Data structure includes the following members.
Elf_Void *d_buf;
Elf_Type d_type;
Elf64_Xword d_size;
Elf64_Off d_off;
Elf64_Xword d_align;
unsigned d_version;
These members are available for direct manipulation by the program. Descriptions appear below.
d_buf A pointer to the data buffer resides here. A data element with no data has a null pointer.
d_type This member’s value specifies the type of the data to which d_buf points. A section’s
type determines how to interpret the section contents, as summarized below.
d_size This member holds the total size, in bytes, of the memory occupied by the data. This may
differ from the size as represented in the file. The size will be zero if no data exist. (See
the discussion of SHT_NOBITS below for more information.)
d_off This member gives the offset, within the section, at which the buffer resides. This offset
is relative to the file’s section, not the memory object’s.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)