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