|ELF_UPDATE(3ELF)||ELF Library Functions||ELF_UPDATE(3ELF)|
elf_update - update an ELF descriptor
cc [ flag ... ] file ... -lelf [ library ... ] #include <libelf.h> off_t elf_update(Elf *elf, Elf_Cmd cmd);
The elf_update() function causes the library to examine the information associated with an ELF descriptor, elf, and to recalculate the structural data needed to generate the file's image.
The cmd argument can have the following values:
If elf_update() succeeds, it returns the total size of the file image (not the memory image), in bytes. Otherwise an error occurred, and the function returns −1.
When updating the internal structures, elf_update() sets some members itself. Members listed below are the application's responsibility and retain the values given by the program.
The following table shows ELF Header members:
|e_ident[EI_DATA]||Library controls other e_ident values|
|e_phoff||Only when ELF_F_LAYOUT asserted|
|e_shoff||Only when ELF_F_LAYOUT asserted|
The following table shows the Program Header members:
|p_type||The application controls all|
|p_offset||program header entries|
The following table shows the Section Header members:
|sh_offset||Only when ELF_F_LAYOUT asserted|
|sh_size||Only when ELF_F_LAYOUT asserted|
|sh_addralign||Only when ELF_F_LAYOUT asserted|
The following table shows the Data Descriptor members:
|d_off||Only when ELF_F_LAYOUT asserted|
Note that the program is responsible for two particularly important members (among others) in the ELF header. The e_version member controls the version of data structures written to the file. If the version is EV_NONE, the library uses its own internal version. The e_ident[EI_DATA] entry controls the data encoding used in the file. As a special case, the value may be ELFDATANONE to request the native data encoding for the host machine. An error occurs in this case if the native encoding doesn't match a file encoding known by the library.
Further note that the program is responsible for the sh_entsize section header member. Although the library sets it for sections with known types, it cannot reliably know the correct value for all sections. Consequently, the library relies on the program to provide the values for unknown section types. If the entry size is unknown or not applicable, the value should be set to 0.
When deciding how to build the output file, elf_update() obeys the alignments of individual data buffers to create output sections. A section's most strictly aligned data buffer controls the section's alignment. The library also inserts padding between buffers, as necessary, to ensure the proper alignment of each buffer.
See attributes(7) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|
As mentioned above, the ELF_C_WRITE command translates data as necessary, before writing them to the file. This translation is not always transparent to the application program. If a program has obtained pointers to data associated with a file (for example, see elf32_getehdr(3ELF) and elf_getdata(3ELF)), the program should reestablish the pointers after calling elf_update().
|July 11, 2001||OmniOS|