xref: /minix3/external/bsd/elftoolchain/dist/libelf/gelf_newehdr.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: gelf_newehdr.3,v 1.2 2014/03/09 16:58:04 christos Exp $
2*0a6a1f1dSLionel Sambuc.\"
3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
4*0a6a1f1dSLionel Sambuc.\"
5*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
6*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions
7*0a6a1f1dSLionel Sambuc.\" are met:
8*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
9*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
10*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
11*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
12*0a6a1f1dSLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
13*0a6a1f1dSLionel Sambuc.\"
14*0a6a1f1dSLionel Sambuc.\" This software is provided by Joseph Koshy ``as is'' and
15*0a6a1f1dSLionel Sambuc.\" any express or implied warranties, including, but not limited to, the
16*0a6a1f1dSLionel Sambuc.\" implied warranties of merchantability and fitness for a particular purpose
17*0a6a1f1dSLionel Sambuc.\" are disclaimed.  in no event shall Joseph Koshy be liable
18*0a6a1f1dSLionel Sambuc.\" for any direct, indirect, incidental, special, exemplary, or consequential
19*0a6a1f1dSLionel Sambuc.\" damages (including, but not limited to, procurement of substitute goods
20*0a6a1f1dSLionel Sambuc.\" or services; loss of use, data, or profits; or business interruption)
21*0a6a1f1dSLionel Sambuc.\" however caused and on any theory of liability, whether in contract, strict
22*0a6a1f1dSLionel Sambuc.\" liability, or tort (including negligence or otherwise) arising in any way
23*0a6a1f1dSLionel Sambuc.\" out of the use of this software, even if advised of the possibility of
24*0a6a1f1dSLionel Sambuc.\" such damage.
25*0a6a1f1dSLionel Sambuc.\"
26*0a6a1f1dSLionel Sambuc.\" Id: gelf_newehdr.3 189 2008-07-20 10:38:08Z jkoshy
27*0a6a1f1dSLionel Sambuc.\"
28*0a6a1f1dSLionel Sambuc.Dd October 22, 2007
29*0a6a1f1dSLionel Sambuc.Os
30*0a6a1f1dSLionel Sambuc.Dt GELF_NEWEHDR 3
31*0a6a1f1dSLionel Sambuc.Sh NAME
32*0a6a1f1dSLionel Sambuc.Nm elf32_newehdr ,
33*0a6a1f1dSLionel Sambuc.Nm elf64_newehdr ,
34*0a6a1f1dSLionel Sambuc.Nm gelf_newehdr
35*0a6a1f1dSLionel Sambuc.Nd retrieve or allocate the object file header
36*0a6a1f1dSLionel Sambuc.Sh LIBRARY
37*0a6a1f1dSLionel Sambuc.Lb libelf
38*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS
39*0a6a1f1dSLionel Sambuc.In libelf.h
40*0a6a1f1dSLionel Sambuc.Ft "Elf32_Ehdr *"
41*0a6a1f1dSLionel Sambuc.Fn elf32_newehdr "Elf *elf"
42*0a6a1f1dSLionel Sambuc.Ft "Elf64_Ehdr *"
43*0a6a1f1dSLionel Sambuc.Fn elf64_newehdr "Elf *elf"
44*0a6a1f1dSLionel Sambuc.In gelf.h
45*0a6a1f1dSLionel Sambuc.Ft "void *"
46*0a6a1f1dSLionel Sambuc.Fn gelf_newehdr "Elf *elf" "int elfclass"
47*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION
48*0a6a1f1dSLionel SambucThese functions retrieve the ELF header from the ELF descriptor
49*0a6a1f1dSLionel Sambuc.Ar elf ,
50*0a6a1f1dSLionel Sambucallocating a new header if needed.
51*0a6a1f1dSLionel SambucFile data structures are translated to their in-memory representations
52*0a6a1f1dSLionel Sambucas described in
53*0a6a1f1dSLionel Sambuc.Xr elf 3 .
54*0a6a1f1dSLionel Sambuc.Pp
55*0a6a1f1dSLionel SambucFunction
56*0a6a1f1dSLionel Sambuc.Fn elf32_newehdr
57*0a6a1f1dSLionel Sambucreturns a pointer to a 32 bit
58*0a6a1f1dSLionel Sambuc.Vt Elf32_Ehdr
59*0a6a1f1dSLionel Sambucstructure.
60*0a6a1f1dSLionel SambucFunction
61*0a6a1f1dSLionel Sambuc.Fn elf64_newehdr
62*0a6a1f1dSLionel Sambucreturns a pointer to a 64 bit
63*0a6a1f1dSLionel Sambuc.Vt Elf64_Ehdr structure.
64*0a6a1f1dSLionel Sambuc.Pp
65*0a6a1f1dSLionel SambucWhen argument
66*0a6a1f1dSLionel Sambuc.Ar elfclass
67*0a6a1f1dSLionel Sambuchas value
68*0a6a1f1dSLionel Sambuc.Dv ELFCLASS32 ,
69*0a6a1f1dSLionel Sambucfunction
70*0a6a1f1dSLionel Sambuc.Fn gelf_newehdr
71*0a6a1f1dSLionel Sambucreturns the value returned by
72*0a6a1f1dSLionel Sambuc.Fn elf32_newehdr "elf" .
73*0a6a1f1dSLionel SambucWhen argument
74*0a6a1f1dSLionel Sambuc.Ar elfclass
75*0a6a1f1dSLionel Sambuchas value
76*0a6a1f1dSLionel Sambuc.Dv ELFCLASS64
77*0a6a1f1dSLionel Sambucit returns the value returned by
78*0a6a1f1dSLionel Sambuc.Fn elf64_newehdr "elf" .
79*0a6a1f1dSLionel Sambuc.Pp
80*0a6a1f1dSLionel SambucIf a fresh header structure is allocated, the members of the
81*0a6a1f1dSLionel Sambucstructure are initialized as follows:
82*0a6a1f1dSLionel Sambuc.Bl -tag -width indent
83*0a6a1f1dSLionel Sambuc.It Va "e_ident[EI_MAG0..EI_MAG3]"
84*0a6a1f1dSLionel SambucIdentification bytes at offsets
85*0a6a1f1dSLionel Sambuc.Dv EI_MAG0 ,
86*0a6a1f1dSLionel Sambuc.Dv EI_MAG1 ,
87*0a6a1f1dSLionel Sambuc.Dv EI_MAG2
88*0a6a1f1dSLionel Sambucand
89*0a6a1f1dSLionel Sambuc.Dv EI_MAG3
90*0a6a1f1dSLionel Sambucare set to the ELF signature.
91*0a6a1f1dSLionel Sambuc.It Va "e_ident[EI_CLASS]"
92*0a6a1f1dSLionel SambucThe identification byte at offset
93*0a6a1f1dSLionel Sambuc.Dv EI_CLASS
94*0a6a1f1dSLionel Sambucis set to the ELF class associated with the function being called
95*0a6a1f1dSLionel Sambucor to argument
96*0a6a1f1dSLionel Sambuc.Ar elfclass
97*0a6a1f1dSLionel Sambucfor function
98*0a6a1f1dSLionel Sambuc.Fn gelf_newehdr .
99*0a6a1f1dSLionel Sambuc.It Va "e_ident[EI_DATA]"
100*0a6a1f1dSLionel SambucThe identification byte at offset
101*0a6a1f1dSLionel Sambuc.Dv EI_DATA
102*0a6a1f1dSLionel Sambucis set to
103*0a6a1f1dSLionel Sambuc.Dv ELFDATANONE .
104*0a6a1f1dSLionel Sambuc.It Va "e_ident[EI_VERSION]"
105*0a6a1f1dSLionel SambucThe identification byte at offset
106*0a6a1f1dSLionel Sambuc.Dv EI_VERSION
107*0a6a1f1dSLionel Sambucis set to the ELF library's operating version set by a prior call to
108*0a6a1f1dSLionel Sambuc.Xr elf_version 3 .
109*0a6a1f1dSLionel Sambuc.It Va e_machine
110*0a6a1f1dSLionel Sambucis set to
111*0a6a1f1dSLionel Sambuc.Dv EM_NONE .
112*0a6a1f1dSLionel Sambuc.It Va e_type
113*0a6a1f1dSLionel Sambucis set to
114*0a6a1f1dSLionel Sambuc.Dv ELF_K_NONE .
115*0a6a1f1dSLionel Sambuc.It Va e_version
116*0a6a1f1dSLionel Sambucis set to the ELF library's operating version set by a prior call to
117*0a6a1f1dSLionel Sambuc.Xr elf_version 3 .
118*0a6a1f1dSLionel Sambuc.El
119*0a6a1f1dSLionel Sambuc.Pp
120*0a6a1f1dSLionel SambucOther members of the header are set to zero.
121*0a6a1f1dSLionel SambucThe application is responsible for changing these values
122*0a6a1f1dSLionel Sambucas needed before calling
123*0a6a1f1dSLionel Sambuc.Fn elf_update .
124*0a6a1f1dSLionel Sambuc.Pp
125*0a6a1f1dSLionel SambucIf successful, these three functions set the
126*0a6a1f1dSLionel Sambuc.Dv ELF_F_DIRTY
127*0a6a1f1dSLionel Sambucflag on ELF descriptor
128*0a6a1f1dSLionel Sambuc.Ar elf .
129*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES
130*0a6a1f1dSLionel SambucThese functions return a pointer to a translated header descriptor
131*0a6a1f1dSLionel Sambucif successful, or NULL on failure.
132*0a6a1f1dSLionel Sambuc.Sh ERRORS
133*0a6a1f1dSLionel SambucThese functions can fail with the following errors:
134*0a6a1f1dSLionel Sambuc.Bl -tag -width "[ELF_E_RESOURCE]"
135*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT
136*0a6a1f1dSLionel SambucThe argument
137*0a6a1f1dSLionel Sambuc.Ar elf
138*0a6a1f1dSLionel Sambucwas null.
139*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT
140*0a6a1f1dSLionel SambucArgument
141*0a6a1f1dSLionel Sambuc.Ar elf
142*0a6a1f1dSLionel Sambucwas not a descriptor for an ELF object.
143*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT
144*0a6a1f1dSLionel SambucArgument
145*0a6a1f1dSLionel Sambuc.Ar elfclass
146*0a6a1f1dSLionel Sambuchad an unsupported value.
147*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT
148*0a6a1f1dSLionel SambucThe class of the ELF descriptor
149*0a6a1f1dSLionel Sambuc.Ar elf
150*0a6a1f1dSLionel Sambucdid not match that of the requested operation.
151*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT
152*0a6a1f1dSLionel SambucFor function
153*0a6a1f1dSLionel Sambuc.Fn gelf_newehdr ,
154*0a6a1f1dSLionel Sambucthe class of argument
155*0a6a1f1dSLionel Sambuc.Ar elf
156*0a6a1f1dSLionel Sambucwas not
157*0a6a1f1dSLionel Sambuc.Dv ELFCLASSNONE
158*0a6a1f1dSLionel Sambucand did not match the argument
159*0a6a1f1dSLionel Sambuc.Ar elfclass .
160*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_CLASS
161*0a6a1f1dSLionel SambucThe ELF class of descriptor
162*0a6a1f1dSLionel Sambuc.Ar elf
163*0a6a1f1dSLionel Sambucdid not match that of the API function being called.
164*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_HEADER
165*0a6a1f1dSLionel SambucA malformed ELF header was detected.
166*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_RESOURCE
167*0a6a1f1dSLionel SambucAn out of memory condition was detected during execution.
168*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_SECTION
169*0a6a1f1dSLionel SambucThe ELF descriptor in argument
170*0a6a1f1dSLionel Sambuc.Ar elf
171*0a6a1f1dSLionel Sambucdid not adhere to the conventions used for extended numbering.
172*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_VERSION
173*0a6a1f1dSLionel SambucThe ELF descriptor
174*0a6a1f1dSLionel Sambuc.Ar elf
175*0a6a1f1dSLionel Sambuchad an unsupported ELF version number.
176*0a6a1f1dSLionel Sambuc.El
177*0a6a1f1dSLionel Sambuc.Sh SEE ALSO
178*0a6a1f1dSLionel Sambuc.Xr elf 3 ,
179*0a6a1f1dSLionel Sambuc.Xr elf32_getehdr 3 ,
180*0a6a1f1dSLionel Sambuc.Xr elf64_getehdr 3 ,
181*0a6a1f1dSLionel Sambuc.Xr elf_flagdata 3 ,
182*0a6a1f1dSLionel Sambuc.Xr elf_getident 3 ,
183*0a6a1f1dSLionel Sambuc.Xr elf_update 3 ,
184*0a6a1f1dSLionel Sambuc.Xr elf_version 3 ,
185*0a6a1f1dSLionel Sambuc.Xr gelf 3 ,
186*0a6a1f1dSLionel Sambuc.Xr gelf_getehdr 3 ,
187*0a6a1f1dSLionel Sambuc.Xr elf 5
188