summaryrefslogtreecommitdiff
path: root/usr/src/man/man3elf/elf_getscn.3elf
blob: bd65b6b0233e37ff5ba7ccab9e44c49dc2027ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'\" te
.\"  Copyright 1989 AT&T  Copyright (c) 2001, Sun Microsystems, Inc.  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH ELF_GETSCN 3ELF "Jul 11, 2001"
.SH NAME
elf_getscn, elf_ndxscn, elf_newscn, elf_nextscn \- get section information
.SH SYNOPSIS
.LP
.nf
cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ]
#include <libelf.h>

\fBElf_Scn *\fR\fBelf_getscn\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIindex\fR);
.fi

.LP
.nf
\fBsize_t\fR \fBelf_ndxscn\fR(\fBElf_Scn *\fR\fIscn\fR);
.fi

.LP
.nf
\fBElf_Scn *\fR\fBelf_newscn\fR(\fBElf *\fR\fIelf\fR);
.fi

.LP
.nf
\fBElf_Scn *\fR\fBelf_nextscn\fR(\fBElf *\fR\fIelf\fR, \fBElf_Scn *\fR\fIscn\fR);
.fi

.SH DESCRIPTION
.sp
.LP
These functions provide indexed and sequential access to the sections
associated with the \fBELF\fR descriptor \fIelf\fR. If the program is building
a new file, it is responsible for creating the file's \fBELF\fR header before
creating sections; see \fBelf32_getehdr\fR(3ELF).
.sp
.LP
The \fBelf_getscn()\fR function returns a section descriptor, given an
\fIindex\fR into the file's section header table. Note that the first ``real''
section has an index of \fB1\fR. Although a program can get a section
descriptor for the section whose \fIindex\fR is \fB0\fR (\fBSHN_UNDEF\fR, the
undefined section), the section has no data and the section header is ``empty''
(though present). If the specified section does not exist, an error occurs, or
\fIelf\fR is \fINULL\fR, \fBelf_getscn()\fR returns a null pointer.
.sp
.LP
The \fBelf_newscn()\fR function creates a new section and appends it to the
list for \fIelf\fR. Because the \fBSHN_UNDEF\fR section is required and not
``interesting'' to applications, the library creates it automatically. Thus the
first call to \fBelf_newscn()\fR for an \fBELF\fR descriptor with no existing
sections returns a descriptor for section 1. If an error occurs or \fIelf\fR is
\fINULL\fR, \fBelf_newscn()\fR returns a null pointer.
.sp
.LP
After creating a new section descriptor, the program can use
\fBelf32_getshdr()\fR to retrieve the newly created, ``clean'' section header.
The new section descriptor will have no associated data (see
\fBelf_getdata\fR(3ELF)). When creating a new section in this way, the library
updates the \fBe_shnum\fR member of the \fBELF\fR header and sets the
\fBELF_F_DIRTY\fR bit for the section (see \fBelf_flagdata\fR(3ELF)). If the
program is building a new file, it is responsible for creating the file's
\fBELF\fR header (see \fBelf32_getehdr\fR(3ELF)) before creating new sections.
.sp
.LP
The \fBelf_nextscn()\fR function takes an existing section descriptor,
\fIscn\fR, and returns a section descriptor for the next higher section. One
may use a null \fIscn\fR to obtain a section descriptor for the section whose
index is \fB1\fR (skipping the section whose index is \fBSHN_UNDEF\fR). If no
further sections are present or an error occurs, \fBelf_nextscn()\fR returns a
null pointer.
.sp
.LP
The \fBelf_ndxscn()\fR function takes an existing section descriptor,
\fIscn\fR, and returns its section table index. If \fIscn\fR is null or an
error occurs, \fBelf_ndxscn()\fR returns \fBSHN_UNDEF\fR.
.SH EXAMPLES
.LP
\fBExample 1 \fRA sample of calling \fBelf_getscn()\fR function.
.sp
.LP
An example of sequential access appears below. Each pass through the loop
processes the next section in the file; the loop terminates when all sections
have been processed.

.sp
.in +2
.nf
\fBscn = 0;
while ((scn = elf_nextscn(elf, scn)) != 0)
{
	/* process section */
}\fR
.fi
.in -2

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Stable
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
\fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), \fBelf32_getshdr\fR(3ELF),
\fBelf_begin\fR(3ELF), \fBelf_flagdata\fR(3ELF), \fBelf_getdata\fR(3ELF),
\fBlibelf\fR(3LIB), \fBattributes\fR(5)