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_VM_ELF_H_
6#define RUNTIME_VM_ELF_H_
7
8#include "platform/globals.h"
9
10#if defined(DART_PRECOMPILER)
11#include "vm/allocation.h"
13#include "vm/datastream.h"
14#include "vm/growable_array.h"
15#include "vm/zone.h"
16#endif
17
18namespace dart {
19
20// The max page size on all supported architectures. Used to determine
21// the alignment of load segments, so that they are guaranteed page-aligned,
22// and no ELF section or segment should have a larger alignment.
23#if defined(DART_TARGET_OS_LINUX) && defined(TARGET_ARCH_ARM64)
24// Some Linux distributions on ARM64 select 64 KB page size.
25// Follow LLVM (https://reviews.llvm.org/D25079) and set maximum page size
26// to 64 KB for ARM64 Linux builds.
27static constexpr intptr_t kElfPageSize = 64 * KB;
28#elif defined(DART_TARGET_OS_ANDROID) && defined(TARGET_ARCH_IS_64_BIT)
29static constexpr intptr_t kElfPageSize = 64 * KB;
30#else
31static constexpr intptr_t kElfPageSize = 16 * KB;
32#endif
33
34#if defined(DART_PRECOMPILER)
35
36class Dwarf;
37class ProgramTable;
38class Section;
39class SectionTable;
40class SymbolTable;
41
42class Elf : public ZoneAllocated {
43 public:
44 enum class Type {
45 // A snapshot that should include segment contents.
47 // Separately compiled debugging information that should not include
48 // most segment contents.
49 DebugInfo,
50 };
51
52 Elf(Zone* zone, BaseWriteStream* stream, Type type, Dwarf* dwarf = nullptr);
53
54 static constexpr intptr_t kPageSize = kElfPageSize;
55
56 bool IsStripped() const { return dwarf_ == nullptr; }
57
58 Zone* zone() const { return zone_; }
59 const Dwarf* dwarf() const { return dwarf_; }
60 Dwarf* dwarf() { return dwarf_; }
61 const SymbolTable& symtab() const {
62 ASSERT(symtab_ != nullptr);
63 return *symtab_;
64 }
65 const SectionTable& section_table() const { return *section_table_; }
66
67 // Stores the information needed to appropriately generate a
68 // relocation from the target to the source at the given section offset.
69 struct Relocation {
70 size_t size_in_bytes;
71 intptr_t section_offset;
72 intptr_t source_label;
73 intptr_t source_offset;
74 intptr_t target_label;
75 intptr_t target_offset;
76
77 // Used when the corresponding offset is relative from the location of the
78 // relocation itself.
79 static constexpr intptr_t kSelfRelative = -1;
80 // Used when the corresponding offset is relative to the start of the
81 // snapshot.
82 static constexpr intptr_t kSnapshotRelative = -2;
83
84 Relocation(size_t size_in_bytes,
85 intptr_t section_offset,
86 intptr_t source_label,
87 intptr_t source_offset,
88 intptr_t target_label,
89 intptr_t target_offset)
90 : size_in_bytes(size_in_bytes),
91 section_offset(section_offset),
92 source_label(source_label),
93 source_offset(source_offset),
94 target_label(target_label),
95 target_offset(target_offset) {
96 // Other than special values, all labels should be positive.
97 ASSERT(source_label > 0 || source_label == kSelfRelative ||
98 source_label == kSnapshotRelative);
99 ASSERT(target_label > 0 || target_label == kSelfRelative ||
100 target_label == kSnapshotRelative);
101 }
102 };
103
104 // Stores the information needed to appropriately generate a symbol
105 // during finalization.
106 struct SymbolData {
107 const char* name;
108 intptr_t type;
109 intptr_t offset;
110 size_t size;
111 // A positive unique ID only used internally in the Dart VM, not part of
112 // the Elf output.
113 intptr_t label;
114
115 SymbolData(const char* name,
116 intptr_t type,
117 intptr_t offset,
118 size_t size,
119 intptr_t label)
120 : name(name), type(type), offset(offset), size(size), label(label) {
121 ASSERT(label > 0);
122 }
123 };
124
125 // Must be the same value as the values returned by ImageWriter::SectionLabel
126 // for the appropriate section and vm values.
127 static constexpr intptr_t kVmBssLabel = 5;
128 static constexpr intptr_t kIsolateBssLabel = 6;
129 static constexpr intptr_t kBuildIdLabel = 7;
130
131 void AddText(const char* name,
132 intptr_t label,
133 const uint8_t* bytes,
134 intptr_t size,
135 const ZoneGrowableArray<Relocation>* relocations,
136 const ZoneGrowableArray<SymbolData>* symbol);
137 void AddROData(const char* name,
138 intptr_t label,
139 const uint8_t* bytes,
140 intptr_t size,
141 const ZoneGrowableArray<Relocation>* relocations,
142 const ZoneGrowableArray<SymbolData>* symbols);
143
144 void Finalize();
145
146 private:
147 static constexpr const char kBuildIdNoteName[] = ".note.gnu.build-id";
148 static constexpr const char kTextName[] = ".text";
149 static constexpr const char kDataName[] = ".rodata";
150 static constexpr const char kBssName[] = ".bss";
151 static constexpr const char kDynamicTableName[] = ".dynamic";
152
153 void CreateBSS();
154 void GenerateBuildId();
155 void InitializeSymbolTables();
156 void FinalizeDwarfSections();
157 void FinalizeEhFrame();
158 void ComputeOffsets();
159
160 Zone* const zone_;
161 BaseWriteStream* const unwrapped_stream_;
162 const Type type_;
163
164 // If nullptr, then the ELF file should be stripped of static information like
165 // the static symbol table (and its corresponding string table).
166 Dwarf* const dwarf_;
167
168 // Contains all sections that will have entries in the section header table.
169 SectionTable* const section_table_;
170
171 // Contains all segments in the program header table. Set after finalizing
172 // the section table.
173 ProgramTable* program_table_ = nullptr;
174
175 // The static tables are always created for use in relocation calculations,
176 // even though they may not end up in the final ELF file.
177 SymbolTable* symtab_ = nullptr;
178
179 friend class SectionTable; // For section name static fields.
180};
181
182#endif // DART_PRECOMPILER
183
184} // namespace dart
185
186#endif // RUNTIME_VM_ELF_H_
GLenum type
#define ASSERT(E)
Definition: dart_vm.cc:33
const char *const name
static constexpr intptr_t kPageSize
Definition: page.h:27
constexpr intptr_t KB
Definition: globals.h:528
static constexpr intptr_t kElfPageSize
Definition: elf.h:31
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SeparatedVector2 offset