xref: /freebsd/contrib/elftoolchain/libelf/elf_getdata.3 (revision d003e0d7fe0d3a9b4b2c5835bb3f0f6faf3ab538)
12de3b87aSKai Wang.\" Copyright (c) 2006,2008,2010-2011 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: elf_getdata.3 3734 2019-04-22 14:10:49Z jkoshy $
252de3b87aSKai Wang.\"
26*d003e0d7SEd Maste.Dd April 22, 2019
272de3b87aSKai Wang.Dt ELF_GETDATA 3
28ae500c1fSEd Maste.Os
292de3b87aSKai Wang.Sh NAME
302de3b87aSKai Wang.Nm elf_getdata ,
312de3b87aSKai Wang.Nm elf_newdata ,
322de3b87aSKai Wang.Nm elf_rawdata
332de3b87aSKai Wang.Nd iterate through or allocate section data
342de3b87aSKai Wang.Sh LIBRARY
352de3b87aSKai Wang.Lb libelf
362de3b87aSKai Wang.Sh SYNOPSIS
372de3b87aSKai Wang.In libelf.h
382de3b87aSKai Wang.Ft "Elf_Data *"
392de3b87aSKai Wang.Fn elf_getdata "Elf_Scn *scn" "Elf_Data *data"
402de3b87aSKai Wang.Ft "Elf_Data *"
412de3b87aSKai Wang.Fn elf_newdata "Elf_Scn *scn"
422de3b87aSKai Wang.Ft "Elf_Data *"
432de3b87aSKai Wang.Fn elf_rawdata "Elf_Scn *scn" "Elf_Data *data"
442de3b87aSKai Wang.Sh DESCRIPTION
452de3b87aSKai WangThese functions are used to access and manipulate data descriptors
462de3b87aSKai Wangassociated with section descriptors.
472de3b87aSKai WangData descriptors used by the ELF library are described in
482de3b87aSKai Wang.Xr elf 3 .
492de3b87aSKai Wang.Pp
502de3b87aSKai WangFunction
512de3b87aSKai Wang.Fn elf_getdata
522de3b87aSKai Wangwill return the next data descriptor associated with section descriptor
532de3b87aSKai Wang.Ar scn .
542de3b87aSKai WangThe returned data descriptor will be setup to contain translated data.
552de3b87aSKai WangArgument
562de3b87aSKai Wang.Ar data
572de3b87aSKai Wangmay be NULL, in which case the function returns the first data descriptor
582de3b87aSKai Wangassociated with section
592de3b87aSKai Wang.Ar scn .
602de3b87aSKai WangIf argument
612de3b87aSKai Wang.Ar data
622de3b87aSKai Wangis not NULL, it must be a pointer to a data descriptor associated with
632de3b87aSKai Wangsection descriptor
642de3b87aSKai Wang.Ar scn ,
652de3b87aSKai Wangand function
662de3b87aSKai Wang.Fn elf_getdata
672de3b87aSKai Wangwill return a pointer to the next data descriptor for the section,
682de3b87aSKai Wangor NULL when the end of the section's descriptor list is reached.
692de3b87aSKai Wang.Pp
702de3b87aSKai WangFunction
712de3b87aSKai Wang.Fn elf_newdata
722de3b87aSKai Wangwill allocate a new data descriptor and append it to the list of data
732de3b87aSKai Wangdescriptors associated with section descriptor
742de3b87aSKai Wang.Ar scn .
752de3b87aSKai WangThe new data descriptor will be initialized as follows:
762de3b87aSKai Wang.Bl -tag -width "d_version" -compact -offset indent
772de3b87aSKai Wang.It Va d_align
782de3b87aSKai WangSet to 1.
792de3b87aSKai Wang.It Va d_buf
802de3b87aSKai WangInitialized to NULL.
812de3b87aSKai Wang.It Va d_off
822de3b87aSKai WangSet to (off_t) -1.
832de3b87aSKai WangThis field is under application control if the
842de3b87aSKai Wang.Dv ELF_F_LAYOUT
852de3b87aSKai Wangflag was set on the ELF descriptor.
862de3b87aSKai Wang.It Va d_size
872de3b87aSKai WangSet to zero.
882de3b87aSKai Wang.It Va d_type
892de3b87aSKai WangInitialized to
902de3b87aSKai Wang.Dv ELF_T_BYTE .
912de3b87aSKai Wang.It Va d_version
922de3b87aSKai WangSet to the current working version of the library, as set by
932de3b87aSKai Wang.Xr elf_version 3 .
942de3b87aSKai Wang.El
952de3b87aSKai WangThe application must set these values as appropriate before
962de3b87aSKai Wangcalling
972de3b87aSKai Wang.Xr elf_update 3 .
982de3b87aSKai WangSection
992de3b87aSKai Wang.Ar scn
1002de3b87aSKai Wangmust be associated with an ELF file opened for writing.
1012de3b87aSKai WangIf the application has not requested full control of layout by
1022de3b87aSKai Wangsetting the
1032de3b87aSKai Wang.Dv ELF_F_LAYOUT
1042de3b87aSKai Wangflag on descriptor
1052de3b87aSKai Wang.Ar elf ,
1062de3b87aSKai Wangthen the data referenced by the returned descriptor will be positioned
1072de3b87aSKai Wangafter the existing content of the section, honoring the file alignment
1082de3b87aSKai Wangspecified in member
1092de3b87aSKai Wang.Va d_align .
1102de3b87aSKai WangOn successful completion of a call to
1112de3b87aSKai Wang.Fn elf_newdata ,
1122de3b87aSKai Wangthe ELF library will mark the section
1132de3b87aSKai Wang.Ar scn
1142de3b87aSKai Wangas
1152de3b87aSKai Wang.Dq dirty .
1162de3b87aSKai Wang.Pp
1172de3b87aSKai WangFunction
1182de3b87aSKai Wang.Fn elf_rawdata
1192de3b87aSKai Wangis used to step through the data descriptors associated with
1202de3b87aSKai Wangsection
1212de3b87aSKai Wang.Ar scn .
1222de3b87aSKai WangIn contrast to function
1232de3b87aSKai Wang.Fn elf_getdata ,
1242de3b87aSKai Wangthis function returns untranslated data.
1252de3b87aSKai WangIf argument
1262de3b87aSKai Wang.Ar data
1272de3b87aSKai Wangis NULL, the first data descriptor associated with section
1282de3b87aSKai Wang.Ar scn
1292de3b87aSKai Wangis returned.
1302de3b87aSKai WangIf argument
1312de3b87aSKai Wang.Ar data
1322de3b87aSKai Wangis not NULL, is must be a data descriptor associated with
1332de3b87aSKai Wangsection
1342de3b87aSKai Wang.Ar scn ,
1352de3b87aSKai Wangand function
1362de3b87aSKai Wang.Fn elf_rawdata
1372de3b87aSKai Wangwill return the next data descriptor in the list, or NULL
1382de3b87aSKai Wangif no further descriptors are present.
1392de3b87aSKai WangFunction
1402de3b87aSKai Wang.Fn elf_rawdata
1412de3b87aSKai Wangalways returns
1422de3b87aSKai Wang.Vt Elf_Data
1432de3b87aSKai Wangstructures of type
1442de3b87aSKai Wang.Dv ELF_T_BYTE .
1452de3b87aSKai Wang.Ss Special handling of zero-sized and SHT_NOBITS sections
1462de3b87aSKai WangFor sections of type
1472de3b87aSKai Wang.Dv SHT_NOBITS ,
1482de3b87aSKai Wangand for zero-sized sections,
1492de3b87aSKai Wangthe functions
1502de3b87aSKai Wang.Fn elf_getdata
1512de3b87aSKai Wangand
1522de3b87aSKai Wang.Fn elf_rawdata
1532de3b87aSKai Wangreturn a pointer to a valid
1542de3b87aSKai Wang.Vt Elf_Data
1552de3b87aSKai Wangstructure that has its
1562de3b87aSKai Wang.Va d_buf
1572de3b87aSKai Wangmember set to NULL and its
1582de3b87aSKai Wang.Va d_size
1592de3b87aSKai Wangmember set to the size of the section.
1602de3b87aSKai Wang.Pp
1612de3b87aSKai WangIf an application wishes to create a section of type
1622de3b87aSKai Wang.Dv SHT_NOBITS ,
1632de3b87aSKai Wangit should add a data buffer to the section using function
1642de3b87aSKai Wang.Fn elf_newdata .
1652de3b87aSKai WangIt should then set the
1662de3b87aSKai Wang.Va d_buf
1672de3b87aSKai Wangand
1682de3b87aSKai Wang.Va d_size
1692de3b87aSKai Wangmembers of the returned
1702de3b87aSKai Wang.Vt Elf_Data
1712de3b87aSKai Wangstructure to NULL and the desired size of the section respectively.
1722de3b87aSKai Wang.Sh RETURN VALUES
1732de3b87aSKai WangThese functions return a valid pointer to a data descriptor if successful, or
1742de3b87aSKai WangNULL if an error occurs.
1752de3b87aSKai Wang.Sh ERRORS
1762de3b87aSKai WangThese functions may fail with the following errors:
1772de3b87aSKai Wang.Bl -tag -width "[ELF_E_RESOURCE]"
1782de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1792de3b87aSKai WangEither of the arguments
1802de3b87aSKai Wang.Ar scn
1812de3b87aSKai Wangor
1822de3b87aSKai Wang.Ar data
1832de3b87aSKai Wangwas NULL.
1842de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1852de3b87aSKai WangThe data descriptor referenced by argument
1862de3b87aSKai Wang.Ar data
1872de3b87aSKai Wangis not associated with section descriptor
1882de3b87aSKai Wang.Ar scn .
1892de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1902de3b87aSKai WangThe section denoted by argument
1912de3b87aSKai Wang.Ar scn
1922de3b87aSKai Wanghad no data associated with it.
1932de3b87aSKai Wang.It Bq Er ELF_E_DATA
1942de3b87aSKai WangRetrieval of data from the underlying object failed.
1952de3b87aSKai Wang.It Bq Er ELF_E_RESOURCE
1962de3b87aSKai WangAn out of memory condition was detected.
1972de3b87aSKai Wang.It Bq Er ELF_E_SECTION
1982de3b87aSKai WangSection
1992de3b87aSKai Wang.Ar scn
2002de3b87aSKai Wanghad type
2012de3b87aSKai Wang.Dv SHT_NULL .
2022de3b87aSKai Wang.It Bq Er ELF_E_SECTION
2032de3b87aSKai WangThe type of the section
2042de3b87aSKai Wang.Ar scn
2052de3b87aSKai Wangwas not recognized by the library.
2062de3b87aSKai Wang.It Bq Er ELF_E_SECTION
2072de3b87aSKai WangThe size of the section
2082de3b87aSKai Wang.Ar scn
2092de3b87aSKai Wangis not a multiple of the file size for its section type.
2102de3b87aSKai Wang.It Bq Er ELF_E_SECTION
2112de3b87aSKai WangThe file offset for section
2122de3b87aSKai Wang.Ar scn
2132de3b87aSKai Wangis incorrect.
2142de3b87aSKai Wang.It Bq Er ELF_E_UNIMPL
2152de3b87aSKai WangThe section type associated with section
2162de3b87aSKai Wang.Ar scn
217*d003e0d7SEd Masteis not supported.
218*d003e0d7SEd Maste.It Bq Er ELF_E_VERSION
219*d003e0d7SEd MasteSection
220*d003e0d7SEd Maste.Ar scn
221*d003e0d7SEd Mastewas associated with an ELF object with an unsupported
222*d003e0d7SEd Masteversion.
2232de3b87aSKai Wang.El
2242de3b87aSKai Wang.Sh SEE ALSO
2252de3b87aSKai Wang.Xr elf 3 ,
2262de3b87aSKai Wang.Xr elf_flagdata 3 ,
2272de3b87aSKai Wang.Xr elf_flagscn 3 ,
2282de3b87aSKai Wang.Xr elf_getscn 3 ,
2292de3b87aSKai Wang.Xr elf_getshdr 3 ,
2302de3b87aSKai Wang.Xr elf_newscn 3 ,
2312de3b87aSKai Wang.Xr elf_rawfile 3 ,
2322de3b87aSKai Wang.Xr elf_update 3 ,
2332de3b87aSKai Wang.Xr elf_version 3 ,
2342de3b87aSKai Wang.Xr gelf 3
235