1 /* $NetBSD: _libelf_config.h,v 1.3 2015/09/29 19:43:39 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 #if !defined(__minix) 108 /* MINIX: LSC: Not accurate anymore. */ 109 /* 110 * Definitions for Minix3. 111 */ 112 #ifdef __minix 113 114 #define LIBELF_ARCH EM_386 115 #define LIBELF_BYTEORDER ELFDATA2LSB 116 #define LIBELF_CLASS ELFCLASS32 117 118 #endif /* __minix */ 119 #endif /* !defined(__minix) */ 120 121 #if defined(__NetBSD__) || defined(__minix) || defined(HAVE_NBTOOL_CONFIG_H) 122 123 #include <machine/elf_machdep.h> 124 125 #if !defined(ARCH_ELFSIZE) 126 #error ARCH_ELFSIZE is not defined. 127 #endif 128 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 134 #else 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 139 #endif 140 141 #endif /* __NetBSD__ || HAVE_NBTOOL_CONFIG_H */ 142 143 #if defined(__OpenBSD__) 144 145 #include <machine/exec.h> 146 147 #define LIBELF_ARCH ELF_TARG_MACH 148 #define LIBELF_BYTEORDER ELF_TARG_DATA 149 #define LIBELF_CLASS ELF_TARG_CLASS 150 151 #endif 152 153 /* 154 * GNU & Linux compatibility. 155 * 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. 160 */ 161 162 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) 163 164 #if defined(__linux__) 165 166 #include "native-elf-format.h" 167 168 #define LIBELF_CLASS ELFTC_CLASS 169 #define LIBELF_ARCH ELFTC_ARCH 170 #define LIBELF_BYTEORDER ELFTC_BYTEORDER 171 172 #endif /* defined(__linux__) */ 173 174 #if LIBELF_CLASS == ELFCLASS32 175 #define Elf_Note Elf32_Nhdr 176 #elif LIBELF_CLASS == ELFCLASS64 177 #define Elf_Note Elf64_Nhdr 178 #else 179 #error LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64 180 #endif 181 182 #endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */ 183