xref: /netbsd-src/external/bsd/elftoolchain/dist/libelf/_libelf_config.h (revision 413d532bcc3f62d122e56d92e13ac64825a40baf)
1 /*	$NetBSD: _libelf_config.h,v 1.2 2014/03/09 16:58:04 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2008-2011 Joseph Koshy
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * Id: _libelf_config.h 2287 2011-12-04 06:45:47Z jkoshy
29  */
30 
31 #ifdef	__DragonFly__
32 
33 #if	defined(__amd64__)
34 #define	LIBELF_ARCH		EM_X86_64
35 #define	LIBELF_BYTEORDER	ELFDATA2LSB
36 #define	LIBELF_CLASS		ELFCLASS64
37 #elif	defined(__i386__)
38 #define	LIBELF_ARCH		EM_386
39 #define	LIBELF_BYTEORDER	ELFDATA2LSB
40 #define	LIBELF_CLASS		ELFCLASS32
41 #endif
42 
43 #endif	/* __DragonFly__ */
44 
45 #ifdef __FreeBSD__
46 
47 /*
48  * Define LIBELF_{ARCH,BYTEORDER,CLASS} based on the machine architecture.
49  * See also: <machine/elf.h>.
50  */
51 
52 #if	defined(__amd64__)
53 
54 #define	LIBELF_ARCH		EM_X86_64
55 #define	LIBELF_BYTEORDER	ELFDATA2LSB
56 #define	LIBELF_CLASS		ELFCLASS64
57 
58 #elif	defined(__arm__)
59 
60 #define	LIBELF_ARCH		EM_ARM
61 #if	defined(__ARMEB__)	/* Big-endian ARM. */
62 #define	LIBELF_BYTEORDER	ELFDATA2MSB
63 #else
64 #define	LIBELF_BYTEORDER	ELFDATA2LSB
65 #endif
66 #define	LIBELF_CLASS		ELFCLASS32
67 
68 #elif	defined(__i386__)
69 
70 #define	LIBELF_ARCH		EM_386
71 #define	LIBELF_BYTEORDER	ELFDATA2LSB
72 #define	LIBELF_CLASS		ELFCLASS32
73 
74 #elif	defined(__ia64__)
75 
76 #define	LIBELF_ARCH		EM_IA_64
77 #define	LIBELF_BYTEORDER	ELFDATA2LSB
78 #define	LIBELF_CLASS		ELFCLASS64
79 
80 #elif	defined(__mips__)
81 
82 #define	LIBELF_ARCH		EM_MIPS
83 #if	defined(__MIPSEB__)
84 #define	LIBELF_BYTEORDER	ELFDATA2MSB
85 #else
86 #define	LIBELF_BYTEORDER	ELFDATA2LSB
87 #endif
88 #define	LIBELF_CLASS		ELFCLASS32
89 
90 #elif	defined(__powerpc__)
91 
92 #define	LIBELF_ARCH		EM_PPC
93 #define	LIBELF_BYTEORDER	ELFDATA2MSB
94 #define	LIBELF_CLASS		ELFCLASS32
95 
96 #elif	defined(__sparc__)
97 
98 #define	LIBELF_ARCH		EM_SPARCV9
99 #define	LIBELF_BYTEORDER	ELFDATA2MSB
100 #define	LIBELF_CLASS		ELFCLASS64
101 
102 #else
103 #error	Unknown FreeBSD architecture.
104 #endif
105 #endif  /* __FreeBSD__ */
106 
107 /*
108  * Definitions for Minix3.
109  */
110 #ifdef __minix
111 
112 #define	LIBELF_ARCH		EM_386
113 #define	LIBELF_BYTEORDER	ELFDATA2LSB
114 #define	LIBELF_CLASS		ELFCLASS32
115 
116 #endif	/* __minix */
117 
118 #ifdef __NetBSD__
119 
120 #include <machine/elf_machdep.h>
121 
122 #if	!defined(ARCH_ELFSIZE)
123 #error	ARCH_ELFSIZE is not defined.
124 #endif
125 
126 #if	ARCH_ELFSIZE == 32
127 #define	LIBELF_ARCH		ELF32_MACHDEP_ID
128 #define	LIBELF_BYTEORDER	ELF32_MACHDEP_ENDIANNESS
129 #define	LIBELF_CLASS		ELFCLASS32
130 #define	Elf_Note		Elf32_Nhdr
131 #else
132 #define	LIBELF_ARCH		ELF64_MACHDEP_ID
133 #define	LIBELF_BYTEORDER	ELF64_MACHDEP_ENDIANNESS
134 #define	LIBELF_CLASS		ELFCLASS64
135 #define	Elf_Note		Elf64_Nhdr
136 #endif
137 
138 #endif	/* __NetBSD__ */
139 
140 #if defined(__OpenBSD__)
141 
142 #include <machine/exec.h>
143 
144 #define	LIBELF_ARCH		ELF_TARG_MACH
145 #define	LIBELF_BYTEORDER	ELF_TARG_DATA
146 #define	LIBELF_CLASS		ELF_TARG_CLASS
147 
148 #endif
149 
150 /*
151  * GNU & Linux compatibility.
152  *
153  * `__linux__' is defined in an environment runs the Linux kernel and glibc.
154  * `__GNU__' is defined in an environment runs a GNU kernel (Hurd) and glibc.
155  * `__GLIBC__' is defined for an environment that runs glibc over a non-GNU
156  *     kernel such as GNU/kFreeBSD.
157  */
158 
159 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
160 
161 #if defined(__linux__)
162 
163 #include "native-elf-format.h"
164 
165 #define	LIBELF_CLASS		ELFTC_CLASS
166 #define	LIBELF_ARCH		ELFTC_ARCH
167 #define	LIBELF_BYTEORDER	ELFTC_BYTEORDER
168 
169 #endif	/* defined(__linux__) */
170 
171 #if	LIBELF_CLASS == ELFCLASS32
172 #define	Elf_Note		Elf32_Nhdr
173 #elif   LIBELF_CLASS == ELFCLASS64
174 #define	Elf_Note		Elf64_Nhdr
175 #else
176 #error  LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64
177 #endif
178 
179 #endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */
180