HP-UX Reference (11i v3 07/02) - 3 Library Functions A-M (vol 6)
e
elf(3E) elf(3E)
Programs may translate data explicitly, taking full control over the object file layout and semantics. If the
program prefers not to have and exercise complete control, the library provides a higher-level interface that
hides many object file details. elf_begin and related functions let a program deal with the native
memory types, converting between memory objects and their file equivalents automatically when reading
or writing an object file.
ELF Versions
Object file versions allow ELF to adapt to new requirements. Three-independent-versions can be important
to a program. First, an application program knows about a particular version by virtue of being compiled
with certain header files. Second, the access library similarly is compiled with header files that control
what versions it understands. Third, an ELF object file holds a value identifying its version, determined by
the ELF version known by the file’s creator. Ideally, all three versions would be the same, but they may
differ.
If a program’s version is newer than the access library, the program might use information unknown to the
library. Translation routines might not work properly, leading to undefined behavior. This condition mer-
its installing a new library.
The library’s version might be newer than the program’s and the file’s. The library understands old ver-
sions, thus avoiding compatibility problems in this case.
Finally, a file’s version might be newer than either the program or the library understands. The program
might or might not be able to process the file properly, depending on whether the file has extra information
and whether that information can be safely ignored. Again, the safe alternative is to install a new library
that understands the file’s version.
To accommodate these differences, a program must use
elf_version to pass its version to the library,
thus establishing the working version for the process. Using this, the library accepts data from and
presents data to the program in the proper representations. When the library reads object files, it uses
each file’s version to interpret the data. When writing files or converting memory types to the file
equivalents, the library uses the program’s working version for the file data.
System Services
As mentioned above, elf_begin and related routines provide a higher-level interface to ELF files, per-
forming input and output on behalf of the application program. These routines assume a program can hold
entire files in memory, without explicitly using temporary files. When reading a file, the library routines
bring the data into memory and perform subsequent operations on the memory copy. Programs that read
or write large object files with this model must execute on a machine with a large process virtual address
space. If the underlying operating system limits the number of open files, a program can use
elf_cntl
to retrieve all necessary data from the file, allowing the program to close the file descriptor and reuse it.
Although the elf_begin interfaces are convenient and efficient for many programs, they might be inap-
propriate for some. In those cases, an application may invoke the elf_xlate data translation routines
directly. These routines perform no input or output, leaving that as the application’s responsibility. By
assuming a larger share of the job, an application controls its input and output model.
Library Names
Names associated with the library take several forms.
elf_name These class-independent names perform some service, name, for the program.
elf32_name Service names with an embedded class, 32 here,indicate they work only for the
designated class of files.
elf64_name Service names with an embedded class, 64 here,indicate they work only for the
designated class of files.
Elf_Type Data types can be class-independent as well, distinguished by Type .
Elf32_Type Class-dependent data types have an embedded class name, 32 here.
Elf64_Type Class-dependent data types have an embedded class name, 64 here.
ELF_C_CMD Several functions take commands that control their actions. These values are
members of the Elf_Cmd enumeration; they range from zero through
ELF_C_NUM-1 .
ELF_F_FLAG Several functions take flags that control library status and/or actions. Flags are
bits that may be combined.
332 Hewlett-Packard Company − 2 − HP-UX 11i Version 3: February 2007