1 /* $NetBSD: _libelf_config.h,v 1.3 2015/09/29 19:43:39 christos Exp $ */
4 * Copyright (c) 2008-2011 Joseph Koshy
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
28 * Id: _libelf_config.h 2287 2011-12-04 06:45:47Z jkoshy
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
43 #endif /* __DragonFly__ */
48 * Define LIBELF_{ARCH,BYTEORDER,CLASS} based on the machine architecture.
49 * See also: <machine/elf.h>.
52 #if defined(__amd64__)
54 #define LIBELF_ARCH EM_X86_64
55 #define LIBELF_BYTEORDER ELFDATA2LSB
56 #define LIBELF_CLASS ELFCLASS64
58 #elif defined(__arm__)
60 #define LIBELF_ARCH EM_ARM
61 #if defined(__ARMEB__) /* Big-endian ARM. */
62 #define LIBELF_BYTEORDER ELFDATA2MSB
64 #define LIBELF_BYTEORDER ELFDATA2LSB
66 #define LIBELF_CLASS ELFCLASS32
68 #elif defined(__i386__)
70 #define LIBELF_ARCH EM_386
71 #define LIBELF_BYTEORDER ELFDATA2LSB
72 #define LIBELF_CLASS ELFCLASS32
74 #elif defined(__ia64__)
76 #define LIBELF_ARCH EM_IA_64
77 #define LIBELF_BYTEORDER ELFDATA2LSB
78 #define LIBELF_CLASS ELFCLASS64
80 #elif defined(__mips__)
82 #define LIBELF_ARCH EM_MIPS
83 #if defined(__MIPSEB__)
84 #define LIBELF_BYTEORDER ELFDATA2MSB
86 #define LIBELF_BYTEORDER ELFDATA2LSB
88 #define LIBELF_CLASS ELFCLASS32
90 #elif defined(__powerpc__)
92 #define LIBELF_ARCH EM_PPC
93 #define LIBELF_BYTEORDER ELFDATA2MSB
94 #define LIBELF_CLASS ELFCLASS32
96 #elif defined(__sparc__)
98 #define LIBELF_ARCH EM_SPARCV9
99 #define LIBELF_BYTEORDER ELFDATA2MSB
100 #define LIBELF_CLASS ELFCLASS64
103 #error Unknown FreeBSD architecture.
105 #endif /* __FreeBSD__ */
107 #if !defined(__minix)
108 /* MINIX: LSC: Not accurate anymore. */
110 * Definitions for Minix3.
114 #define LIBELF_ARCH EM_386
115 #define LIBELF_BYTEORDER ELFDATA2LSB
116 #define LIBELF_CLASS ELFCLASS32
119 #endif /* !defined(__minix) */
121 #if defined(__NetBSD__) || defined(__minix) || defined(HAVE_NBTOOL_CONFIG_H)
123 #include <machine/elf_machdep.h>
125 #if !defined(ARCH_ELFSIZE)
126 #error ARCH_ELFSIZE is not defined.
129 #if ARCH_ELFSIZE == 32
130 #define LIBELF_ARCH ELF32_MACHDEP_ID
131 #define LIBELF_BYTEORDER ELF32_MACHDEP_ENDIANNESS
132 #define LIBELF_CLASS ELFCLASS32
133 #define Elf_Note Elf32_Nhdr
135 #define LIBELF_ARCH ELF64_MACHDEP_ID
136 #define LIBELF_BYTEORDER ELF64_MACHDEP_ENDIANNESS
137 #define LIBELF_CLASS ELFCLASS64
138 #define Elf_Note Elf64_Nhdr
141 #endif /* __NetBSD__ || HAVE_NBTOOL_CONFIG_H */
143 #if defined(__OpenBSD__)
145 #include <machine/exec.h>
147 #define LIBELF_ARCH ELF_TARG_MACH
148 #define LIBELF_BYTEORDER ELF_TARG_DATA
149 #define LIBELF_CLASS ELF_TARG_CLASS
154 * GNU & Linux compatibility.
156 * `__linux__' is defined in an environment runs the Linux kernel and glibc.
157 * `__GNU__' is defined in an environment runs a GNU kernel (Hurd) and glibc.
158 * `__GLIBC__' is defined for an environment that runs glibc over a non-GNU
159 * kernel such as GNU/kFreeBSD.
162 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
164 #if defined(__linux__)
166 #include "native-elf-format.h"
168 #define LIBELF_CLASS ELFTC_CLASS
169 #define LIBELF_ARCH ELFTC_ARCH
170 #define LIBELF_BYTEORDER ELFTC_BYTEORDER
172 #endif /* defined(__linux__) */
174 #if LIBELF_CLASS == ELFCLASS32
175 #define Elf_Note Elf32_Nhdr
176 #elif LIBELF_CLASS == ELFCLASS64
177 #define Elf_Note Elf64_Nhdr
179 #error LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64
182 #endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */