xref: /illumos-gate/usr/src/uts/common/sys/machelf.h (revision 46b592853d0f4f11781b6b0a7533f267c6aee132)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_MACHELF_H
28 #define	_SYS_MACHELF_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #if defined(__amd64) || (defined(__i386) && defined(_ELF64))
35 #include <sys/elf_amd64.h>
36 #elif defined(__i386)
37 #include <sys/elf_386.h>
38 #elif defined(__sparc)
39 #include <sys/elf_SPARC.h>
40 #endif
41 #ifndef	_ASM
42 #include <sys/types.h>
43 #include <sys/elf.h>
44 #include <sys/link.h>	/* for Elf*_Dyn */
45 #endif	/* _ASM */
46 
47 /*
48  * Make machine class dependent data types transparent to the common code
49  */
50 #if defined(_ELF64) && !defined(_ELF32_COMPAT)
51 
52 #ifndef	_ASM
53 typedef	Elf64_Xword	Xword;
54 typedef	Elf64_Lword	Lword;
55 typedef	Elf64_Sxword	Sxword;
56 typedef	Elf64_Word	Word;
57 typedef	Elf64_Sword	Sword;
58 typedef	Elf64_Half	Half;
59 typedef	Elf64_Addr	Addr;
60 typedef	Elf64_Off	Off;
61 typedef	uchar_t		Byte;
62 #endif	/* _ASM */
63 
64 #if defined(_KERNEL)
65 #define	ELF_R_TYPE	ELF64_R_TYPE
66 #define	ELF_R_SYM	ELF64_R_SYM
67 #define	ELF_R_TYPE_DATA ELF64_R_TYPE_DATA
68 #define	ELF_R_INFO	ELF64_R_INFO
69 #define	ELF_ST_BIND	ELF64_ST_BIND
70 #define	ELF_ST_TYPE	ELF64_ST_TYPE
71 #define	ELF_M_SYM	ELF64_M_SYM
72 #define	ELF_M_SIZE	ELF64_M_SIZE
73 #endif
74 
75 #ifndef	_ASM
76 typedef	Elf64_Ehdr	Ehdr;
77 typedef	Elf64_Shdr	Shdr;
78 typedef	Elf64_Sym	Sym;
79 typedef	Elf64_Syminfo	Syminfo;
80 typedef	Elf64_Rela	Rela;
81 typedef	Elf64_Rel	Rel;
82 typedef	Elf64_Nhdr	Nhdr;
83 typedef	Elf64_Phdr	Phdr;
84 typedef	Elf64_Dyn	Dyn;
85 typedef	Elf64_Boot	Boot;
86 typedef	Elf64_Verdef	Verdef;
87 typedef	Elf64_Verdaux	Verdaux;
88 typedef	Elf64_Verneed	Verneed;
89 typedef	Elf64_Vernaux	Vernaux;
90 typedef	Elf64_Versym	Versym;
91 typedef	Elf64_Move	Move;
92 typedef	Elf64_Cap	Cap;
93 #endif	/* _ASM */
94 
95 #else	/* _ILP32 */
96 
97 #ifndef	_ASM
98 typedef	Elf32_Word	Xword;	/* Xword/Sxword are 32-bits in Elf32 */
99 typedef	Elf32_Lword	Lword;
100 typedef	Elf32_Sword	Sxword;
101 typedef	Elf32_Word	Word;
102 typedef	Elf32_Sword	Sword;
103 typedef	Elf32_Half	Half;
104 typedef	Elf32_Addr	Addr;
105 typedef	Elf32_Off	Off;
106 typedef	uchar_t		Byte;
107 #endif	/* _ASM */
108 
109 #if defined(_KERNEL)
110 #define	ELF_R_TYPE	ELF32_R_TYPE
111 #define	ELF_R_SYM	ELF32_R_SYM
112 #define	ELF_R_TYPE_DATA(x)	(0)
113 #define	ELF_R_INFO	ELF32_R_INFO
114 #define	ELF_ST_BIND	ELF32_ST_BIND
115 #define	ELF_ST_TYPE	ELF32_ST_TYPE
116 #define	ELF_M_SYM	ELF32_M_SYM
117 #define	ELF_M_SIZE	ELF32_M_SIZE
118 #endif
119 
120 #ifndef	_ASM
121 typedef	Elf32_Ehdr	Ehdr;
122 typedef	Elf32_Shdr	Shdr;
123 typedef	Elf32_Sym	Sym;
124 typedef	Elf32_Syminfo	Syminfo;
125 typedef	Elf32_Rela	Rela;
126 typedef	Elf32_Rel	Rel;
127 typedef	Elf32_Nhdr	Nhdr;
128 typedef	Elf32_Phdr	Phdr;
129 typedef	Elf32_Dyn	Dyn;
130 typedef	Elf32_Boot	Boot;
131 typedef	Elf32_Verdef	Verdef;
132 typedef	Elf32_Verdaux	Verdaux;
133 typedef	Elf32_Verneed	Verneed;
134 typedef	Elf32_Vernaux	Vernaux;
135 typedef	Elf32_Versym	Versym;
136 typedef	Elf32_Move	Move;
137 typedef	Elf32_Cap	Cap;
138 #endif	/* _ASM */
139 
140 #endif	/* _ILP32 */
141 
142 /*
143  * Elf `printf' type-cast macros.  These force arguments to be a fixed size
144  * so that Elf32 and Elf64 can share common format strings.
145  */
146 #ifndef	__lint
147 #define	EC_ADDR(a)	((Elf64_Addr)(a))		/* "ull" */
148 #define	EC_OFF(a)	((Elf64_Off)(a))		/* "ull"  */
149 #define	EC_HALF(a)	((Elf64_Half)(a))		/* "d"   */
150 #define	EC_WORD(a)	((Elf64_Word)(a))		/* "u"   */
151 #define	EC_SWORD(a)	((Elf64_Sword)(a))		/* "d"   */
152 #define	EC_XWORD(a)	((Elf64_Xword)(a))		/* "ull" */
153 #define	EC_SXWORD(a)	((Elf64_Sxword)(a))		/* "ll"  */
154 #define	EC_LWORD(a)	((Elf64_Lword)(a))		/* "ull" */
155 
156 /*
157  * A native pointer is special.  Although it can be convenient to display
158  * these from a common format (ull), compilers may flag the cast of a pointer
159  * to an integer as illegal.  Casting these pointers to the native pointer
160  * size, suppresses any compiler errors.
161  */
162 #define	EC_NATPTR(a)	((Elf64_Xword)(uintptr_t)(a))	/* "ull" */
163 #else
164 #define	EC_ADDR(a)	((u_longlong_t)(a))
165 #define	EC_OFF(a)	((u_longlong_t)(a))
166 #define	EC_HALF(a)	((ushort_t)(a))
167 #define	EC_WORD(a)	((uint_t)(a))
168 #define	EC_SWORD(a)	((int)(a))
169 #define	EC_XWORD(a)	((u_longlong_t)(a))
170 #define	EC_SXWORD(a)	((longlong_t)(a))
171 #define	EC_LWORD(a)	((u_longlong_t)(a))
172 
173 #define	EC_NATPTR(a)	((u_longlong_t)(a))
174 #endif
175 
176 #ifdef	__cplusplus
177 }
178 #endif
179 
180 #endif	/* _SYS_MACHELF_H */
181