1 | // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_PLATFORM_ELF_H_ |
6 | #define RUNTIME_PLATFORM_ELF_H_ |
7 | |
8 | #include "platform/globals.h" |
9 | |
10 | namespace dart { |
11 | namespace elf { |
12 | |
13 | #pragma pack(push, 1) |
14 | |
15 | struct { |
16 | uint8_t [16]; |
17 | uint16_t ; |
18 | uint16_t ; |
19 | uint32_t ; |
20 | #if defined(TARGET_ARCH_IS_32_BIT) |
21 | uint32_t entry_point; |
22 | uint32_t program_table_offset; |
23 | uint32_t section_table_offset; |
24 | #else |
25 | uint64_t ; |
26 | uint64_t ; |
27 | uint64_t ; |
28 | #endif |
29 | uint32_t ; |
30 | uint16_t ; |
31 | uint16_t ; |
32 | uint16_t ; |
33 | uint16_t ; |
34 | uint16_t ; |
35 | uint16_t ; |
36 | }; |
37 | |
38 | enum class : uint32_t { |
39 | = 0, |
40 | = 1, |
41 | = 2, |
42 | = 4, |
43 | = 6, |
44 | }; |
45 | |
46 | struct { |
47 | #if defined(TARGET_ARCH_IS_32_BIT) |
48 | ProgramHeaderType type; |
49 | uint32_t file_offset; |
50 | uint32_t memory_offset; |
51 | uint32_t physical_memory_offset; |
52 | uint32_t file_size; |
53 | uint32_t memory_size; |
54 | uint32_t flags; |
55 | uint32_t alignment; |
56 | #else |
57 | ProgramHeaderType ; |
58 | uint32_t ; |
59 | uint64_t ; |
60 | uint64_t ; |
61 | uint64_t ; |
62 | uint64_t ; |
63 | uint64_t ; |
64 | uint64_t ; |
65 | #endif |
66 | }; |
67 | |
68 | enum class : uint32_t { |
69 | = 0, |
70 | = 1, |
71 | = 2, |
72 | = 3, |
73 | = 5, |
74 | = 7, |
75 | = 8, |
76 | = 6, |
77 | = 11, |
78 | }; |
79 | |
80 | struct { |
81 | #if defined(TARGET_ARCH_IS_32_BIT) |
82 | uint32_t name; |
83 | SectionHeaderType type; |
84 | uint32_t flags; |
85 | uint32_t memory_offset; |
86 | uint32_t file_offset; |
87 | uint32_t file_size; |
88 | uint32_t link; |
89 | uint32_t info; |
90 | uint32_t alignment; |
91 | uint32_t entry_size; |
92 | #else |
93 | uint32_t ; |
94 | SectionHeaderType ; |
95 | uint64_t ; |
96 | uint64_t ; |
97 | uint64_t ; |
98 | uint64_t ; |
99 | uint32_t ; |
100 | uint32_t ; |
101 | uint64_t ; |
102 | uint64_t ; |
103 | #endif |
104 | }; |
105 | |
106 | struct Symbol { |
107 | #if defined(TARGET_ARCH_IS_32_BIT) |
108 | uint32_t name; |
109 | uint32_t value; |
110 | uint32_t size; |
111 | uint8_t info; |
112 | uint8_t other; // Reserved by ELF. |
113 | uint16_t section; |
114 | #else |
115 | uint32_t name; |
116 | uint8_t info; |
117 | uint8_t other; // Reserved by ELF. |
118 | uint16_t section; |
119 | uint64_t value; |
120 | uint64_t size; |
121 | #endif |
122 | }; |
123 | |
124 | enum class DynamicEntryType : uint32_t { |
125 | DT_NULL = 0, |
126 | DT_HASH = 4, |
127 | DT_STRTAB = 5, |
128 | DT_SYMTAB = 6, |
129 | DT_STRSZ = 10, |
130 | DT_SYMENT = 11, |
131 | }; |
132 | |
133 | struct DynamicEntry { |
134 | #if defined(TARGET_ARCH_IS_32_BIT) |
135 | uint32_t tag; |
136 | uint32_t value; |
137 | #else |
138 | uint64_t tag; |
139 | uint64_t value; |
140 | #endif |
141 | }; |
142 | |
143 | enum class NoteType : uint32_t { |
144 | NT_GNU_BUILD_ID = 3, |
145 | }; |
146 | |
147 | struct Note { |
148 | uint32_t name_size; |
149 | uint32_t description_size; |
150 | NoteType type; |
151 | uint8_t data[]; |
152 | }; |
153 | |
154 | #pragma pack(pop) |
155 | |
156 | static constexpr intptr_t ELFCLASS32 = 1; |
157 | static constexpr intptr_t ELFCLASS64 = 2; |
158 | |
159 | static const intptr_t EI_DATA = 5; |
160 | static const intptr_t ELFDATA2LSB = 1; |
161 | |
162 | static const intptr_t ELFOSABI_SYSV = 0; |
163 | |
164 | static const intptr_t ET_DYN = 3; |
165 | |
166 | static constexpr intptr_t EF_ARM_ABI_FLOAT_HARD = 0x00000400; |
167 | static constexpr intptr_t EF_ARM_ABI_FLOAT_SOFT = 0x00000200; |
168 | static constexpr intptr_t EF_ARM_ABI = 0x05000000; |
169 | |
170 | static constexpr intptr_t EM_386 = 3; |
171 | static constexpr intptr_t EM_ARM = 40; |
172 | static constexpr intptr_t EM_X86_64 = 62; |
173 | static constexpr intptr_t EM_AARCH64 = 183; |
174 | |
175 | static const intptr_t EV_CURRENT = 1; |
176 | |
177 | static const intptr_t PF_X = 1; |
178 | static const intptr_t PF_W = 2; |
179 | static const intptr_t PF_R = 4; |
180 | |
181 | static const intptr_t SHF_WRITE = 0x1; |
182 | static const intptr_t SHF_ALLOC = 0x2; |
183 | static const intptr_t SHF_EXECINSTR = 0x4; |
184 | |
185 | static const intptr_t SHN_UNDEF = 0; |
186 | |
187 | static const intptr_t STN_UNDEF = 0; |
188 | |
189 | static const intptr_t STB_LOCAL = 0; |
190 | static const intptr_t STB_GLOBAL = 1; |
191 | |
192 | static const intptr_t STT_OBJECT = 1; // I.e., data. |
193 | static const intptr_t STT_FUNC = 2; |
194 | static const intptr_t STT_SECTION = 3; |
195 | |
196 | static constexpr const char* ELF_NOTE_GNU = "GNU" ; |
197 | |
198 | } // namespace elf |
199 | } // namespace dart |
200 | |
201 | #endif // RUNTIME_PLATFORM_ELF_H_ |
202 | |