1 /* $NetBSD: _libelf_config.h,v 1.5 2016/02/20 02:43:42 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 3396 2016-02-10 21:50:05Z emaste 29 */ 30 31 #if defined(__APPLE__) || defined(__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(__aarch64__) 59 60 #define LIBELF_ARCH EM_AARCH64 61 #define LIBELF_BYTEORDER ELFDATA2LSB 62 #define LIBELF_CLASS ELFCLASS64 63 64 #elif defined(__arm__) 65 66 #define LIBELF_ARCH EM_ARM 67 #if defined(__ARMEB__) /* Big-endian ARM. */ 68 #define LIBELF_BYTEORDER ELFDATA2MSB 69 #else 70 #define LIBELF_BYTEORDER ELFDATA2LSB 71 #endif 72 #define LIBELF_CLASS ELFCLASS32 73 74 #elif defined(__i386__) 75 76 #define LIBELF_ARCH EM_386 77 #define LIBELF_BYTEORDER ELFDATA2LSB 78 #define LIBELF_CLASS ELFCLASS32 79 80 #elif defined(__ia64__) 81 82 #define LIBELF_ARCH EM_IA_64 83 #define LIBELF_BYTEORDER ELFDATA2LSB 84 #define LIBELF_CLASS ELFCLASS64 85 86 #elif defined(__mips__) 87 88 #define LIBELF_ARCH EM_MIPS 89 #if defined(__MIPSEB__) 90 #define LIBELF_BYTEORDER ELFDATA2MSB 91 #else 92 #define LIBELF_BYTEORDER ELFDATA2LSB 93 #endif 94 #define LIBELF_CLASS ELFCLASS32 95 96 #elif defined(__powerpc__) 97 98 #define LIBELF_ARCH EM_PPC 99 #define LIBELF_BYTEORDER ELFDATA2MSB 100 #define LIBELF_CLASS ELFCLASS32 101 102 #elif defined(__riscv64) 103 104 #define LIBELF_ARCH EM_RISCV 105 #define LIBELF_BYTEORDER ELFDATA2LSB 106 #define LIBELF_CLASS ELFCLASS64 107 108 #elif defined(__sparc__) 109 110 #define LIBELF_ARCH EM_SPARCV9 111 #define LIBELF_BYTEORDER ELFDATA2MSB 112 #define LIBELF_CLASS ELFCLASS64 113 114 #else 115 #error Unknown FreeBSD architecture. 116 #endif 117 #endif /* __FreeBSD__ */ 118 119 /* 120 * Definitions for Minix3. 121 */ 122 #ifdef __minix 123 124 #define LIBELF_ARCH EM_386 125 #define LIBELF_BYTEORDER ELFDATA2LSB 126 #define LIBELF_CLASS ELFCLASS32 127 128 #endif /* __minix */ 129 130 #if defined(__NetBSD__) || defined(HAVE_NBTOOL_CONFIG_H) 131 132 #include <machine/elf_machdep.h> 133 134 #if !defined(ARCH_ELFSIZE) 135 #error ARCH_ELFSIZE is not defined. 136 #endif 137 138 #if ARCH_ELFSIZE == 32 139 #define LIBELF_ARCH ELF32_MACHDEP_ID 140 #define LIBELF_BYTEORDER ELF32_MACHDEP_ENDIANNESS 141 #define LIBELF_CLASS ELFCLASS32 142 #define Elf_Note Elf32_Nhdr 143 #else 144 #define LIBELF_ARCH ELF64_MACHDEP_ID 145 #define LIBELF_BYTEORDER ELF64_MACHDEP_ENDIANNESS 146 #define LIBELF_CLASS ELFCLASS64 147 #define Elf_Note Elf64_Nhdr 148 #endif 149 150 #endif /* __NetBSD__ || HAVE_NBTOOL_CONFIG_H */ 151 152 #if defined(__OpenBSD__) 153 154 #include <machine/exec.h> 155 156 #define LIBELF_ARCH ELF_TARG_MACH 157 #define LIBELF_BYTEORDER ELF_TARG_DATA 158 #define LIBELF_CLASS ELF_TARG_CLASS 159 160 #endif 161 162 /* 163 * GNU & Linux compatibility. 164 * 165 * `__linux__' is defined in an environment runs the Linux kernel and glibc. 166 * `__GNU__' is defined in an environment runs a GNU kernel (Hurd) and glibc. 167 * `__GLIBC__' is defined for an environment that runs glibc over a non-GNU 168 * kernel such as GNU/kFreeBSD. 169 */ 170 171 #ifndef HAVE_NBTOOL_CONFIG_H 172 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) 173 174 #if defined(__linux__) 175 176 #include "native-elf-format.h" 177 178 #define LIBELF_CLASS ELFTC_CLASS 179 #define LIBELF_ARCH ELFTC_ARCH 180 #define LIBELF_BYTEORDER ELFTC_BYTEORDER 181 182 #endif /* defined(__linux__) */ 183 184 #if LIBELF_CLASS == ELFCLASS32 185 #define Elf_Note Elf32_Nhdr 186 #elif LIBELF_CLASS == ELFCLASS64 187 #define Elf_Note Elf64_Nhdr 188 #else 189 #error LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64 190 #endif 191 192 #endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */ 193 #endif /* HAVE_NBTOOL_CONFIG_H */ 194