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__) || defined(__FreeBSD__) 30 31/* 32 * Define LIBELF_{ARCH,BYTEORDER,CLASS} based on the machine architecture. 33 * See also: <machine/elf.h> on FreeBSD. 34 */ 35 36#if defined(__amd64__) 37 38#define LIBELF_ARCH EM_X86_64 39#define LIBELF_BYTEORDER ELFDATA2LSB 40#define LIBELF_CLASS ELFCLASS64 41 42#elif defined(__aarch64__) 43 44#define LIBELF_ARCH EM_AARCH64 45#define LIBELF_BYTEORDER ELFDATA2LSB 46#define LIBELF_CLASS ELFCLASS64 47 48#elif defined(__arm__) 49 50#define LIBELF_ARCH EM_ARM 51#if defined(__ARMEB__) /* Big-endian ARM. */ 52#define LIBELF_BYTEORDER ELFDATA2MSB 53#else 54#define LIBELF_BYTEORDER ELFDATA2LSB 55#endif 56#define LIBELF_CLASS ELFCLASS32 57 58#elif defined(__i386__) 59 60#define LIBELF_ARCH EM_386 61#define LIBELF_BYTEORDER ELFDATA2LSB 62#define LIBELF_CLASS ELFCLASS32 63 64#elif defined(__ia64__) 65 66#define LIBELF_ARCH EM_IA_64 67#define LIBELF_BYTEORDER ELFDATA2LSB 68#define LIBELF_CLASS ELFCLASS64 69 70#elif defined(__mips__) 71 72#define LIBELF_ARCH EM_MIPS 73#if defined(__MIPSEB__) 74#define LIBELF_BYTEORDER ELFDATA2MSB 75#else 76#define LIBELF_BYTEORDER ELFDATA2LSB 77#endif 78#define LIBELF_CLASS ELFCLASS32 79 80#elif defined(__powerpc64__) 81 82#define LIBELF_ARCH EM_PPC64 83#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 84#define LIBELF_BYTEORDER ELFDATA2LSB 85#else 86#define LIBELF_BYTEORDER ELFDATA2MSB 87#endif 88#define LIBELF_CLASS ELFCLASS64 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(__riscv) && (__riscv_xlen == 64) 97 98#define LIBELF_ARCH EM_RISCV 99#define LIBELF_BYTEORDER ELFDATA2LSB 100#define LIBELF_CLASS ELFCLASS64 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 architecture. 116#endif 117#endif /* defined(__APPLE__) || defined(__DragonFly__) || defined(__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#ifdef __NetBSD__ 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__ */ 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#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) 172 173#if defined(__linux__) 174 175#include "native-elf-format.h" 176 177#define LIBELF_CLASS ELFTC_CLASS 178#define LIBELF_ARCH ELFTC_ARCH 179#define LIBELF_BYTEORDER ELFTC_BYTEORDER 180 181#endif /* defined(__linux__) */ 182 183#if LIBELF_CLASS == ELFCLASS32 184#define Elf_Note Elf32_Nhdr 185#elif LIBELF_CLASS == ELFCLASS64 186#define Elf_Note Elf64_Nhdr 187#else 188#error LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64 189#endif 190 191#endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */ 192