1elf_getident(3ELF) ELF Library Functions elf_getident(3ELF)
2
3
4
6 elf_getident, elf_getphdrnum, elf_getshdrnum, elf_getshdrstrndx,
7 elf_getphnum, elf_getshnum, elf_getshstrndx - retrieve ELF header data
8
10 cc [ flag ... ] file ... -lelf [ library ... ]
11 #include <libelf.h>
12
13 char *elf_getident(Elf *elf, size_t *dst);
14
15
16 int elf_getphdrnum(Elf *elf, size_t *dst);
17
18
19 int elf_getshdrnum(Elf *elf, size_t *dst);
20
21
22 int elf_getshdrstrndx(Elf *elf, size_t *dst);
23
24
25 Obsolete Interfaces
26 int elf_getphnum(Elf *elf, size_t *dst);
27
28
29 int elf_getshnum(Elf *elf, size_t *dst);
30
31
32 int elf_getshstrndx(Elf *elf, size_t *dst);
33
34
36 As elf(3ELF) explains, ELF provides a framework for various classes of
37 files, where basic objects might have 32 or 64 bits. To accommodate
38 these differences, without forcing the larger sizes on smaller
39 machines, the initial bytes in an ELF file hold identification informa‐
40 tion common to all file classes. The e_ident of every ELF header has
41 EI_NIDENT bytes with interpretations described in the following table.
42
43
44
45
46 e_ident Index Value Purpose
47
48 EI_MAG0 ELFMAG0 File identification
49 EI_MAG1 ELFMAG1
50 EI_MAG2 ELFMAG2
51 EI_MAG3 ELFMAG3
52
53 EI_CLASS ELFCLASSNONE File class
54 ELFCLASS32
55 ELFCLASS64
56
57 EI_DATA ELFDATANONE Data encoding
58 ELFDATA2LSB
59 ELFDATA2MSB
60
61 EI_VERSION EV_CURRENT File version
62
63 7-15 0 Unused, set to zero
64
65
66
67 Other kinds of files might have identification data, though they would
68 not conform to e_ident. See elf_kind(3ELF) for information on other
69 kinds of files.
70
71
72 The elf_getident() function returns a pointer to the initial bytes of
73 the file. If the library recognizes the file, a conversion from the
74 file image to the memory image can occur. The identification bytes are
75 guaranteed to be unmodified, though the size of the unmodified area
76 depends on the file type. If the dst argument is non-null, the library
77 stores the number of identification bytes in the location to which dst
78 points. If no data are present, elf is NULL, or an error occurs, the
79 return value is a null pointer, with 0 stored through dst, if dst is
80 non-null.
81
82
83 The elf_getphdrnum() function obtains the number of program headers
84 recorded in the ELF file. The number of sections in a file is typically
85 recorded in the e_phnum field of the ELF header. A file that requires
86 the ELF extended program header records the value PN_XNUM in the
87 e_phnum field and records the number of sections in the sh_info field
88 of section header 0. See USAGE. The dst argument points to the location
89 where the number of sections is stored. If elf is NULL or an error
90 occurs, elf_getphdrnum() returns −1.
91
92
93 The elf_getshdrnum() function obtains the number of sections recorded
94 in the ELF file. The number of sections in a file is typically recorded
95 in the e_shnum field of the ELF header. A file that requires ELF
96 extended section records the value 0 in the e_shnum field and records
97 the number of sections in the sh_size field of section header 0. See
98 USAGE. The dst argument points to the location where the number of sec‐
99 tions is stored. If a call to elf_newscn(3ELF) that uses the same elf
100 descriptor is performed, the value obtained by elf_getshnum() is valid
101 only after a successful call to elf_update(3ELF). If elf is NULL or an
102 error occurs, elf_getshdrnum() returns −1.
103
104
105 The elf_getshdrstrndx() function obtains the section index of the
106 string table associated with the section headers in the ELF file. The
107 section header string table index is typically recorded in the
108 e_shstrndx field of the ELF header. A file that requires ELF extended
109 section records the value SHN_XINDEX in the e_shstrndx field and
110 records the string table index in the sh_link field of section header
111 0. See USAGE. The dst argument points to the location where the section
112 header string table index is stored. If elf is NULL or an error occurs,
113 elf_getshdrstrndx() returns −1.
114
115
116 The elf_getphnum(), elf_getshnum(), and elf_getshstrndx() functions
117 behave in a manner similar to elf_getphdrnum(), elf_getshdrnum(), and
118 elf_getshdrstrndx(), respectively, except that they return 0 if elf is
119 NULL or an error occurs. Because these return values differ from those
120 used by some other systems, they are therefore non-portable and their
121 use is discouraged. The elf_getphdrnum(), elf_getshdrnum(), and
122 elf_getshdrstrndx() functions should be used instead.
123
125 ELF extended sections allow an ELF file to contain more than 0xff00
126 (SHN_LORESERVE) section. ELF extended program headers allow an ELF file
127 to contain 0xffff (PN_XNUM) or more program headers. See the Linker and
128 Libraries Guide for more information.
129
131 Upon successful completion, the elf_getident() function returns 1. Oth‐
132 erwise, it return 0.
133
134
135 Upon successful completion, the elf_getphdrnum(), elf_getshdrnum(), and
136 elf_getshdrstrndx() functions return 0. Otherwise, they return -1.
137
138
139 Upon successful completion, the elf_getphnum(), elf_getshnum(), and
140 elf_getshstrndx() functions return 1. Otherwise, they return 0.
141
143 See attributes(5) for descriptions of the following attributes:
144
145
146
147
148 ┌─────────────────────────────┬─────────────────────────────┐
149 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
150 ├─────────────────────────────┼─────────────────────────────┤
151 │Interface Stability │See below. │
152 ├─────────────────────────────┼─────────────────────────────┤
153 │MT-Level │MT-Safe │
154 └─────────────────────────────┴─────────────────────────────┘
155
156
157 The elf_getident(), elf_getphdrnum(), elf_getshdrnum(), and elf_get‐
158 shdrstrndx() functions are Committed. The elf_getphnum(), elf_get‐
159 shnum(), and elf_getshstrndx() functions are Committed (Obsolete).
160
162 elf(3ELF), elf32_getehdr(3ELF), elf_begin(3ELF), elf_kind(3ELF),
163 elf_newscn(3ELF), elf_rawfile(3ELF), elf_update(3ELF), libelf(3LIB),
164 attributes(5)
165
166
167 Linker and Libraries Guide
168
169
170
171SunOS 5.11 18 Jun 2009 elf_getident(3ELF)