xref: /illumos-gate/usr/src/head/gelf.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_GELF_H
28 #define	_GELF_H
29 
30 #include <sys/feature_tests.h>
31 
32 #include <libelf.h>
33 #include <sys/link.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 
40 #if !defined(_INT64_TYPE)
41 #error "64-bit integer types are required by gelf."
42 #endif
43 
44 /*
45  * Class-independent ELF API for Elf utilities.  This is
46  * for manipulating Elf32 and Elf64 specific information
47  * in a format common to both classes.
48  */
49 
50 typedef Elf64_Addr	GElf_Addr;
51 typedef Elf64_Half	GElf_Half;
52 typedef Elf64_Off	GElf_Off;
53 typedef Elf64_Sword	GElf_Sword;
54 typedef Elf64_Sxword	GElf_Sxword;
55 typedef Elf64_Word	GElf_Word;
56 typedef Elf64_Xword	GElf_Xword;
57 
58 typedef Elf64_Ehdr	GElf_Ehdr;
59 typedef	Elf64_Move	GElf_Move;
60 typedef Elf64_Phdr	GElf_Phdr;
61 typedef Elf64_Shdr	GElf_Shdr;
62 typedef Elf64_Sym	GElf_Sym;
63 typedef	Elf64_Syminfo	GElf_Syminfo;
64 typedef Elf64_Rela	GElf_Rela;
65 typedef Elf64_Rel	GElf_Rel;
66 typedef Elf64_Dyn	GElf_Dyn;
67 typedef Elf64_Cap	GElf_Cap;
68 
69 /*
70  * The processing of versioning information can stay the
71  * same because both the Elf32 and Elf64 structures are
72  * of equal sizes.
73  */
74 typedef Elf64_Verdef	GElf_Verdef;
75 typedef Elf64_Verdaux	GElf_Verdaux;
76 typedef Elf64_Verneed	GElf_Verneed;
77 typedef Elf64_Vernaux	GElf_Vernaux;
78 typedef Elf64_Versym	GElf_Versym;
79 
80 /*
81  * move.m_info is encoded using the 64bit fields in Gelf.
82  */
83 #define	GELF_M_SYM	ELF64_M_SYM
84 #define	GELF_M_SIZE	ELF64_M_SIZE
85 
86 /*
87  * sym.st_info field is same size for Elf32 and Elf64.
88  */
89 #define	GELF_ST_BIND	ELF64_ST_BIND
90 #define	GELF_ST_TYPE	ELF64_ST_TYPE
91 #define	GELF_ST_INFO	ELF64_ST_INFO
92 
93 
94 /*
95  * Elf64 r_info may have data field in type id's word,
96  * so GELF_R_TYPE is defined as ELF64_R_TYPE_ID in order
97  * to isolate the proper bits for the true type id.
98  */
99 #define	GELF_R_TYPE		ELF64_R_TYPE_ID
100 #define	GELF_R_SYM		ELF64_R_SYM
101 #define	GELF_R_INFO		ELF64_R_INFO
102 #define	GELF_R_TYPE_DATA	ELF64_R_TYPE_DATA
103 #define	GELF_R_TYPE_ID		ELF64_R_TYPE_ID
104 #define	GELF_R_TYPE_INFO	ELF64_R_TYPE_INFO
105 
106 
107 
108 int		gelf_getclass(Elf*);
109 size_t		gelf_fsize(Elf *, Elf_Type, size_t, uint_t);
110 GElf_Ehdr *	gelf_getehdr(Elf *, GElf_Ehdr *);
111 int		gelf_update_ehdr(Elf *, GElf_Ehdr *);
112 unsigned long	gelf_newehdr(Elf *, int);
113 GElf_Phdr *	gelf_getphdr(Elf *, int, GElf_Phdr *);
114 int		gelf_update_phdr(Elf *, int, GElf_Phdr *);
115 unsigned long	gelf_newphdr(Elf *, size_t);
116 GElf_Shdr *	gelf_getshdr(Elf_Scn *,  GElf_Shdr *);
117 int		gelf_update_shdr(Elf_Scn *, GElf_Shdr *);
118 Elf_Data *	gelf_xlatetof(Elf *, Elf_Data *, const Elf_Data *, uint_t);
119 Elf_Data *	gelf_xlatetom(Elf *, Elf_Data *, const Elf_Data *, uint_t);
120 GElf_Sym *	gelf_getsym(Elf_Data *, int, GElf_Sym *);
121 int		gelf_update_sym(Elf_Data *, int, GElf_Sym *);
122 GElf_Sym *	gelf_getsymshndx(Elf_Data *, Elf_Data *, int, GElf_Sym *,
123 		    Elf32_Word *);
124 int		gelf_update_symshndx(Elf_Data *, Elf_Data *, int, GElf_Sym *,
125 		    Elf32_Word);
126 GElf_Syminfo *	gelf_getsyminfo(Elf_Data *, int, GElf_Syminfo *);
127 int		gelf_update_syminfo(Elf_Data *, int, GElf_Syminfo *);
128 GElf_Move *	gelf_getmove(Elf_Data *, int, GElf_Move *);
129 int		gelf_update_move(Elf_Data *, int, GElf_Move *);
130 GElf_Dyn *	gelf_getdyn(Elf_Data *, int, GElf_Dyn *);
131 int		gelf_update_dyn(Elf_Data *, int, GElf_Dyn *);
132 GElf_Rela *	gelf_getrela(Elf_Data *, int, GElf_Rela *);
133 int		gelf_update_rela(Elf_Data *, int, GElf_Rela *);
134 GElf_Rel *	gelf_getrel(Elf_Data *, int, GElf_Rel *);
135 int		gelf_update_rel(Elf_Data *, int, GElf_Rel *);
136 long		gelf_checksum(Elf *);
137 GElf_Cap *	gelf_getcap(Elf_Data *, int, GElf_Cap *);
138 int		gelf_update_cap(Elf_Data *, int, GElf_Cap *);
139 
140 
141 #ifdef	__cplusplus
142 }
143 #endif
144 
145 #endif	/* _GELF_H */
146