aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libspl/include/sys/machelf.h
blob: f4c5c356f12adbd09e0cc6abdee3df444252c4bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * CDDL HEADER START
 *
 * 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.
 *
 * 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.
 *
 * 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]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_SYS_MACHELF_H
#define	_SYS_MACHELF_H

#ifdef	__cplusplus
extern "C" {
#endif

#if defined(__amd64)
#include <sys/elf_amd64.h>
#elif defined(__i386)
#include <sys/elf_386.h>
#elif defined(__sparc)
#include <sys/elf_SPARC.h>
#endif
#ifndef	_ASM
#include <sys/types.h>
#include <sys/elf.h>
#include <sys/link.h>	/* for Elf*_Dyn */
#endif	/* _ASM */

/*
 * Make machine class dependent data types transparent to the common code
 */
#if defined(_ELF64) && !defined(_ELF32_COMPAT)

#ifndef	_ASM
typedef	Elf64_Xword	Xword;
typedef	Elf64_Lword	Lword;
typedef	Elf64_Sxword	Sxword;
typedef	Elf64_Word	Word;
typedef	Elf64_Sword	Sword;
typedef	Elf64_Half	Half;
typedef	Elf64_Addr	Addr;
typedef	Elf64_Off	Off;
typedef	uchar_t		Byte;
#endif	/* _ASM */

#if defined(_KERNEL)
#define	ELF_R_TYPE	ELF64_R_TYPE
#define	ELF_R_SYM	ELF64_R_SYM
#define	ELF_R_TYPE_DATA ELF64_R_TYPE_DATA
#define	ELF_R_INFO	ELF64_R_INFO
#define	ELF_ST_BIND	ELF64_ST_BIND
#define	ELF_ST_TYPE	ELF64_ST_TYPE
#define	ELF_M_SYM	ELF64_M_SYM
#define	ELF_M_SIZE	ELF64_M_SIZE
#endif

#ifndef	_ASM
typedef	Elf64_Ehdr	Ehdr;
typedef	Elf64_Shdr	Shdr;
typedef	Elf64_Sym	Sym;
typedef	Elf64_Syminfo	Syminfo;
typedef	Elf64_Rela	Rela;
typedef	Elf64_Rel	Rel;
typedef	Elf64_Nhdr	Nhdr;
typedef	Elf64_Phdr	Phdr;
typedef	Elf64_Dyn	Dyn;
typedef	Elf64_Boot	Boot;
typedef	Elf64_Verdef	Verdef;
typedef	Elf64_Verdaux	Verdaux;
typedef	Elf64_Verneed	Verneed;
typedef	Elf64_Vernaux	Vernaux;
typedef	Elf64_Versym	Versym;
typedef	Elf64_Move	Move;
typedef	Elf64_Cap	Cap;
#endif	/* _ASM */

#else	/* _ILP32 */

#ifndef	_ASM
typedef	Elf32_Word	Xword;	/* Xword/Sxword are 32-bits in Elf32 */
typedef	Elf32_Lword	Lword;
typedef	Elf32_Sword	Sxword;
typedef	Elf32_Word	Word;
typedef	Elf32_Sword	Sword;
typedef	Elf32_Half	Half;
typedef	Elf32_Addr	Addr;
typedef	Elf32_Off	Off;
typedef	uchar_t		Byte;
#endif	/* _ASM */

#if defined(_KERNEL)
#define	ELF_R_TYPE	ELF32_R_TYPE
#define	ELF_R_SYM	ELF32_R_SYM
#define	ELF_R_TYPE_DATA(x)	(0)
#define	ELF_R_INFO	ELF32_R_INFO
#define	ELF_ST_BIND	ELF32_ST_BIND
#define	ELF_ST_TYPE	ELF32_ST_TYPE
#define	ELF_M_SYM	ELF32_M_SYM
#define	ELF_M_SIZE	ELF32_M_SIZE
#endif

#ifndef	_ASM
typedef	Elf32_Ehdr	Ehdr;
typedef	Elf32_Shdr	Shdr;
typedef	Elf32_Sym	Sym;
typedef	Elf32_Syminfo	Syminfo;
typedef	Elf32_Rela	Rela;
typedef	Elf32_Rel	Rel;
typedef	Elf32_Nhdr	Nhdr;
typedef	Elf32_Phdr	Phdr;
typedef	Elf32_Dyn	Dyn;
typedef	Elf32_Boot	Boot;
typedef	Elf32_Verdef	Verdef;
typedef	Elf32_Verdaux	Verdaux;
typedef	Elf32_Verneed	Verneed;
typedef	Elf32_Vernaux	Vernaux;
typedef	Elf32_Versym	Versym;
typedef	Elf32_Move	Move;
typedef	Elf32_Cap	Cap;
#endif	/* _ASM */

#endif	/* _ILP32 */

/*
 * Elf `printf' type-cast macros.  These force arguments to be a fixed size
 * so that Elf32 and Elf64 can share common format strings.
 */
#ifndef	__lint
#define	EC_ADDR(a)	((Elf64_Addr)(a))		/* "ull" */
#define	EC_OFF(a)	((Elf64_Off)(a))		/* "ull"  */
#define	EC_HALF(a)	((Elf64_Half)(a))		/* "d"   */
#define	EC_WORD(a)	((Elf64_Word)(a))		/* "u"   */
#define	EC_SWORD(a)	((Elf64_Sword)(a))		/* "d"   */
#define	EC_XWORD(a)	((Elf64_Xword)(a))		/* "ull" */
#define	EC_SXWORD(a)	((Elf64_Sxword)(a))		/* "ll"  */
#define	EC_LWORD(a)	((Elf64_Lword)(a))		/* "ull" */

/*
 * A native pointer is special.  Although it can be convenient to display
 * these from a common format (ull), compilers may flag the cast of a pointer
 * to an integer as illegal.  Casting these pointers to the native pointer
 * size, suppresses any compiler errors.
 */
#define	EC_NATPTR(a)	((Elf64_Xword)(uintptr_t)(a))	/* "ull" */
#else
#define	EC_ADDR(a)	((u_longlong_t)(a))
#define	EC_OFF(a)	((u_longlong_t)(a))
#define	EC_HALF(a)	((ushort_t)(a))
#define	EC_WORD(a)	((uint_t)(a))
#define	EC_SWORD(a)	((int)(a))
#define	EC_XWORD(a)	((u_longlong_t)(a))
#define	EC_SXWORD(a)	((longlong_t)(a))
#define	EC_LWORD(a)	((u_longlong_t)(a))

#define	EC_NATPTR(a)	((u_longlong_t)(a))
#endif

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_MACHELF_H */