2 .\" Copyright 1989 AT&T Copyright (c) 1996, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH ELF_UPDATE 3ELF "Jul 11, 2001"
8 elf_update \- update an ELF descriptor
12 cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ]
15 \fBoff_t\fR \fBelf_update\fR(\fBElf *\fR\fIelf\fR, \fBElf_Cmd\fR \fIcmd\fR);
21 The \fBelf_update()\fR function causes the library to examine the information
22 associated with an \fBELF\fR descriptor, \fIelf\fR, and to recalculate the
23 structural data needed to generate the file's image.
26 The \fIcmd\fR argument can have the following values:
30 \fB\fBELF_C_NULL\fR\fR
33 This value tells \fBelf_update()\fR to recalculate various values, updating
34 only the \fBELF\fR descriptor's memory structures. Any modified structures are
35 flagged with the \fBELF_F_DIRTY\fR bit. A program thus can update the
36 structural information and then reexamine them without changing the file
37 associated with the \fBELF\fR descriptor. Because this does not change the
38 file, the \fBELF\fR descriptor may allow reading, writing, or both reading and
39 writing (see \fBelf_begin\fR(3ELF)).
45 \fB\fBELF_C_WRITE\fR\fR
48 If \fIcmd\fR has this value, \fBelf_update()\fR duplicates its \fBELF_C_NULL\fR
49 actions and also writes any ``dirty'' information associated with the \fBELF\fR
50 descriptor to the file. That is, when a program has used
51 \fBelf_getdata\fR(3ELF) or the \fBelf_flagdata\fR(3ELF) facilities to supply
52 new (or update existing) information for an \fBELF\fR descriptor, those data
53 will be examined, coordinated, translated if necessary (see
54 \fBelf32_xlatetof\fR(3ELF)), and written to the file. When portions of the file
55 are written, any \fBELF_F_DIRTY\fR bits are reset, indicating those items no
56 longer need to be written to the file (see \fBelf_flagdata\fR(3ELF)). The
57 sections' data are written in the order of their section header entries, and
58 the section header table is written to the end of the file. When the \fBELF\fR
59 descriptor was created with \fBelf_begin()\fR, it must have allowed writing the
60 file. That is, the \fBelf_begin()\fR command must have been either
61 \fBELF_C_RDWR\fR or \fBELF_C_WRITE\fR.
66 If \fBelf_update()\fR succeeds, it returns the total size of the file image
67 (not the memory image), in bytes. Otherwise an error occurred, and the function
68 returns \fB\(mi1\fR\&.
71 When updating the internal structures, \fBelf_update()\fR sets some members
72 itself. Members listed below are the application's responsibility and retain
73 the values given by the program.
76 The following table shows ELF Header members:
85 e_ident[EI_DATA] Library controls other \fBe_ident\fR values
90 e_phoff Only when \fBELF_F_LAYOUT\fR asserted
91 e_shoff Only when \fBELF_F_LAYOUT\fR asserted
98 The following table shows the Program Header members:
107 p_type The application controls all
108 p_offset program header entries
119 The following table shows the Section Header members:
132 sh_offset Only when \fBELF_F_LAYOUT\fR asserted
133 sh_size Only when \fBELF_F_LAYOUT\fR asserted
136 sh_addralign Only when \fBELF_F_LAYOUT\fR asserted
142 The following table shows the Data Descriptor members:
154 d_off Only when \fBELF_F_LAYOUT\fR asserted
161 Note that the program is responsible for two particularly important members
162 (among others) in the \fBELF\fR header. The \fBe_version\fR member controls the
163 version of data structures written to the file. If the version is
164 \fBEV_NONE\fR, the library uses its own internal version. The
165 \fBe_ident[EI_DATA]\fR entry controls the data encoding used in the file. As a
166 special case, the value may be \fBELFDATANONE\fR to request the native data
167 encoding for the host machine. An error occurs in this case if the native
168 encoding doesn't match a file encoding known by the library.
171 Further note that the program is responsible for the \fBsh_entsize\fR section
172 header member. Although the library sets it for sections with known types, it
173 cannot reliably know the correct value for all sections. Consequently, the
174 library relies on the program to provide the values for unknown section types.
175 If the entry size is unknown or not applicable, the value should be set to
179 When deciding how to build the output file, \fBelf_update()\fR obeys the
180 alignments of individual data buffers to create output sections. A section's
181 most strictly aligned data buffer controls the section's alignment. The library
182 also inserts padding between buffers, as necessary, to ensure the proper
183 alignment of each buffer.
187 See \fBattributes\fR(5) for descriptions of the following attributes:
195 ATTRIBUTE TYPE ATTRIBUTE VALUE
197 Interface Stability Stable
205 \fBelf\fR(3ELF), \fBelf32_fsize\fR(3ELF), \fBelf32_getehdr\fR(3ELF),
206 \fBelf32_getshdr\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), \fBelf_begin\fR(3ELF),
207 \fBelf_flagdata\fR(3ELF), \fBelf_getdata\fR(3ELF), \fBlibelf\fR(3LIB),
212 As mentioned above, the \fBELF_C_WRITE\fR command translates data as necessary,
213 before writing them to the file. This translation is \fInot\fR always
214 transparent to the application program. If a program has obtained pointers to
215 data associated with a file (for example, see \fBelf32_getehdr\fR(3ELF) and
216 \fBelf_getdata\fR(3ELF)), the program should reestablish the pointers after
217 calling \fBelf_update()\fR.