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 open an ELF file or ar(1) archive
37 .Fn elf_begin "int fd" "Elf_Cmd cmd" "Elf *elf"
41 is used to open ELF files and
43 archives for further processing by other APIs in the
46 It is also used to access individual ELF members of an
48 archive in combination with the
56 is an open file descriptor returned from an
63 for reading or writing depending on the value of argument
67 is primarily used for iterating through archives.
71 can have the following values:
72 .Bl -tag -width "ELF_C_WRITE"
81 are ignored, and no additional error is signalled.
83 This value is to be when the application wishes to examine (but not
84 modify) the contents of the file specified by argument
86 It can be used for both
88 archives and for regular ELF files.
92 should have been opened for reading.
95 is NULL, the library will allocate a new ELF descriptor for
96 the file being processed.
99 is not NULL, and references a regular ELF file previously opened with
101 then the activation count for
106 is not NULL, and references a descriptor for an
108 archive opened earlier with
110 a descriptor for an element in the archive is returned as
111 described in the section
112 .Sx "Processing ar(1) archives"
115 The command is used to prepare an ELF file for reading and writing.
116 It is not supported for archives.
120 should have been opened for reading and writing.
123 is NULL, the library will allocate a new ELF descriptor for
124 the file being processed.
127 is non-null, it should point to a descriptor previously
130 with the same values for arguments
134 in this case the library will increment the activation count for descriptor
136 and return the same descriptor.
137 Changes to the in-memory image of the ELF file are written back to
142 This command is not valid for
146 This command is used when the application wishes to create a new ELF
150 should have been opened for writing.
153 is ignored, and the previous contents of file referenced by
158 .Ss Processing ar(1) archives
161 archive may be opened in read mode (with argument
169 The returned ELF descriptor can be passed into to
172 to access individual members of the archive.
174 Random access within an opened archive is possible using
181 The symbol table of the archive may be retrieved
185 The function returns a pointer to a ELF descriptor if successful, or NULL
186 if an error occurred.
188 To iterate through the members of an
191 .Bd -literal -offset indent
196 if ((ar_e = elf_begin(fd, c, (Elf *) 0)) == 0) {
197 \&... handle error in opening the archive ...
199 while ((elf_e = elf_begin(fd, c, ar_e)) != 0) {
200 \&... process member referenced by elf_e here ...
206 To create a new ELF file, use:
207 .Bd -literal -offset indent
211 if ((fd = open("filename", O_RDWR|O_TRUNC|O_CREAT, 0666)) < 0) {
212 \&... handle the error from open(2) ...
214 if ((e = elf_begin(fd, ELF_C_WRITE, (Elf *) 0)) == 0) {
215 \&... handle the error from elf_begin() ...
217 \&... create the ELF image using other elf(3) APIs ...
218 elf_update(e, ELF_C_WRITE);
224 can fail with the following errors:
225 .Bl -tag -width "[ELF_E_RESOURCE]"
226 .It Bq Er ELF_E_ARCHIVE
227 The archive denoted by argument
230 .It Bq Er ELF_E_ARGUMENT
231 An unrecognized value was specified in argument
233 .It Bq Er ELF_E_ARGUMENT
234 A non-null value for argument
240 .It Bq Er ELF_E_ARGUMENT
241 The value of argument
243 differs from the one the ELF descriptor
246 .It Bq Er ELF_E_ARGUMENT
249 differs from the value specified when ELF descriptor
252 .It Bq Er ELF_E_ARGUMENT
255 archive was opened with with
262 was unable to truncate a file opened for writing using
264 .It Bq Er ELF_E_RESOURCE
265 An out of memory condition was encountered.
266 .It Bq Er ELF_E_SEQUENCE
269 was called before a working version was established with