xref: /freebsd/contrib/elftoolchain/libelf/elf_open.3 (revision 5d418202f888e5d5062f1e4d26457ea67fc81739)
1.\" Copyright (c) 2012 Joseph Koshy.  All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
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.
11.\"
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
22.\" such damage.
23.\"
24.\" $Id: elf_open.3 3743 2019-06-12 19:36:30Z jkoshy $
25.\"
26.Dd July 15, 2025
27.Dt ELF_OPEN 3
28.Os
29.Sh NAME
30.Nm elf_open ,
31.Nm elf_openmemory
32.Nd open ELF objects and ar(1) archives
33.Sh LIBRARY
34.Lb libelf
35.Sh SYNOPSIS
36.In libelf.h
37.Ft "Elf *"
38.Fn elf_open "int fd"
39.Ft "Elf *"
40.Fn elf_openmemory "char *image" "size_t sz"
41.Sh DESCRIPTION
42.Em Important :
43The functions
44.Fn elf_open
45and
46.Fn elf_openmemory
47are extensions to the
48.Xr elf 3
49API, for the internal use of the
50Elftoolchain project.
51Portable applications should not use these functions.
52.Pp
53The function
54.Fn elf_open
55returns an Elf descriptor opened with mode
56.Dv ELF_C_READ
57for the ELF object or
58.Xr ar 1
59archive referenced by the file descriptor in argument
60.Ar fd .
61.Pp
62The function
63.Fn elf_openmemory
64returns an ELF descriptor opened with mode
65.Dv ELF_C_READ
66for the ELF object or
67.Xr ar 1
68archive contained in the memory area pointed to by the argument
69.Ar image .
70The argument
71.Ar sz
72specifies the size of the memory area in bytes.
73.Sh RETURN VALUES
74The function returns a pointer to a ELF descriptor if successful, or
75NULL if an error occurred.
76.Sh COMPATIBILITY
77These functions are non-standard extensions to the
78.Xr elf 3
79API set.
80.Pp
81The behavior of these functions differs from their counterparts
82.Xr elf_begin 3
83and
84.Xr elf_memory 3
85in that these functions will successfully open malformed ELF objects
86and
87.Xr ar 1
88archives, returning an Elf descriptor of type
89.Dv ELF_K_NONE .
90.Sh ERRORS
91These functions can fail with the following errors:
92.Bl -tag -width "[ELF_E_RESOURCE]"
93.It Bq Er ELF_E_ARGUMENT
94The argument
95.Ar fd
96was of an unsupported file type.
97.It Bq Er ELF_E_ARGUMENT
98The argument
99.Ar sz
100was zero, or the argument
101.Ar image
102was NULL.
103.It Bq Er ELF_E_IO
104The file descriptor in argument
105.Ar fd
106was invalid.
107.It Bq Er ELF_E_IO
108The file descriptor in argument
109.Ar fd
110could not be read.
111.It Bq Er ELF_E_RESOURCE
112An out of memory condition was encountered.
113.It Bq Er ELF_E_SEQUENCE
114Functions
115.Fn elf_open
116or
117.Fn elf_openmemory
118was called before a working version was established with
119.Xr elf_version 3 .
120.El
121.Sh SEE ALSO
122.Xr elf 3 ,
123.Xr elf_begin 3 ,
124.Xr elf_errno 3 ,
125.Xr elf_memory 3 ,
126.Xr gelf 3
127