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