Flutter Engine
The Flutter Engine
elf.h
Go to the documentation of this file.
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
10namespace dart {
11namespace elf {
12
13#pragma pack(push, 1)
14
15struct ElfHeader {
16 uint8_t ident[16];
17 uint16_t type;
18 uint16_t machine;
19 uint32_t version;
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 entry_point;
28#endif
29 uint32_t flags;
30 uint16_t header_size;
36};
37
38enum class ProgramHeaderType : uint32_t {
39 PT_NULL = 0,
40 PT_LOAD = 1,
41 PT_DYNAMIC = 2,
42 PT_NOTE = 4,
43 PT_PHDR = 6,
44 PT_GNU_STACK = 0x6474e551,
45};
46
48#if defined(TARGET_ARCH_IS_32_BIT)
50 uint32_t file_offset;
51 uint32_t memory_offset;
53 uint32_t file_size;
54 uint32_t memory_size;
55 uint32_t flags;
56 uint32_t alignment;
57#else
59 uint32_t flags;
60 uint64_t file_offset;
61 uint64_t memory_offset;
63 uint64_t file_size;
64 uint64_t memory_size;
65 uint64_t alignment;
66#endif
67};
68
69enum class SectionHeaderType : uint32_t {
70 SHT_NULL = 0,
71 SHT_PROGBITS = 1,
72 SHT_SYMTAB = 2,
73 SHT_STRTAB = 3,
74 SHT_HASH = 5,
75 SHT_NOTE = 7,
76 SHT_NOBITS = 8,
77 SHT_DYNAMIC = 6,
78 SHT_DYNSYM = 11,
79};
80
82#if defined(TARGET_ARCH_IS_32_BIT)
83 uint32_t name;
85 uint32_t flags;
86 uint32_t memory_offset;
87 uint32_t file_offset;
88 uint32_t file_size;
89 uint32_t link;
90 uint32_t info;
91 uint32_t alignment;
92 uint32_t entry_size;
93#else
94 uint32_t name;
96 uint64_t flags;
97 uint64_t memory_offset;
98 uint64_t file_offset;
99 uint64_t file_size;
100 uint32_t link;
101 uint32_t info;
102 uint64_t alignment;
103 uint64_t entry_size;
104#endif
105};
106
107struct Symbol {
108#if defined(TARGET_ARCH_IS_32_BIT)
109 uint32_t name;
110 uint32_t value;
111 uint32_t size;
112 uint8_t info;
113 uint8_t other; // Reserved by ELF.
114 uint16_t section;
115#else
116 uint32_t name;
117 uint8_t info;
118 uint8_t other; // Reserved by ELF.
119 uint16_t section;
120 uint64_t value;
121 uint64_t size;
122#endif
123};
124
125enum class DynamicEntryType : uint32_t {
126 DT_NULL = 0,
127 DT_HASH = 4,
128 DT_STRTAB = 5,
129 DT_SYMTAB = 6,
130 DT_STRSZ = 10,
131 DT_SYMENT = 11,
132};
133
135#if defined(TARGET_ARCH_IS_32_BIT)
136 uint32_t tag;
137 uint32_t value;
138#else
139 uint64_t tag;
140 uint64_t value;
141#endif
142};
143
144enum class NoteType : uint32_t {
145 NT_GNU_BUILD_ID = 3,
146};
147
148struct Note {
149 uint32_t name_size;
152 uint8_t data[];
153};
154
155#pragma pack(pop)
156
157static constexpr intptr_t ELFCLASS32 = 1;
158static constexpr intptr_t ELFCLASS64 = 2;
159
160static constexpr intptr_t EI_DATA = 5;
161static constexpr intptr_t ELFDATA2LSB = 1;
162
163static constexpr intptr_t ELFOSABI_SYSV = 0;
164
165static constexpr intptr_t ET_DYN = 3;
166
167static constexpr intptr_t EF_ARM_ABI_FLOAT_HARD = 0x00000400;
168static constexpr intptr_t EF_ARM_ABI_FLOAT_SOFT = 0x00000200;
169static constexpr intptr_t EF_ARM_ABI = 0x05000000;
170
171static constexpr intptr_t EM_386 = 3;
172static constexpr intptr_t EM_ARM = 40;
173static constexpr intptr_t EM_X86_64 = 62;
174static constexpr intptr_t EM_AARCH64 = 183;
175static constexpr intptr_t EM_RISCV = 243;
176
177static constexpr intptr_t EV_CURRENT = 1;
178
179static constexpr intptr_t PF_X = 1;
180static constexpr intptr_t PF_W = 2;
181static constexpr intptr_t PF_R = 4;
182
183static constexpr intptr_t SHF_WRITE = 0x1;
184static constexpr intptr_t SHF_ALLOC = 0x2;
185static constexpr intptr_t SHF_EXECINSTR = 0x4;
186
187static constexpr intptr_t SHN_UNDEF = 0;
188
189static constexpr intptr_t STN_UNDEF = 0;
190
191static constexpr intptr_t STB_LOCAL = 0;
192static constexpr intptr_t STB_GLOBAL = 1;
193
194static constexpr intptr_t STT_NOTYPE = 0;
195static constexpr intptr_t STT_OBJECT = 1; // I.e., data.
196static constexpr intptr_t STT_FUNC = 2;
197static constexpr intptr_t STT_SECTION = 3;
198
199static constexpr const char ELF_NOTE_GNU[] = "GNU";
200
201// Creates symbol info from the given STB and STT values.
202constexpr decltype(Symbol::info) SymbolInfo(intptr_t binding, intptr_t type) {
203 // Take the low nibble of each value in case, though the upper bits should
204 // all be zero as long as STB/STT constants are used.
205 return (binding & 0xf) << 4 | (type & 0xf);
206}
207
208// Retrieves the STB binding value for the given symbol info.
209constexpr intptr_t SymbolBinding(const decltype(Symbol::info) info) {
210 return (info >> 4) & 0xf;
211}
212
213// Retrieves the STT type value for the given symbol info.
214constexpr intptr_t SymbolType(const decltype(Symbol::info) info) {
215 return info & 0xf;
216}
217
218} // namespace elf
219} // namespace dart
220
221#endif // RUNTIME_PLATFORM_ELF_H_
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
GLenum type
static constexpr intptr_t ELFCLASS64
Definition: elf.h:158
static constexpr intptr_t STT_SECTION
Definition: elf.h:197
static constexpr intptr_t SHN_UNDEF
Definition: elf.h:187
static constexpr intptr_t EF_ARM_ABI_FLOAT_SOFT
Definition: elf.h:168
static constexpr intptr_t ELFOSABI_SYSV
Definition: elf.h:163
static constexpr intptr_t STB_GLOBAL
Definition: elf.h:192
static constexpr intptr_t PF_R
Definition: elf.h:181
static constexpr intptr_t PF_X
Definition: elf.h:179
SectionHeaderType
Definition: elf.h:69
static constexpr intptr_t STN_UNDEF
Definition: elf.h:189
static constexpr intptr_t ET_DYN
Definition: elf.h:165
static constexpr intptr_t EM_X86_64
Definition: elf.h:173
DynamicEntryType
Definition: elf.h:125
static constexpr intptr_t EM_386
Definition: elf.h:171
constexpr intptr_t SymbolBinding(const decltype(Symbol::info) info)
Definition: elf.h:209
static constexpr intptr_t ELFCLASS32
Definition: elf.h:157
NoteType
Definition: elf.h:144
static constexpr intptr_t EM_RISCV
Definition: elf.h:175
static constexpr intptr_t EM_AARCH64
Definition: elf.h:174
constexpr decltype(Symbol::info) SymbolInfo(intptr_t binding, intptr_t type)
Definition: elf.h:202
static constexpr intptr_t STB_LOCAL
Definition: elf.h:191
static constexpr intptr_t SHF_EXECINSTR
Definition: elf.h:185
static constexpr intptr_t SHF_WRITE
Definition: elf.h:183
ProgramHeaderType
Definition: elf.h:38
static constexpr intptr_t PF_W
Definition: elf.h:180
static constexpr const char ELF_NOTE_GNU[]
Definition: elf.h:199
static constexpr intptr_t ELFDATA2LSB
Definition: elf.h:161
static constexpr intptr_t EF_ARM_ABI_FLOAT_HARD
Definition: elf.h:167
static constexpr intptr_t STT_NOTYPE
Definition: elf.h:194
static constexpr intptr_t EF_ARM_ABI
Definition: elf.h:169
static constexpr intptr_t EI_DATA
Definition: elf.h:160
static constexpr intptr_t EM_ARM
Definition: elf.h:172
static constexpr intptr_t STT_FUNC
Definition: elf.h:196
static constexpr intptr_t EV_CURRENT
Definition: elf.h:177
static constexpr intptr_t SHF_ALLOC
Definition: elf.h:184
static constexpr intptr_t STT_OBJECT
Definition: elf.h:195
constexpr intptr_t SymbolType(const decltype(Symbol::info) info)
Definition: elf.h:214
Definition: dart_vm.cc:33
uint64_t value
Definition: elf.h:140
uint16_t shstrtab_section_index
Definition: elf.h:35
uint8_t ident[16]
Definition: elf.h:16
uint32_t flags
Definition: elf.h:29
uint16_t machine
Definition: elf.h:18
uint16_t program_table_entry_size
Definition: elf.h:31
uint64_t section_table_offset
Definition: elf.h:27
uint16_t num_section_headers
Definition: elf.h:34
uint16_t num_program_headers
Definition: elf.h:32
uint16_t header_size
Definition: elf.h:30
uint16_t type
Definition: elf.h:17
uint64_t program_table_offset
Definition: elf.h:26
uint32_t version
Definition: elf.h:19
uint16_t section_table_entry_size
Definition: elf.h:33
uint64_t entry_point
Definition: elf.h:25
NoteType type
Definition: elf.h:151
uint8_t data[]
Definition: elf.h:152
uint32_t description_size
Definition: elf.h:150
uint32_t name_size
Definition: elf.h:149
uint64_t physical_memory_offset
Definition: elf.h:62
uint64_t memory_size
Definition: elf.h:64
uint64_t file_offset
Definition: elf.h:60
ProgramHeaderType type
Definition: elf.h:58
uint64_t file_size
Definition: elf.h:63
uint64_t alignment
Definition: elf.h:65
uint32_t flags
Definition: elf.h:59
uint64_t memory_offset
Definition: elf.h:61
uint64_t memory_offset
Definition: elf.h:97
uint64_t file_size
Definition: elf.h:99
uint64_t file_offset
Definition: elf.h:98
uint64_t flags
Definition: elf.h:96
uint64_t entry_size
Definition: elf.h:103
SectionHeaderType type
Definition: elf.h:95
uint64_t alignment
Definition: elf.h:102
uint16_t section
Definition: elf.h:119
uint64_t size
Definition: elf.h:121
uint8_t other
Definition: elf.h:118
uint32_t name
Definition: elf.h:116
uint64_t value
Definition: elf.h:120
uint8_t info
Definition: elf.h:117