1 .\" Copyright (c) 2006-2008 Joseph Koshy. All rights reserved.
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\" notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\" notice, this list of conditions and the following disclaimer in the
10 .\" documentation and/or other materials provided with the distribution.
12 .\" This software is provided by Joseph Koshy ``as is'' and
13 .\" any express or implied warranties, including, but not limited to, the
14 .\" implied warranties of merchantability and fitness for a particular purpose
15 .\" are disclaimed. in no event shall Joseph Koshy be liable
16 .\" for any direct, indirect, incidental, special, exemplary, or consequential
17 .\" damages (including, but not limited to, procurement of substitute goods
18 .\" or services; loss of use, data, or profits; or business interruption)
19 .\" however caused and on any theory of liability, whether in contract, strict
20 .\" liability, or tort (including negligence or otherwise) arising in any way
21 .\" out of the use of this software, even if advised of the possibility of
31 .Nd update an ELF descriptor
37 .Fn elf_update "Elf *elf" "Elf_Cmd cmd"
41 causes the library to recalculate the structure of an ELF
42 object and optionally write out the image of the object
47 is a descriptor to an ELF object.
50 can take on the following values:
51 .Bl -tag -width "ELF_C_WRITE"
53 The library will recalculate structural information flagging
54 modified structures with the
56 flag, but will not write back data to the underlying file image.
58 The library will recalculate structural information and will
59 also write the new image to the underlying file.
64 flag has been set on the ELF descriptor, the application assumes full
65 responsibility for the layout of the ELF object.
66 If this flag is not set, the ELF library will compute the layout of the
67 file from its associated section descriptors.
69 It is the application's responsibility to manage the the following
70 structure members in the ELF file:
71 .Bl -tag -width indent
72 .It "Executable Header"
73 The ELF executable header is described in
75 The following members of the ELF executable header are the application's
78 .Bl -tag -width "e_ident[EI_OSABI]" -compact
80 Set to the desired entry address for executables.
82 Set to the desired processor specific flags.
83 .It Va "e_ident[EI_DATA]"
88 .It Va "e_ident[EI_OSABI]"
89 Set to the OS ABI desired.
92 executables, this field should be set to
93 .Dv ELFOSABI_FREEBSD .
95 Set to the desired machine architecture, one of the
98 .In sys/elf_common.h .
100 If the application is managing the object's layout, it must
101 set this field to the file offset of the ELF program header table.
103 If the application is managing the object's layout, it must
104 set this field to the file offset of the ELF section header table.
106 Set to the index of the string table containing
109 Set to the type of the ELF object, one of the
112 .In sys/elf_common.h .
114 Set to the desired version of the ELF object.
117 All fields of the entries in the program header table are
118 under application control.
120 The ELF section header is described in
122 The following members of the ELF section header are the
123 application's responsibility:
125 .Bl -tag -width "sh_addralign" -compact
127 Set to the physical memory address where the section should reside.
129 If the application is managing the file layout, it must set this
130 field to the desired alignment for the section's contents.
131 This value must be a power of two.
133 Set to the size of each entry, for sections containing fixed size
134 elements, or set to zero for sections without fixed size elements.
135 If the application is not managing file layout, it may leave this
136 field as zero for those sections whose types are known to the library.
138 Set to the desired section flags.
146 Set to the index of the section's name in the string table containing
149 If the application is managing the file layout, it must set this
150 field to the file offset of the section's contents.
152 If the application is managing the file layout, it must set this
153 field to the file size of the section's contents.
155 Set to the type of the section.
159 Gaps in the coverage of the file's contents will be set to the fill value
163 If the application has requested full control over the file's layout by
166 flag on the ELF descriptor, it should ensure that there are no
167 gaps in the coverage of the file's contents.
173 descriptors associated with descriptor
175 should be considered as invalid after a call to
180 returns the total size of the file image if successful, or -1 if an
183 This function may fail with the following errors:
184 .Bl -tag -width "[ELF_E_RESOURCE]"
185 .It Bq Er ELF_E_ARGUMENT
189 .It Bq Er ELF_E_ARGUMENT
193 .It Bq Er ELF_E_ARGUMENT
196 was not a descriptor for an ELF object.
197 .It Bq Er ELF_E_CLASS
199 .Va e_ident[EI_CLASS]
200 field of the executable header of argument
202 did not match the class of the file.
206 descriptor contained in argument
208 specified a type incompatible with its containing section.
209 .It Bq Er ELF_E_HEADER
210 The ELF header in argument
212 requested a different byte order from the byte order already
213 associated with the file.
215 An I/O error was encountered.
216 .It Bq Er ELF_E_LAYOUT
219 descriptor contained in argument
221 specified an alignment incompatible with its containing section.
222 .It Bq Er ELF_E_LAYOUT
225 contained section descriptors that overlapped in extent.
226 .It Bq Er ELF_E_LAYOUT
229 contained section descriptors that were incorrectly aligned or were
230 too small for their data.
231 .It Bq Er ELF_E_LAYOUT
234 was set on the Elf descriptor and the section header table overlapped
235 an extent in the object mapped by a section descriptor.
239 operation was requested with an ELF descriptor that was not opened for
241 .It Bq Er ELF_E_SECTION
244 contained a section with an unrecognized type.
245 .It Bq Er ELF_E_SECTION
246 The section header at index
248 had an illegal section type.
249 .It Bq Er ELF_E_SEQUENCE
252 operation was requested after a prior call to
253 .Fn elf_cntl elf ELF_C_FDDONE
254 disassociated the ELF descriptor
256 from its underlying file.
257 .It Bq Er ELF_E_VERSION
260 had an unsupported version or contained an
262 descriptor with an unsupported version.
266 .Xr elf32_getehdr 3 ,
267 .Xr elf32_getphdr 3 ,
268 .Xr elf32_newehdr 3 ,
269 .Xr elf32_newphdr 3 ,
270 .Xr elf64_getehdr 3 ,
271 .Xr elf64_getphdr 3 ,
272 .Xr elf64_newehdr 3 ,
273 .Xr elf64_newphdr 3 ,