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 // Target-specific ELF type traits. 6 7 #ifndef TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_ 8 #define TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_ 9 10 #include "elf.h" 11 #include "libelf.h" 12 13 #if !defined(DT_MIPS_RLD_MAP2) 14 #define DT_MIPS_RLD_MAP2 0x70000035 15 #endif 16 17 // ELF is a traits structure used to provide convenient aliases for 18 // 32/64 bit Elf types and functions, depending on the target file. 19 20 struct ELF32_traits { 21 typedef Elf32_Addr Addr; 22 typedef Elf32_Dyn Dyn; 23 typedef Elf32_Ehdr Ehdr; 24 typedef Elf32_Off Off; 25 typedef Elf32_Phdr Phdr; 26 typedef Elf32_Rel Rel; 27 typedef Elf32_Rela Rela; 28 typedef Elf32_Shdr Shdr; 29 typedef Elf32_Sword Sword; 30 typedef Elf32_Sxword Sxword; 31 typedef Elf32_Sym Sym; 32 typedef Elf32_Word Word; 33 typedef Elf32_Xword Xword; 34 typedef Elf32_Half Half; 35 36 static inline Ehdr* getehdr(Elf* elf) { return elf32_getehdr(elf); } 37 static inline Phdr* getphdr(Elf* elf) { return elf32_getphdr(elf); } 38 static inline Shdr* getshdr(Elf_Scn* scn) { return elf32_getshdr(scn); } 39 static inline Word elf_r_type(Word info) { return ELF32_R_TYPE(info); } 40 static inline int elf_st_type(uint8_t info) { return ELF32_ST_TYPE(info); } 41 static inline Word elf_r_sym(Word info) { return ELF32_R_SYM(info); } 42 }; 43 44 struct ELF64_traits { 45 typedef Elf64_Addr Addr; 46 typedef Elf64_Dyn Dyn; 47 typedef Elf64_Ehdr Ehdr; 48 typedef Elf64_Off Off; 49 typedef Elf64_Phdr Phdr; 50 typedef Elf64_Rel Rel; 51 typedef Elf64_Rela Rela; 52 typedef Elf64_Shdr Shdr; 53 typedef Elf64_Sword Sword; 54 typedef Elf64_Sxword Sxword; 55 typedef Elf64_Sym Sym; 56 typedef Elf64_Word Word; 57 typedef Elf64_Xword Xword; 58 typedef Elf64_Half Half; 59 60 static inline Ehdr* getehdr(Elf* elf) { return elf64_getehdr(elf); } 61 static inline Phdr* getphdr(Elf* elf) { return elf64_getphdr(elf); } 62 static inline Shdr* getshdr(Elf_Scn* scn) { return elf64_getshdr(scn); } 63 static inline Xword elf_r_type(Xword info) { return ELF64_R_TYPE(info); } 64 static inline int elf_st_type(uint8_t info) { return ELF64_ST_TYPE(info); } 65 static inline Word elf_r_sym(Xword info) { return ELF64_R_SYM(info); } 66 }; 67 68 #endif // TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_ 69