xref: /freebsd/contrib/elftoolchain/libelf/gelf_newehdr.3 (revision d003e0d7fe0d3a9b4b2c5835bb3f0f6faf3ab538)
12de3b87aSKai Wang.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
22de3b87aSKai Wang.\"
32de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without
42de3b87aSKai Wang.\" modification, are permitted provided that the following conditions
52de3b87aSKai Wang.\" are met:
62de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright
72de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer.
82de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright
92de3b87aSKai Wang.\"    notice, this list of conditions and the following disclaimer in the
102de3b87aSKai Wang.\"    documentation and/or other materials provided with the distribution.
112de3b87aSKai Wang.\"
122de3b87aSKai Wang.\" This software is provided by Joseph Koshy ``as is'' and
132de3b87aSKai Wang.\" any express or implied warranties, including, but not limited to, the
142de3b87aSKai Wang.\" implied warranties of merchantability and fitness for a particular purpose
152de3b87aSKai Wang.\" are disclaimed.  in no event shall Joseph Koshy be liable
162de3b87aSKai Wang.\" for any direct, indirect, incidental, special, exemplary, or consequential
172de3b87aSKai Wang.\" damages (including, but not limited to, procurement of substitute goods
182de3b87aSKai Wang.\" or services; loss of use, data, or profits; or business interruption)
192de3b87aSKai Wang.\" however caused and on any theory of liability, whether in contract, strict
202de3b87aSKai Wang.\" liability, or tort (including negligence or otherwise) arising in any way
212de3b87aSKai Wang.\" out of the use of this software, even if advised of the possibility of
222de3b87aSKai Wang.\" such damage.
232de3b87aSKai Wang.\"
24*d003e0d7SEd Maste.\" $Id: gelf_newehdr.3 3743 2019-06-12 19:36:30Z jkoshy $
252de3b87aSKai Wang.\"
26*d003e0d7SEd Maste.Dd June 12, 2019
272de3b87aSKai Wang.Dt GELF_NEWEHDR 3
28ae500c1fSEd Maste.Os
292de3b87aSKai Wang.Sh NAME
302de3b87aSKai Wang.Nm elf32_newehdr ,
312de3b87aSKai Wang.Nm elf64_newehdr ,
322de3b87aSKai Wang.Nm gelf_newehdr
332de3b87aSKai Wang.Nd retrieve or allocate the object file header
342de3b87aSKai Wang.Sh LIBRARY
352de3b87aSKai Wang.Lb libelf
362de3b87aSKai Wang.Sh SYNOPSIS
372de3b87aSKai Wang.In libelf.h
382de3b87aSKai Wang.Ft "Elf32_Ehdr *"
392de3b87aSKai Wang.Fn elf32_newehdr "Elf *elf"
402de3b87aSKai Wang.Ft "Elf64_Ehdr *"
412de3b87aSKai Wang.Fn elf64_newehdr "Elf *elf"
422de3b87aSKai Wang.In gelf.h
432de3b87aSKai Wang.Ft "void *"
442de3b87aSKai Wang.Fn gelf_newehdr "Elf *elf" "int elfclass"
452de3b87aSKai Wang.Sh DESCRIPTION
462de3b87aSKai WangThese functions retrieve the ELF header from the ELF descriptor
472de3b87aSKai Wang.Ar elf ,
482de3b87aSKai Wangallocating a new header if needed.
492de3b87aSKai WangFile data structures are translated to their in-memory representations
502de3b87aSKai Wangas described in
512de3b87aSKai Wang.Xr elf 3 .
522de3b87aSKai Wang.Pp
532de3b87aSKai WangFunction
542de3b87aSKai Wang.Fn elf32_newehdr
552de3b87aSKai Wangreturns a pointer to a 32 bit
562de3b87aSKai Wang.Vt Elf32_Ehdr
572de3b87aSKai Wangstructure.
582de3b87aSKai WangFunction
592de3b87aSKai Wang.Fn elf64_newehdr
602de3b87aSKai Wangreturns a pointer to a 64 bit
61ae500c1fSEd Maste.Vt Elf64_Ehdr
62ae500c1fSEd Mastestructure.
632de3b87aSKai Wang.Pp
642de3b87aSKai WangWhen argument
652de3b87aSKai Wang.Ar elfclass
662de3b87aSKai Wanghas value
672de3b87aSKai Wang.Dv ELFCLASS32 ,
682de3b87aSKai Wangfunction
692de3b87aSKai Wang.Fn gelf_newehdr
702de3b87aSKai Wangreturns the value returned by
712de3b87aSKai Wang.Fn elf32_newehdr "elf" .
722de3b87aSKai WangWhen argument
732de3b87aSKai Wang.Ar elfclass
742de3b87aSKai Wanghas value
752de3b87aSKai Wang.Dv ELFCLASS64
762de3b87aSKai Wangit returns the value returned by
772de3b87aSKai Wang.Fn elf64_newehdr "elf" .
782de3b87aSKai Wang.Pp
792de3b87aSKai WangIf a fresh header structure is allocated, the members of the
802de3b87aSKai Wangstructure are initialized as follows:
812de3b87aSKai Wang.Bl -tag -width indent
822de3b87aSKai Wang.It Va "e_ident[EI_MAG0..EI_MAG3]"
832de3b87aSKai WangIdentification bytes at offsets
842de3b87aSKai Wang.Dv EI_MAG0 ,
852de3b87aSKai Wang.Dv EI_MAG1 ,
862de3b87aSKai Wang.Dv EI_MAG2
872de3b87aSKai Wangand
882de3b87aSKai Wang.Dv EI_MAG3
892de3b87aSKai Wangare set to the ELF signature.
902de3b87aSKai Wang.It Va "e_ident[EI_CLASS]"
912de3b87aSKai WangThe identification byte at offset
922de3b87aSKai Wang.Dv EI_CLASS
932de3b87aSKai Wangis set to the ELF class associated with the function being called
942de3b87aSKai Wangor to argument
952de3b87aSKai Wang.Ar elfclass
962de3b87aSKai Wangfor function
972de3b87aSKai Wang.Fn gelf_newehdr .
982de3b87aSKai Wang.It Va "e_ident[EI_DATA]"
992de3b87aSKai WangThe identification byte at offset
1002de3b87aSKai Wang.Dv EI_DATA
1012de3b87aSKai Wangis set to
1022de3b87aSKai Wang.Dv ELFDATANONE .
1032de3b87aSKai Wang.It Va "e_ident[EI_VERSION]"
1042de3b87aSKai WangThe identification byte at offset
1052de3b87aSKai Wang.Dv EI_VERSION
1062de3b87aSKai Wangis set to the ELF library's operating version set by a prior call to
1072de3b87aSKai Wang.Xr elf_version 3 .
1082de3b87aSKai Wang.It Va e_machine
1092de3b87aSKai Wangis set to
1102de3b87aSKai Wang.Dv EM_NONE .
1112de3b87aSKai Wang.It Va e_type
1122de3b87aSKai Wangis set to
1132de3b87aSKai Wang.Dv ELF_K_NONE .
1142de3b87aSKai Wang.It Va e_version
1152de3b87aSKai Wangis set to the ELF library's operating version set by a prior call to
1162de3b87aSKai Wang.Xr elf_version 3 .
1172de3b87aSKai Wang.El
1182de3b87aSKai Wang.Pp
1192de3b87aSKai WangOther members of the header are set to zero.
1202de3b87aSKai WangThe application is responsible for changing these values
1212de3b87aSKai Wangas needed before calling
1222de3b87aSKai Wang.Fn elf_update .
1232de3b87aSKai Wang.Pp
1242de3b87aSKai WangIf successful, these three functions set the
1252de3b87aSKai Wang.Dv ELF_F_DIRTY
1262de3b87aSKai Wangflag on ELF descriptor
1272de3b87aSKai Wang.Ar elf .
1282de3b87aSKai Wang.Sh RETURN VALUES
1292de3b87aSKai WangThese functions return a pointer to a translated header descriptor
1302de3b87aSKai Wangif successful, or NULL on failure.
131bee2765cSEd Maste.Sh COMPATIBILITY
132bee2765cSEd MasteThe
133bee2765cSEd Maste.Fn gelf_newehdr
134bee2765cSEd Mastefunction uses a type of
135bee2765cSEd Maste.Ft "void *"
136bee2765cSEd Mastefor its returned value.
137*d003e0d7SEd MasteThis differs from some other implementations of the
138*d003e0d7SEd Maste.Xr elf 3
139*d003e0d7SEd MasteAPI, which use an
140bee2765cSEd Maste.Ft "unsigned long"
141bee2765cSEd Mastereturn type.
1422de3b87aSKai Wang.Sh ERRORS
1432de3b87aSKai WangThese functions can fail with the following errors:
1442de3b87aSKai Wang.Bl -tag -width "[ELF_E_RESOURCE]"
1452de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1462de3b87aSKai WangThe argument
1472de3b87aSKai Wang.Ar elf
1482de3b87aSKai Wangwas null.
1492de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1502de3b87aSKai WangArgument
1512de3b87aSKai Wang.Ar elf
1522de3b87aSKai Wangwas not a descriptor for an ELF object.
1532de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1542de3b87aSKai WangArgument
1552de3b87aSKai Wang.Ar elfclass
1562de3b87aSKai Wanghad an unsupported value.
1572de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1582de3b87aSKai WangThe class of the ELF descriptor
1592de3b87aSKai Wang.Ar elf
1602de3b87aSKai Wangdid not match that of the requested operation.
1612de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1622de3b87aSKai WangFor function
1632de3b87aSKai Wang.Fn gelf_newehdr ,
1642de3b87aSKai Wangthe class of argument
1652de3b87aSKai Wang.Ar elf
1662de3b87aSKai Wangwas not
1672de3b87aSKai Wang.Dv ELFCLASSNONE
1682de3b87aSKai Wangand did not match the argument
1692de3b87aSKai Wang.Ar elfclass .
1702de3b87aSKai Wang.It Bq Er ELF_E_CLASS
1712de3b87aSKai WangThe ELF class of descriptor
1722de3b87aSKai Wang.Ar elf
1732de3b87aSKai Wangdid not match that of the API function being called.
1742de3b87aSKai Wang.It Bq Er ELF_E_HEADER
1752de3b87aSKai WangA malformed ELF header was detected.
1762de3b87aSKai Wang.It Bq Er ELF_E_RESOURCE
1772de3b87aSKai WangAn out of memory condition was detected during execution.
1782de3b87aSKai Wang.It Bq Er ELF_E_SECTION
1792de3b87aSKai WangThe ELF descriptor in argument
1802de3b87aSKai Wang.Ar elf
1812de3b87aSKai Wangdid not adhere to the conventions used for extended numbering.
1822de3b87aSKai Wang.It Bq Er ELF_E_VERSION
1832de3b87aSKai WangThe ELF descriptor
1842de3b87aSKai Wang.Ar elf
1852de3b87aSKai Wanghad an unsupported ELF version number.
1862de3b87aSKai Wang.El
1872de3b87aSKai Wang.Sh SEE ALSO
1882de3b87aSKai Wang.Xr elf 3 ,
1892de3b87aSKai Wang.Xr elf32_getehdr 3 ,
1902de3b87aSKai Wang.Xr elf64_getehdr 3 ,
1912de3b87aSKai Wang.Xr elf_flagdata 3 ,
1922de3b87aSKai Wang.Xr elf_getident 3 ,
1932de3b87aSKai Wang.Xr elf_update 3 ,
1942de3b87aSKai Wang.Xr elf_version 3 ,
1952de3b87aSKai Wang.Xr gelf 3 ,
1962de3b87aSKai Wang.Xr gelf_getehdr 3 ,
1972de3b87aSKai Wang.Xr elf 5
198