xref: /freebsd/contrib/elftoolchain/libelf/elf_getscn.3 (revision ae500c1ff8974130f7f2692772cf288b90349e0d)
1*ae500c1fSEd Maste.\" Copyright (c) 2006-2008,2018 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*ae500c1fSEd Maste.\" $Id: elf_getscn.3 3639 2018-10-14 14:07:02Z jkoshy $
252de3b87aSKai Wang.\"
26*ae500c1fSEd Maste.Dd September 24, 2018
272de3b87aSKai Wang.Dt ELF_GETSCN 3
28*ae500c1fSEd Maste.Os
292de3b87aSKai Wang.Sh NAME
302de3b87aSKai Wang.Nm elf_getscn ,
312de3b87aSKai Wang.Nm elf_ndxscn ,
322de3b87aSKai Wang.Nm elf_newscn ,
332de3b87aSKai Wang.Nm elf_nextscn
342de3b87aSKai Wang.Nd get/allocate section information for an ELF object
352de3b87aSKai Wang.Sh LIBRARY
362de3b87aSKai Wang.Lb libelf
372de3b87aSKai Wang.Sh SYNOPSIS
382de3b87aSKai Wang.In libelf.h
392de3b87aSKai Wang.Ft "Elf_Scn *"
402de3b87aSKai Wang.Fn elf_getscn "Elf *elf" "size_t index"
412de3b87aSKai Wang.Ft size_t
422de3b87aSKai Wang.Fn elf_ndxscn "Elf_Scn *scn"
432de3b87aSKai Wang.Ft "Elf_Scn *"
442de3b87aSKai Wang.Fn elf_newscn "Elf *elf"
452de3b87aSKai Wang.Ft "Elf_Scn *"
462de3b87aSKai Wang.Fn elf_nextscn "Elf *elf" "Elf_Scn *scn"
472de3b87aSKai Wang.Sh DESCRIPTION
482de3b87aSKai WangThese functions are used to iterate through the sections associated
492de3b87aSKai Wangwith an ELF descriptor.
502de3b87aSKai Wang.Pp
512de3b87aSKai WangFunction
522de3b87aSKai Wang.Fn elf_getscn
532de3b87aSKai Wangwill return a section descriptor for the section at index
542de3b87aSKai Wang.Ar index
552de3b87aSKai Wangin the object denoted by ELF descriptor
562de3b87aSKai Wang.Ar elf .
572de3b87aSKai WangAn error will be signalled if the specified section does not
582de3b87aSKai Wangexist.
592de3b87aSKai Wang.Pp
602de3b87aSKai WangFunction
612de3b87aSKai Wang.Fn elf_ndxscn
622de3b87aSKai Wangreturns the section table index associated with section descriptor
632de3b87aSKai Wang.Ar scn .
642de3b87aSKai Wang.Pp
652de3b87aSKai WangFunction
662de3b87aSKai Wang.Fn elf_newscn
672de3b87aSKai Wangcreates a new section and appends it to the list of sections
682de3b87aSKai Wangassociated with descriptor
692de3b87aSKai Wang.Ar elf .
702de3b87aSKai WangThe library will automatically increment the
712de3b87aSKai Wang.Va e_shnum
722de3b87aSKai Wangfield of the ELF header associated with descriptor
732de3b87aSKai Wang.Ar elf ,
742de3b87aSKai Wangand will set the
752de3b87aSKai Wang.Dv ELF_F_DIRTY
762de3b87aSKai Wangflag on the returned section descriptor.
772de3b87aSKai WangFor ELF descriptors opened for writing, the ELF library will
782de3b87aSKai Wangautomatically create an empty section at index zero
792de3b87aSKai Wang.Dv ( SHN_UNDEF )
802de3b87aSKai Wangon the first call to
812de3b87aSKai Wang.Fn elf_newscn .
822de3b87aSKai Wang.Pp
832de3b87aSKai WangFunction
842de3b87aSKai Wang.Fn elf_nextscn
852de3b87aSKai Wangtakes a section descriptor
862de3b87aSKai Wang.Ar scn
872de3b87aSKai Wangand returns a pointer to the section descriptor at the next higher
882de3b87aSKai Wangindex.
89*ae500c1fSEd MasteAs a consequence,
90*ae500c1fSEd Maste.Fn elf_nextscn
91*ae500c1fSEd Mastewill never return a pointer to the empty section at index zero
92*ae500c1fSEd Maste.Dv ( SHN_UNDEF ) .
932de3b87aSKai WangArgument
942de3b87aSKai Wang.Ar scn
952de3b87aSKai Wangis allowed to be NULL, in which case this function will return a
962de3b87aSKai Wangpointer to the section descriptor at index 1.
972de3b87aSKai WangIf no further sections are present, function
982de3b87aSKai Wang.Fn elf_nextscn
992de3b87aSKai Wangwill return a NULL pointer.
1002de3b87aSKai Wang.Sh RETURN VALUES
1012de3b87aSKai WangFunctions
1022de3b87aSKai Wang.Fn elf_getscn ,
1032de3b87aSKai Wang.Fn elf_newscn
1042de3b87aSKai Wangand
1052de3b87aSKai Wang.Fn elf_nextscn
1062de3b87aSKai Wangreturn a valid pointer to a section descriptor if successful, or
1072de3b87aSKai WangNULL if an error occurs.
1082de3b87aSKai Wang.Pp
1092de3b87aSKai WangFunction
1102de3b87aSKai Wang.Fn elf_ndxscn
1112de3b87aSKai Wangreturns a valid section table index if successful, or
1122de3b87aSKai Wang.Dv SHN_UNDEF
1132de3b87aSKai Wangif an error occurs.
1142de3b87aSKai Wang.Sh ERRORS
1152de3b87aSKai WangThese functions may fail with the following errors:
1162de3b87aSKai Wang.Bl -tag -width "[ELF_E_RESOURCE]"
1172de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1182de3b87aSKai WangArguments
1192de3b87aSKai Wang.Ar elf
1202de3b87aSKai Wangor
1212de3b87aSKai Wang.Ar scn
1222de3b87aSKai Wangwere NULL.
1232de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1242de3b87aSKai WangArgument
1252de3b87aSKai Wang.Ar index
1262de3b87aSKai Wangexceeded the current number of sections in the ELF object.
1272de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1282de3b87aSKai WangArgument
1292de3b87aSKai Wang.Ar elf
1302de3b87aSKai Wangwas not a descriptor for an ELF file.
1312de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT
1322de3b87aSKai WangSection descriptor
1332de3b87aSKai Wang.Ar scn
1342de3b87aSKai Wangwas not associated with ELF descriptor
1352de3b87aSKai Wang.Ar elf .
1362de3b87aSKai Wang.It Bq Er ELF_E_CLASS
1372de3b87aSKai WangDescriptor
1382de3b87aSKai Wang.Ar elf
1392de3b87aSKai Wangwas of an unknown ELF class.
1402de3b87aSKai Wang.It Bq Er ELF_E_SECTION
1412de3b87aSKai WangArgument
1422de3b87aSKai Wang.Ar elf
1432de3b87aSKai Wangspecified extended section numbering in the ELF header with the section header at
1442de3b87aSKai Wangindex
1452de3b87aSKai Wang.Dv SHN_UNDEF
1462de3b87aSKai Wangnot being of type
1472de3b87aSKai Wang.Dv SHT_NULL .
1482de3b87aSKai Wang.El
1492de3b87aSKai Wang.Sh SEE ALSO
1502de3b87aSKai Wang.Xr elf 3 ,
1512de3b87aSKai Wang.Xr elf_flagdata 3 ,
1522de3b87aSKai Wang.Xr elf_flagscn 3 ,
1532de3b87aSKai Wang.Xr elf_getdata 3 ,
1542de3b87aSKai Wang.Xr elf_getshdr 3 ,
1552de3b87aSKai Wang.Xr gelf 3
156