3 .\" Copyright (c) 2006,2007-2008 Joseph Koshy. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" This software is provided by Joseph Koshy ``as is'' and
15 .\" any express or implied warranties, including, but not limited to, the
16 .\" implied warranties of merchantability and fitness for a particular purpose
17 .\" are disclaimed. in no event shall Joseph Koshy be liable
18 .\" for any direct, indirect, incidental, special, exemplary, or consequential
19 .\" damages (including, but not limited to, procurement of substitute goods
20 .\" or services; loss of use, data, or profits; or business interruption)
21 .\" however caused and on any theory of liability, whether in contract, strict
22 .\" liability, or tort (including negligence or otherwise) arising in any way
23 .\" out of the use of this software, even if advised of the possibility of
26 .\" $FreeBSD: src/lib/libelf/elf_update.3,v 1.6.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $
33 .Nd update an ELF descriptor
39 .Fn elf_update "Elf *elf" "Elf_Cmd cmd"
43 causes the library to recalculate the structure of an ELF
44 object and optionally write out the image of the object
49 is a descriptor to an ELF object.
52 can take on the following values:
53 .Bl -tag -width "ELF_C_WRITE"
55 The library will recalculate structural information flagging
56 modified structures with the
58 flag, but will not write back data to the underlying file image.
60 The library will recalculate structural information and will
61 also write the new image to the underlying file.
66 flag has been set on the ELF descriptor, the application assumes full
67 responsibility for the layout of the ELF object.
68 If this flag is not set, the ELF library will compute the layout of the
69 file from its associated section descriptors.
71 It is the application's responsibility to manage the the following
72 structure members in the ELF file:
73 .Bl -tag -width indent
74 .It "Executable Header"
75 The ELF executable header is described in
77 The following members of the ELF executable header are the application's
80 .Bl -tag -width "e_ident[EI_OSABI]" -compact
82 Set to the desired entry address for executables.
84 Set to the desired processor specific flags.
85 .It Va "e_ident[EI_DATA]"
90 .It Va "e_ident[EI_OSABI]"
91 Set to the OS ABI desired.
94 executables, this field should be set to
95 .Dv ELFOSABI_FREEBSD .
97 Set to the desired machine architecture, one of the
100 .In sys/elf_common.h .
102 If the application is managing the object's layout, it must
103 set this field to the file offset of the ELF program header table.
105 If the application is managing the object's layout, it must
106 set this field to the file offset of the ELF section header table.
108 Set to the index of the string table containing
111 Set to the type of the ELF object, one of the
114 .In sys/elf_common.h .
116 Set to the desired version of the ELF object.
119 All fields of the entries in the program header table are
120 under application control.
122 The ELF section header is described in
124 The following members of the ELF section header are the
125 application's responsibility:
127 .Bl -tag -width "sh_addralign" -compact
129 Set to the physical memory address where the section should reside.
131 If the application is managing the file layout, it must set this
132 field to the desired alignment for the section's contents.
133 This value must be a power of two.
135 Set to the size of each entry, for sections containing fixed size
136 elements, or set to zero for sections without fixed size elements.
137 If the application is not managing file layout, it may leave this
138 field as zero for those sections whose types known to the library.
140 Set to the desired section flags.
148 Set to the index of the section's name in the string table containing
151 If the application is managing the file layout, it must set this
152 field to the file offset of the section's contents.
154 If the application is managing the file layout, it must set this
155 field to the file size of the section's contents.
157 Set to the type of the section.
161 Gaps in the coverage of the file's contents will be set to the fill value
165 If the application has requested full control over the file's layout by
168 flag on the ELF descriptor, it should ensure that there are no
169 gaps in the coverage of the file's contents.
175 descriptors associated with descriptor
177 should be considered as invalid after a call to
182 returns the total size of the file image if successful, or -1 if an
185 This function may fail with the following errors:
186 .Bl -tag -width "[ELF_E_RESOURCE]"
187 .It Bq Er ELF_E_ARGUMENT
191 .It Bq Er ELF_E_ARGUMENT
195 .It Bq Er ELF_E_ARGUMENT
198 was not a descriptor for an ELF object.
199 .It Bq Er ELF_E_CLASS
201 .Va e_ident[EI_CLASS]
202 field of the executable header of argument
204 did not match the class of the file.
208 descriptor contained in argument
210 specified a type incompatible with its containing section.
211 .It Bq Er ELF_E_HEADER
212 The ELF header in argument
214 requested a different byte order from the byte order already
215 associated with the file.
217 An I/O error was encountered.
218 .It Bq Er ELF_E_LAYOUT
221 descriptor contained in argument
223 specified an alignment incompatible with its containing section.
224 .It Bq Er ELF_E_LAYOUT
227 contained section descriptors that overlapped in extent.
228 .It Bq Er ELF_E_LAYOUT
231 contained section descriptors that were incorrectly aligned or were
232 too small for their data.
233 .It Bq Er ELF_E_LAYOUT
236 was set on the Elf descriptor and the section header table overlapped
237 an extent in the object mapped by a section descriptor.
241 operation was requested with an ELF descriptor that was not opened for
243 .It Bq Er ELF_E_SECTION
246 contained a section with an unrecognized type.
247 .It Bq Er ELF_E_SECTION
248 The section header at index
250 had an illegal section type.
251 .It Bq Er ELF_E_SEQUENCE
254 operation was requested after a prior call to
255 .Fn elf_cntl elf ELF_C_FDDONE
256 disassociated the ELF descriptor
258 from its underlying file.
259 .It Bq Er ELF_E_VERSION
262 had an unsupported version or contained an
264 descriptor with an unsupported version.
268 .Xr elf32_getehdr 3 ,
269 .Xr elf32_getphdr 3 ,
270 .Xr elf32_newehdr 3 ,
271 .Xr elf32_newphdr 3 ,
272 .Xr elf64_getehdr 3 ,
273 .Xr elf64_getphdr 3 ,
274 .Xr elf64_newehdr 3 ,
275 .Xr elf64_newphdr 3 ,