1elf_getscn(3ELF)             ELF Library Functions            elf_getscn(3ELF)
2
3
4

NAME

6       elf_getscn,  elf_ndxscn, elf_newscn, elf_nextscn - get section informa‐
7       tion
8

SYNOPSIS

10       cc [ flag ... ] file ... -lelf [ library ... ]
11       #include <libelf.h>
12
13       Elf_Scn *elf_getscn(Elf *elf, size_t index);
14
15
16       size_t elf_ndxscn(Elf_Scn *scn);
17
18
19       Elf_Scn *elf_newscn(Elf *elf);
20
21
22       Elf_Scn *elf_nextscn(Elf *elf, Elf_Scn *scn);
23
24

DESCRIPTION

26       These functions provide indexed and sequential access to  the  sections
27       associated  with  the  ELF descriptor elf. If the program is building a
28       new file, it is responsible for creating the file's ELF  header  before
29       creating sections; see elf32_getehdr(3ELF).
30
31
32       The  elf_getscn() function returns a section descriptor, given an index
33       into the file's section header table. Note that the first ``real'' sec‐
34       tion has an index of 1. Although a program can get a section descriptor
35       for the section whose index is 0 (SHN_UNDEF,  the  undefined  section),
36       the  section  has  no  data and the section header is ``empty'' (though
37       present). If the specified section does not exist, an error occurs,  or
38       elf is NULL, elf_getscn() returns a null pointer.
39
40
41       The  elf_newscn()  function creates a new section and appends it to the
42       list for elf.  Because  the  SHN_UNDEF  section  is  required  and  not
43       ``interesting''  to applications, the library creates it automatically.
44       Thus the first call to elf_newscn()  for  an  ELF  descriptor  with  no
45       existing  sections  returns  a  descriptor  for  section 1. If an error
46       occurs or elf is NULL, elf_newscn() returns a null pointer.
47
48
49       After creating a new section descriptor, the program can use elf32_get‐
50       shdr() to retrieve the newly created, ``clean'' section header. The new
51       section  descriptor  will  have  no  associated  data   (see   elf_get‐
52       data(3ELF)).  When  creating  a  new  section  in this way, the library
53       updates the e_shnum member of the ELF header and sets  the  ELF_F_DIRTY
54       bit  for the section (see elf_flagdata(3ELF)). If the program is build‐
55       ing a new file, it is responsible for creating the  file's  ELF  header
56       (see elf32_getehdr(3ELF)) before creating new sections.
57
58
59       The  elf_nextscn()  function takes an existing section descriptor, scn,
60       and returns a section descriptor for the next higher section.  One  may
61       use  a  null  scn  to obtain a section descriptor for the section whose
62       index is 1 (skipping the section whose index is SHN_UNDEF). If no  fur‐
63       ther  sections  are present or an error occurs, elf_nextscn() returns a
64       null pointer.
65
66
67       The elf_ndxscn() function takes an existing  section  descriptor,  scn,
68       and returns its section table index. If scn is null or an error occurs,
69       elf_ndxscn() returns SHN_UNDEF.
70

EXAMPLES

72       Example 1 A sample of calling elf_getscn() function.
73
74
75       An example of sequential access appears below. Each  pass  through  the
76       loop  processes  the next section in the file; the loop terminates when
77       all sections have been processed.
78
79
80         scn = 0;
81         while ((scn = elf_nextscn(elf, scn)) != 0)
82         {
83              /* process section */
84         }
85
86

ATTRIBUTES

88       See attributes(5) for descriptions of the following attributes:
89
90
91
92
93       ┌─────────────────────────────┬─────────────────────────────┐
94       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
95       ├─────────────────────────────┼─────────────────────────────┤
96       │Interface Stability          │Stable                       │
97       ├─────────────────────────────┼─────────────────────────────┤
98       │MT-Level                     │MT-Safe                      │
99       └─────────────────────────────┴─────────────────────────────┘
100

SEE ALSO

102       elf(3ELF), elf32_getehdr(3ELF),  elf32_getshdr(3ELF),  elf_begin(3ELF),
103       elf_flagdata(3ELF), elf_getdata(3ELF), libelf(3LIB), attributes(5)
104
105
106
107SunOS 5.11                        11 Jul 2001                 elf_getscn(3ELF)
Impressum