1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef _ELF_TRAITS_H_ 6 #define _ELF_TRAITS_H_ 7 8 // NOTE: <stdint.h> is required here before <elf.h>. This is a NDK header bug. 9 #include <stdint.h> 10 #include <elf.h> 11 12 // ELF is a traits structure used to provide convenient aliases for 13 // 32/64 bit Elf types, depending on the target CPU bitness. 14 #if __SIZEOF_POINTER__ == 4 15 struct ELF { 16 typedef Elf32_Ehdr Ehdr; 17 typedef Elf32_Phdr Phdr; 18 typedef Elf32_Word Word; 19 typedef Elf32_Sword Sword; 20 typedef Elf32_Addr Addr; 21 typedef Elf32_Dyn Dyn; 22 typedef Elf32_Sym Sym; 23 typedef Elf32_Rel Rel; 24 typedef Elf32_Rela Rela; 25 typedef Elf32_auxv_t auxv_t; 26 27 enum { kElfClass = ELFCLASS32 }; 28 enum { kElfBits = 32 }; 29 30 #ifndef ELF_R_TYPE 31 #define ELF_R_TYPE ELF32_R_TYPE 32 #endif 33 34 #ifndef ELF_R_SYM 35 #define ELF_R_SYM ELF32_R_SYM 36 #endif 37 }; 38 #elif __SIZEOF_POINTER__ == 8 39 struct ELF { 40 typedef Elf64_Ehdr Ehdr; 41 typedef Elf64_Phdr Phdr; 42 typedef Elf64_Word Word; 43 typedef Elf64_Sword Sword; 44 typedef Elf64_Addr Addr; 45 typedef Elf64_Dyn Dyn; 46 typedef Elf64_Sym Sym; 47 typedef Elf64_Rel Rel; 48 typedef Elf64_Rela Rela; 49 typedef Elf64_auxv_t auxv_t; 50 51 enum { kElfClass = ELFCLASS64 }; 52 enum { kElfBits = 64 }; 53 54 #ifndef ELF_R_TYPE 55 #define ELF_R_TYPE ELF64_R_TYPE 56 #endif 57 58 #ifndef ELF_R_SYM 59 #define ELF_R_SYM ELF64_R_SYM 60 #endif 61 }; 62 #else 63 #error "Unsupported target CPU bitness" 64 #endif 65 66 #ifdef __arm__ 67 #define ELF_MACHINE EM_ARM 68 #elif defined(__i386__) 69 #define ELF_MACHINE EM_386 70 #elif defined(__mips__) && !defined(__LP64__) // mips64el defines __mips__ too 71 #define ELF_MACHINE EM_MIPS 72 #elif defined(__aarch64__) 73 #define ELF_MACHINE EM_AARCH64 74 #else 75 #error "Unsupported target CPU architecture" 76 #endif 77 78 #endif // _ELF_TRAITS_H_ 79