2 .\" Copyright (c) 2004, Sun Microsystems, Inc., All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH GELF 3ELF "Jun 8, 2004"
8 gelf, gelf_checksum, gelf_fsize, gelf_getcap, gelf_getclass, gelf_getdyn,
9 gelf_getehdr, gelf_getmove, gelf_getphdr, gelf_getrel, gelf_getrela,
10 gelf_getshdr, gelf_getsym, gelf_getsyminfo, gelf_getsymshndx, gelf_newehdr,
11 gelf_newphdr, gelf_update_cap, gelf_update_dyn, gelf_update_ehdr,
12 gelf_update_getmove, gelf_update_move, gelf_update_phdr, gelf_update_rel,
13 gelf_update_rela, gelf_update_shdr, gelf_update_sym, gelf_update_symshndx,
14 gelf_update_syminfo, gelf_xlatetof, gelf_xlatetom \- generic class-independent
19 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB\(milelf\fR [ \fIlibrary\fR... ]
22 \fBlong\fR \fBgelf_checksum\fR(\fBElf *\fR\fIelf\fR);
27 \fBsize_t\fR \fBgelf_fsize\fR(\fBElf *\fR\fIelf\fR, \fBElf_Type\fR \fItype\fR, \fBsize_t\fR \fIcnt\fR, \fBunsigned\fR \fIver\fR);
32 \fBint\fR \fBgelf_getcap\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Cap *\fR\fIdst\fR);
37 \fBint\fR \fBgelf_getclass\fR(\fBElf *\fR\fIelf\fR);
42 \fBGElf_Dyn *\fR\fBgelf_getdyn\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Dyn *\fR\fIdst\fR);
47 \fBGElf_Ehdr *\fR\fBgelf_getehdr\fR(\fBElf *\fR\fIelf\fR, \fBGElf_Ehdr *\fR\fIdst\fR);
52 \fBGElf_Move *\fR\fBgelf_getmove\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Move *\fR\fIdst\fR);
57 \fBGElf_Phdr *\fR\fBgelf_getphdr\fR(\fBElf *\fR\fIelf\fR, \fBint\fR \fIndx\fR, \fBGElf_Phdr *\fR\fIdst\fR);
62 \fBGElf_Rel *\fR\fBgelf_getrel\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Rel *\fR\fIdst\fR);
67 \fBGElf_Rela *\fR\fBgelf_getrela\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Rela *\fR\fIdst\fR);
72 \fBGElf_Shdr *\fR\fBgelf_getshdr\fR(\fBElf_Scn *\fR\fIscn\fR, \fBGElf_Shdr *\fR\fIdst\fR);
77 \fBGElf_Sym *\fR\fBgelf_getsym\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Sym *\fR\fIdst\fR);
82 \fBGElf_Syminfo *\fR\fBgelf_getsyminfo\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Syminfo *\fR\fIdst\fR);
87 \fBGElf_Sym *\fR\fBgelf_getsymshndx\fR(\fBElf_Data *\fR\fIsymsrc\fR, \fBElf_Data *\fR\fIshndxsrc\fR,
88 \fBint\fR \fIndx\fR, \fBGElf_Sym *\fR\fIsymdst\fR, \fBElf32_Word *\fR\fIshndxdst\fR);
93 \fBunsigned long\fR \fBgelf_newehdr\fR(\fBElf *\fR\fIelf\fR, \fBint\fR \fIclass\fR);
98 \fBunsigned long\fR \fBgelf_newphdr\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIphnum\fR);
103 \fBint\fR \fBgelf_update_cap\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Cap *\fR\fIsrc\fR);
108 \fBint\fR \fBgelf_update_dyn\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Dyn *\fR\fIsrc\fR);
113 \fBint\fR \fBgelf_update_ehdr\fR(\fBElf *\fR\fIelf\fR, \fBGElf_Ehdr *\fR\fIsrc\fR);
118 \fBint\fR \fBgelf_update_move\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Move *\fR\fIsrc\fR);
123 \fBint\fR \fBgelf_update_phdr\fR(\fBElf *\fR\fIelf\fR, \fBint\fR \fIndx\fR, \fBGElf_Phdr *\fR\fIsrc\fR);
128 \fBint\fR \fBgelf_update_rel\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Rel *\fR\fIsrc\fR);
133 \fBint\fR \fBgelf_update_rela\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Rela *\fR\fIsrc\fR);
138 \fBint\fR \fBgelf_update_shdr\fR(\fBElf_Scn *\fR\fIdst\fR, \fBGElf_Shdr *\fR\fIsrc\fR);
143 \fBint\fR \fBgelf_update_sym\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Sym *\fR\fIsrc\fR);
148 \fBint\fR \fBgelf_update_syminfo\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Syminfo *\fR\fIsrc\fR);
153 \fBint\fR \fBgelf_update_symshndx\fR(\fBElf_Data *\fR\fIsymdst\fR, \fBElf_Data *\fR\fIshndxdst\fR, \fBint\fR \fIndx\fR,
154 \fBGElf_Sym *\fR\fIsymsrc\fR, \fBElf32_Word\fR \fIshndxsrc\fR);
159 \fBElf_Data *\fR\fBgelf_xlatetof\fR(\fBElf *\fR\fIelf\fR, \fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR,
160 \fBunsigned\fR \fIencode\fR);
165 \fBElf_Data *\fR\fBgelf_xlatetom\fR(\fBElf *\fR\fIelf\fR, \fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR,
166 \fBunsigned\fR \fIencode\fR);
172 \fBGElf\fR is a generic, \fBELF\fR class-independent \fBAPI\fR for manipulating
173 \fBELF\fR object files. \fBGElf\fR provides a single, common interface for
174 handling 32-bit and 64-bit \fBELF\fR format object files. \fBGElf\fR is a
175 translation layer between the application and the class-dependent parts of the
176 \fBELF\fR library. Thus, the application can use \fBGElf\fR, which in turn,
177 will call the corresponding \fBelf32_\fR or \fBelf64_\fR functions on behalf of
178 the application. The data structures returned are all large enough to hold
179 32-bit and 64-bit data.
182 \fBGElf\fR provides a simple, class-independent layer of indirection over the
183 class-dependent \fBELF32\fR and \fBELF64\fR \fBAPI\fR's. \fBGElf\fR is
184 stateless, and may be used along side the \fBELF32\fR and \fBELF64\fR
188 \fBGElf\fR always returns a copy of the underlying \fBELF32\fR or \fBELF64\fR
189 structure, and therefore the programming practice of using the address of an
190 \fBELF\fR header as the base offset for the \fBELF\fR's mapping into memory
191 should be avoided. Also, data accessed by type-casting the \fBElf_Data\fR
192 buffer to a class-dependent type and treating it like an array, for example, a
193 symbol table, will not work under \fBGElf\fR, and the \fBgelf_get\fR functions
194 must be used instead. See the EXAMPLE section.
197 Programs that create or modify \fBELF\fR files using \fBlibelf\fR(3LIB) need to
198 perform an extra step when using \fBGElf\fR. Modifications to \fBGElf\fR values
199 must be explicitly flushed to the underlying \fBELF32\fR or \fBELF64\fR
200 structures by way of the \fBgelf_update_\fR interfaces. Use of \fBelf_update\fR
201 or \fBelf_flagelf\fR and the like remains the same.
204 The sizes of versioning structures remain the same between \fBELF32\fR and
205 \fBELF64\fR. The \fBGElf\fR \fBAPI\fR only defines types for versioning, rather
206 than a functional \fBAPI\fR. The processing of versioning information will stay
207 the same in the \fBGElf\fR environment as it was in the class-dependent
208 \fBELF\fR environment.
209 .SS "List of Functions"
213 \fB\fBgelf_checksum()\fR\fR
216 An analog to \fBelf32_checksum\fR(3ELF) and \fBelf64_checksum\fR(3ELF).
222 \fB\fBgelf_fsize()\fR\fR
225 An analog to \fBelf32_fsize\fR(3ELF) and \fBelf64_fsize\fR(3ELF).
231 \fB\fBgelf_getcap()\fR\fR
234 Retrieves the \fBElf32_Cap\fR or \fBElf64_Cap\fR information from the
235 capability table at the given index. \fBdst\fR points to the location where the
236 \fBGElf_Cap\fR capability entry is stored.
242 \fB\fBgelf_getclass()\fR\fR
245 Returns one of the constants \fBELFCLASS32\fR, \fBELFCLASS64\fR or
252 \fB\fBgelf_getdyn()\fR\fR
255 Retrieves the \fBElf32_Dyn\fR or \fBElf64_Dyn\fR information from the dynamic
256 table at the given index. \fBdst\fR points to the location where the
257 \fBGElf_Dyn\fR dynamic entry is stored.
263 \fB\fBgelf_getehdr()\fR\fR
266 An analog to \fBelf32_getehdr\fR(3ELF) and \fBelf64_getehdr\fR(3ELF). \fBdst\fR
267 points to the location where the \fBGElf_Ehdr\fR header is stored.
273 \fB\fBgelf_getmove()\fR\fR
276 Retrieves the \fBElf32_Move\fR or \fBElf64_Move\fR information from the move
277 table at the given index. \fBdst\fR points to the location where the
278 \fBGElf_Move\fR move entry is stored.
284 \fB\fBgelf_getphdr()\fR\fR
287 An analog to\fBelf32_getphdr\fR(3ELF) and \fBelf64_getphdr\fR(3ELF). \fBdst\fR
288 points to the location where the \fBGElf_Phdr\fR program header is stored.
294 \fB\fBgelf_getrel()\fR\fR
297 Retrieves the \fBElf32_Rel\fR or \fBElf64_Rel\fR information from the
298 relocation table at the given index. \fBdst\fR points to the location where the
299 \fBGElf_Rel\fR relocation entry is stored.
305 \fB\fBgelf_getrela()\fR\fR
308 Retrieves the \fBElf32_Rela\fR or \fBElf64_Rela\fR information from the
309 relocation table at the given index. \fBdst\fR points to the location where the
310 \fBGElf_Rela\fR relocation entry is stored.
316 \fB\fBgelf_getshdr()\fR\fR
319 An analog to \fBelf32_getshdr\fR(3ELF) and \fBelf64_getshdr\fR(3ELF). \fBdst\fR
320 points to the location where the \fBGElf_Shdr\fR section header is stored.
326 \fB\fBgelf_getsym()\fR\fR
329 Retrieves the \fBElf32_Sym\fR or \fBElf64_Sym\fR information from the symbol
330 table at the given index. \fBdst\fR points to the location where the
331 \fBGElf_Sym\fR symbol entry is stored.
337 \fB\fBgelf_getsyminfo()\fR\fR
340 Retrieves the \fBElf32_Syminfo\fR or \fBElf64_Syminfo\fR information from the
341 relocation table at the given index. \fBdst\fR points to the location where the
342 \fBGElf_Syminfo\fR symbol information entry is stored.
348 \fB\fBgelf_getsymshndx()\fR\fR
351 Provides an extension to \fBgelf_getsym()\fR that retrieves the \fBElf32_Sym\fR
352 or \fBElf64_Sym\fR information, and the section index from the symbol table at
353 the given index \fIndx\fR.
355 The symbols section index is typically recorded in the \fBst_shndx\fR field of
356 the symbols structure. However, a file that requires \fBELF\fR Extended
357 Sections may record an \fBst_shndx\fR of \fBSHN_XINDEX\fR indicating that the
358 section index must be obtained from an associated \fBSHT_SYMTAB_SHNDX\fR
359 section entry. If \fIxshndx\fR and \fIshndxdata\fR are non-null, the value
360 recorded at index \fIndx\fR of the \fBSHT_SYMTAB_SHNDX\fR table pointed to by
361 \fIshndxdata\fR is returned in \fIxshndx\fR. See USAGE.
367 \fB\fBgelf_newehdr()\fR\fR
370 An analog to \fBelf32_newehdr\fR(3ELF) and \fBelf64_newehdr\fR(3ELF).
376 \fB\fBgelf_newphdr()\fR\fR
379 An analog to \fBelf32_newphdr\fR(3ELF) and \fBelf64_newphdr\fR(3ELF).
385 \fB\fBgelf_update_cap()\fR\fR
388 Copies the \fBGElf_Cap\fR information back into the underlying \fBElf32_Cap\fR
389 or \fBElf64_Cap\fR structure at the given index.
395 \fB\fBgelf_update_dyn()\fR\fR
398 Copies the \fBGElf_Dyn\fR information back into the underlying \fBElf32_Dyn\fR
399 or \fBElf64_Dyn\fR structure at the given index.
405 \fB\fBgelf_update_ehdr()\fR\fR
408 Copies the contents of the \fBGElf_Ehdr\fR \fBELF\fR header to the underlying
409 \fBElf32_Ehdr\fR or \fBElf64_Ehdr\fR structure.
415 \fB\fBgelf_update_move()\fR\fR
418 Copies the \fBGElf_Move\fR information back into the underlying
419 \fBElf32_Move\fR or \fBElf64_Move\fR structure at the given index.
425 \fB\fBgelf_update_phdr()\fR\fR
428 Copies of the contents of \fBGElf_Phdr\fR program header to underlying the
429 \fBElf32_Phdr\fR or \fBElf64_Phdr\fR structure.
435 \fB\fBgelf_update_rel()\fR\fR
438 Copies the \fBGElf_Rel\fR information back into the underlying \fBElf32_Rel\fR
439 or \fBElf64_Rel\fR structure at the given index.
445 \fB\fBgelf_update_rela()\fR\fR
448 Copies the \fBGElf_Rela\fR information back into the underlying
449 \fBElf32_Rela\fR or \fBElf64_Rela\fR structure at the given index.
455 \fB\fBgelf_update_shdr()\fR\fR
458 Copies of the contents of \fBGElf_Shdr\fR section header to underlying the
459 \fBElf32_Shdr\fR or \fBElf64_Shdr\fR structure.
465 \fB\fBgelf_update_sym()\fR\fR
468 Copies the \fBGElf_Sym\fR information back into the underlying \fBElf32_Sym\fR
469 or \fBElf64_Sym\fR structure at the given index.
475 \fB\fBgelf_update_syminfo()\fR\fR
478 Copies the \fBGElf_Syminfo\fR information back into the underlying
479 \fBElf32_Syminfo\fR or \fBElf64_Syminfo\fR structure at the given index.
485 \fB\fBgelf_update_symshndx()\fR\fR
488 Provides an extension to \fBgelf_update_sym()\fR that copies the \fBGElf_Sym\fR
489 information back into the \fBElf32_Sym\fR or \fBElf64_Sym\fR structure at the
490 given index \fIndx\fR, and copies the extended \fIxshndx\fR section index into
491 the \fBElf32_Word\fR at the given index \fIndx\fR in the buffer described by
492 \fBshndxdata\fR. See USAGE.
498 \fB\fBgelf_xlatetof()\fR\fR
501 An analog to \fBelf32_xlatetof\fR(3ELF) and \fBelf64_xlatetof\fR(3ELF)
507 \fB\fBgelf_xlatetom()\fR\fR
510 An analog to \fBelf32_xlatetom\fR(3ELF) and \fBelf64_xlatetom\fR(3ELF)
516 Upon failure, all \fBGElf\fR functions return \fB0\fR and set \fIelf_errno\fR.
517 See \fBelf_errno\fR(3ELF)
520 \fBExample 1 \fRPrinting the ELF Symbol Table
525 #include <sys/types.h>
526 #include <sys/stat.h>
532 main(int argc, char **argv)
540 elf_version(EV_CURRENT);
542 fd = open(argv[1], O_RDONLY);
543 elf = elf_begin(fd, ELF_C_READ, NULL);
545 while ((scn = elf_nextscn(elf, scn)) != NULL) {
546 gelf_getshdr(scn, &shdr);
547 if (shdr.sh_type == SHT_SYMTAB) {
548 /* found a symbol table, go print it. */
553 data = elf_getdata(scn, NULL);
554 count = shdr.sh_size / shdr.sh_entsize;
556 /* print the symbol names */
557 for (ii = 0; ii < count; ++ii) {
559 gelf_getsym(data, ii, &sym);
560 printf("%s\en", elf_strptr(elf, shdr.sh_link, sym.st_name));
571 ELF Extended Sections are employed to allow an ELF file to contain more than
572 \fB0xff00\fR (\fBSHN_LORESERVE\fR) section. See the \fILinker and Libraries
573 Guide\fR for more information.
578 \fB\fB/lib/libelf.so.1\fR\fR
587 \fB\fB/lib/64/libelf.so.1\fR\fR
596 See \fBattributes\fR(5) for descriptions of the following attributes:
604 ATTRIBUTE TYPE ATTRIBUTE VALUE
606 Interface Stability Stable
614 \fBelf\fR(3ELF), \fBelf32_checksum\fR(3ELF), \fBelf32_fsize\fR(3ELF),
615 \fBelf32_getehdr\fR(3ELF), \fBelf32_newehdr\fR(3ELF),
616 \fBelf32_getphdr\fR(3ELF), \fBelf32_newphdr\fR(3ELF),
617 \fBelf32_getshdr\fR(3ELF), \fBelf32_xlatetof\fR(3ELF),
618 \fBelf32_xlatetom\fR(3ELF), \fBelf_errno\fR(3ELF), \fBlibelf\fR(3LIB),
622 \fILinker and Libraries Guide\fR