/ external / libelf / _libelf_config.h
_libelf_config.h
  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$
 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  #elif   defined(__aarch64__)
 40  #define LIBELF_ARCH             EM_AARCH64
 41  #define LIBELF_BYTEORDER        ELFDATA2LSB
 42  #define LIBELF_CLASS            ELFCLASS64
 43  #endif
 44  
 45  #endif	/* __DragonFly__ */
 46  
 47  #ifdef __FreeBSD__
 48  
 49  /*
 50   * Define LIBELF_{ARCH,BYTEORDER,CLASS} based on the machine architecture.
 51   * See also: <machine/elf.h>.
 52   */
 53  
 54  #if	defined(__amd64__)
 55  
 56  #define	LIBELF_ARCH		EM_X86_64
 57  #define	LIBELF_BYTEORDER	ELFDATA2LSB
 58  #define	LIBELF_CLASS		ELFCLASS64
 59  
 60  #elif	defined(__aarch64__)
 61  
 62  #define	LIBELF_ARCH		EM_AARCH64
 63  #define	LIBELF_BYTEORDER	ELFDATA2LSB
 64  #define	LIBELF_CLASS		ELFCLASS64
 65  
 66  #elif	defined(__arm__)
 67  
 68  #define	LIBELF_ARCH		EM_ARM
 69  #if	defined(__ARMEB__)	/* Big-endian ARM. */
 70  #define	LIBELF_BYTEORDER	ELFDATA2MSB
 71  #else
 72  #define	LIBELF_BYTEORDER	ELFDATA2LSB
 73  #endif
 74  #define	LIBELF_CLASS		ELFCLASS32
 75  
 76  #elif	defined(__i386__)
 77  
 78  #define	LIBELF_ARCH		EM_386
 79  #define	LIBELF_BYTEORDER	ELFDATA2LSB
 80  #define	LIBELF_CLASS		ELFCLASS32
 81  
 82  #elif	defined(__ia64__)
 83  
 84  #define	LIBELF_ARCH		EM_IA_64
 85  #define	LIBELF_BYTEORDER	ELFDATA2LSB
 86  #define	LIBELF_CLASS		ELFCLASS64
 87  
 88  #elif	defined(__mips__)
 89  
 90  #define	LIBELF_ARCH		EM_MIPS
 91  #if	defined(__MIPSEB__)
 92  #define	LIBELF_BYTEORDER	ELFDATA2MSB
 93  #else
 94  #define	LIBELF_BYTEORDER	ELFDATA2LSB
 95  #endif
 96  #define	LIBELF_CLASS		ELFCLASS32
 97  
 98  #elif defined(__powerpc64__)
 99  
100  #define LIBELF_ARCH EM_PPC64
101  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
102  #define LIBELF_BYTEORDER ELFDATA2LSB
103  #else
104  #define LIBELF_BYTEORDER ELFDATA2MSB
105  #endif
106  #define LIBELF_CLASS ELFCLASS64
107  
108  #elif	defined(__powerpc__)
109  
110  #define	LIBELF_ARCH		EM_PPC
111  #define	LIBELF_BYTEORDER	ELFDATA2MSB
112  #define	LIBELF_CLASS		ELFCLASS32
113  
114  #elif	defined(__sparc__)
115  
116  #define	LIBELF_ARCH		EM_SPARCV9
117  #define	LIBELF_BYTEORDER	ELFDATA2MSB
118  #define	LIBELF_CLASS		ELFCLASS64
119  
120  #else
121  #error	Unknown FreeBSD architecture.
122  #endif
123  #endif  /* __FreeBSD__ */
124  
125  /*
126   * Definitions for Minix3.
127   */
128  #ifdef __minix
129  
130  #define	LIBELF_ARCH		EM_386
131  #define	LIBELF_BYTEORDER	ELFDATA2LSB
132  #define	LIBELF_CLASS		ELFCLASS32
133  
134  #endif	/* __minix */
135  
136  #ifdef __NetBSD__
137  
138  #include <machine/elf_machdep.h>
139  
140  #if	!defined(ARCH_ELFSIZE)
141  #error	ARCH_ELFSIZE is not defined.
142  #endif
143  
144  #if	ARCH_ELFSIZE == 32
145  #define	LIBELF_ARCH		ELF32_MACHDEP_ID
146  #define	LIBELF_BYTEORDER	ELF32_MACHDEP_ENDIANNESS
147  #define	LIBELF_CLASS		ELFCLASS32
148  #define	Elf_Note		Elf32_Nhdr
149  #else
150  #define	LIBELF_ARCH		ELF64_MACHDEP_ID
151  #define	LIBELF_BYTEORDER	ELF64_MACHDEP_ENDIANNESS
152  #define	LIBELF_CLASS		ELFCLASS64
153  #define	Elf_Note		Elf64_Nhdr
154  #endif
155  
156  #endif	/* __NetBSD__ */
157  
158  #if defined(__OpenBSD__)
159  
160  #include <machine/exec.h>
161  
162  #define	LIBELF_ARCH		ELF_TARG_MACH
163  #define	LIBELF_BYTEORDER	ELF_TARG_DATA
164  #define	LIBELF_CLASS		ELF_TARG_CLASS
165  
166  #endif
167  
168  /*
169   * GNU & Linux compatibility.
170   *
171   * `__linux__' is defined in an environment runs the Linux kernel and glibc.
172   * `__GNU__' is defined in an environment runs a GNU kernel (Hurd) and glibc.
173   * `__GLIBC__' is defined for an environment that runs glibc over a non-GNU
174   *     kernel such as GNU/kFreeBSD.
175   */
176  
177  #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
178  
179  #if defined(__linux__)
180  
181  #if    defined(__amd64__)
182  
183  #define LIBELF_ARCH             EM_X86_64
184  #define LIBELF_BYTEORDER        ELFDATA2LSB
185  #define LIBELF_CLASS            ELFCLASS64
186  
187  #elif   defined(__aarch64__)
188  
189  #define LIBELF_ARCH             EM_AARCH64
190  #define LIBELF_BYTEORDER        ELFDATA2LSB
191  #define LIBELF_CLASS            ELFCLASS64
192  
193  #elif  defined(__i386__)
194  
195  #define LIBELF_ARCH             EM_386
196  #define LIBELF_BYTEORDER        ELFDATA2LSB
197  #define LIBELF_CLASS            ELFCLASS32
198  
199  #endif
200  
201  #endif	/* defined(__linux__) */
202  
203  #if	LIBELF_CLASS == ELFCLASS32
204  #define	Elf_Note		Elf32_Nhdr
205  #elif   LIBELF_CLASS == ELFCLASS64
206  #define	Elf_Note		Elf64_Nhdr
207  #else
208  #error  LIBELF_CLASS needs to be one of ELFCLASS32 or ELFCLASS64
209  #endif
210  
211  #endif /* defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) */