xref: /freebsd/contrib/elftoolchain/libelf/elf_getscn.3 (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1.\" Copyright (c) 2006-2008,2018 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_getscn.3 3639 2018-10-14 14:07:02Z jkoshy $
25.\"
26.Dd September 24, 2018
27.Dt ELF_GETSCN 3
28.Os
29.Sh NAME
30.Nm elf_getscn ,
31.Nm elf_ndxscn ,
32.Nm elf_newscn ,
33.Nm elf_nextscn
34.Nd get/allocate section information for an ELF object
35.Sh LIBRARY
36.Lb libelf
37.Sh SYNOPSIS
38.In libelf.h
39.Ft "Elf_Scn *"
40.Fn elf_getscn "Elf *elf" "size_t index"
41.Ft size_t
42.Fn elf_ndxscn "Elf_Scn *scn"
43.Ft "Elf_Scn *"
44.Fn elf_newscn "Elf *elf"
45.Ft "Elf_Scn *"
46.Fn elf_nextscn "Elf *elf" "Elf_Scn *scn"
47.Sh DESCRIPTION
48These functions are used to iterate through the sections associated
49with an ELF descriptor.
50.Pp
51Function
52.Fn elf_getscn
53will return a section descriptor for the section at index
54.Ar index
55in the object denoted by ELF descriptor
56.Ar elf .
57An error will be signalled if the specified section does not
58exist.
59.Pp
60Function
61.Fn elf_ndxscn
62returns the section table index associated with section descriptor
63.Ar scn .
64.Pp
65Function
66.Fn elf_newscn
67creates a new section and appends it to the list of sections
68associated with descriptor
69.Ar elf .
70The library will automatically increment the
71.Va e_shnum
72field of the ELF header associated with descriptor
73.Ar elf ,
74and will set the
75.Dv ELF_F_DIRTY
76flag on the returned section descriptor.
77For ELF descriptors opened for writing, the ELF library will
78automatically create an empty section at index zero
79.Dv ( SHN_UNDEF )
80on the first call to
81.Fn elf_newscn .
82.Pp
83Function
84.Fn elf_nextscn
85takes a section descriptor
86.Ar scn
87and returns a pointer to the section descriptor at the next higher
88index.
89As a consequence,
90.Fn elf_nextscn
91will never return a pointer to the empty section at index zero
92.Dv ( SHN_UNDEF ) .
93Argument
94.Ar scn
95is allowed to be NULL, in which case this function will return a
96pointer to the section descriptor at index 1.
97If no further sections are present, function
98.Fn elf_nextscn
99will return a NULL pointer.
100.Sh RETURN VALUES
101Functions
102.Fn elf_getscn ,
103.Fn elf_newscn
104and
105.Fn elf_nextscn
106return a valid pointer to a section descriptor if successful, or
107NULL if an error occurs.
108.Pp
109Function
110.Fn elf_ndxscn
111returns a valid section table index if successful, or
112.Dv SHN_UNDEF
113if an error occurs.
114.Sh ERRORS
115These functions may fail with the following errors:
116.Bl -tag -width "[ELF_E_RESOURCE]"
117.It Bq Er ELF_E_ARGUMENT
118Arguments
119.Ar elf
120or
121.Ar scn
122were NULL.
123.It Bq Er ELF_E_ARGUMENT
124Argument
125.Ar index
126exceeded the current number of sections in the ELF object.
127.It Bq Er ELF_E_ARGUMENT
128Argument
129.Ar elf
130was not a descriptor for an ELF file.
131.It Bq Er ELF_E_ARGUMENT
132Section descriptor
133.Ar scn
134was not associated with ELF descriptor
135.Ar elf .
136.It Bq Er ELF_E_CLASS
137Descriptor
138.Ar elf
139was of an unknown ELF class.
140.It Bq Er ELF_E_SECTION
141Argument
142.Ar elf
143specified extended section numbering in the ELF header with the section header at
144index
145.Dv SHN_UNDEF
146not being of type
147.Dv SHT_NULL .
148.El
149.Sh SEE ALSO
150.Xr elf 3 ,
151.Xr elf_flagdata 3 ,
152.Xr elf_flagscn 3 ,
153.Xr elf_getdata 3 ,
154.Xr elf_getshdr 3 ,
155.Xr gelf 3
156