OLD | NEW |
(Empty) | |
| 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 // The TARGET_ macro controls which Elf types we expect and handle. |
| 14 // Either TARGET_ARM or TARGET_ARM64 must be defined, but not both. |
| 15 |
| 16 #if !defined(TARGET_ARM) && !defined(TARGET_ARM64) |
| 17 # error "Unsupported target, define one of TARGET_ARM or TARGET_ARM64" |
| 18 #elif defined(TARGET_ARM) && defined(TARGET_ARM64) |
| 19 # error "Define one of TARGET_ARM or TARGET_ARM64, but not both" |
| 20 #endif |
| 21 |
| 22 // ELF is a traits structure used to provide convenient aliases for |
| 23 // 32/64 bit Elf types and functions, depending on the target specified. |
| 24 |
| 25 #if defined(TARGET_ARM) |
| 26 struct ELF { |
| 27 typedef Elf32_Addr Addr; |
| 28 typedef Elf32_Dyn Dyn; |
| 29 typedef Elf32_Ehdr Ehdr; |
| 30 typedef Elf32_Off Off; |
| 31 typedef Elf32_Phdr Phdr; |
| 32 typedef Elf32_Rel Rel; |
| 33 typedef Elf32_Shdr Shdr; |
| 34 typedef Elf32_Sword Sword; |
| 35 typedef Elf32_Sxword Sxword; |
| 36 typedef Elf32_Sym Sym; |
| 37 typedef Elf32_Word Word; |
| 38 typedef Elf32_Xword Xword; |
| 39 |
| 40 static inline Ehdr* getehdr(Elf* elf) { return elf32_getehdr(elf); } |
| 41 static inline Phdr* getphdr(Elf* elf) { return elf32_getphdr(elf); } |
| 42 static inline Shdr* getshdr(Elf_Scn* scn) { return elf32_getshdr(scn); } |
| 43 |
| 44 enum { kMachine = EM_ARM }; |
| 45 enum { kFileClass = ELFCLASS32 }; |
| 46 enum { kRelativeRelocationCode = R_ARM_RELATIVE }; |
| 47 enum { kNoRelocationCode = R_ARM_NONE }; |
| 48 |
| 49 static inline const char* Machine() { return "ARM"; } |
| 50 |
| 51 # define ELF_R_SYM(val) ELF32_R_SYM(val) |
| 52 # define ELF_R_TYPE(val) ELF32_R_TYPE(val) |
| 53 # define ELF_R_INFO(sym, type) ELF32_R_INFO(sym, type) |
| 54 # define ELF_ST_TYPE(val) ELF32_ST_TYPE(val) |
| 55 }; |
| 56 |
| 57 #elif defined(TARGET_ARM64) |
| 58 struct ELF { |
| 59 typedef Elf64_Addr Addr; |
| 60 typedef Elf64_Dyn Dyn; |
| 61 typedef Elf64_Ehdr Ehdr; |
| 62 typedef Elf64_Off Off; |
| 63 typedef Elf64_Phdr Phdr; |
| 64 typedef Elf64_Rel Rel; |
| 65 typedef Elf64_Shdr Shdr; |
| 66 typedef Elf64_Sword Sword; |
| 67 typedef Elf64_Sxword Sxword; |
| 68 typedef Elf64_Sym Sym; |
| 69 typedef Elf64_Word Word; |
| 70 typedef Elf64_Xword Xword; |
| 71 |
| 72 static inline Ehdr* getehdr(Elf* elf) { return elf64_getehdr(elf); } |
| 73 static inline Phdr* getphdr(Elf* elf) { return elf64_getphdr(elf); } |
| 74 static inline Shdr* getshdr(Elf_Scn* scn) { return elf64_getshdr(scn); } |
| 75 |
| 76 // TODO(simonb): Eliminate these once AARCH64 appears reliably in elf.h. |
| 77 # ifndef EM_AARCH64 |
| 78 # define EM_AARCH64 183 |
| 79 # endif |
| 80 # ifndef R_AARCH64_RELATIVE |
| 81 # define R_AARCH64_RELATIVE 1027 |
| 82 # endif |
| 83 # ifndef R_AARCH64_NONE |
| 84 # define R_AARCH64_NONE 0 |
| 85 # endif |
| 86 |
| 87 enum { kMachine = EM_AARCH64 }; |
| 88 enum { kFileClass = ELFCLASS64 }; |
| 89 enum { kRelativeRelocationCode = R_AARCH64_RELATIVE }; |
| 90 enum { kNoRelocationCode = R_AARCH64_NONE }; |
| 91 |
| 92 static inline const char* Machine() { return "ARM64"; } |
| 93 |
| 94 # define ELF_R_SYM(val) ELF64_R_SYM(val) |
| 95 # define ELF_R_TYPE(val) ELF64_R_TYPE(val) |
| 96 # define ELF_R_INFO(sym, type) ELF64_R_INFO(sym, type) |
| 97 # define ELF_ST_TYPE(val) ELF64_ST_TYPE(val) |
| 98 }; |
| 99 #endif |
| 100 |
| 101 #endif // TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_ |
OLD | NEW |