Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
elf_loader.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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
6
7#include <utility>
8
9#include "flutter/fml/file.h"
10#include "flutter/fml/paths.h"
13
14namespace flutter::testing {
15
18 return {};
19 }
20
21 const auto elf_path =
22 fml::paths::JoinPaths({GetFixturesPath(), std::move(elf_filename)});
23
24 if (!fml::IsFile(elf_path)) {
25 FML_LOG(ERROR) << "App AOT file does not exist for this fixture. Attempts "
26 "to launch the Dart VM with these AOT symbols will fail.";
27 return {};
28 }
29
30 ELFAOTSymbols symbols;
31
32#if OS_FUCHSIA
33 // TODO(gw280): https://github.com/flutter/flutter/issues/50285
34 // Dart doesn't implement Dart_LoadELF on Fuchsia
35 FML_LOG(ERROR) << "Dart doesn't implement Dart_LoadELF on Fuchsia";
36 return {};
37#else
38 // Must not be freed.
39 const char* error = nullptr;
40
41 auto loaded_elf =
42 Dart_LoadELF(elf_path.c_str(), // file path
43 0, // file offset
44 &error, // error (out)
45 &symbols.vm_isolate_data, // vm isolate data (out)
46 &symbols.vm_isolate_instrs // vm isolate instr (out)
47 );
48 if (loaded_elf != nullptr) {
49 symbols.vm_snapshot_data = symbols.vm_isolate_data;
50 symbols.vm_snapshot_instrs = symbols.vm_isolate_instrs;
51 }
52
53 if (loaded_elf == nullptr) {
54 FML_LOG(ERROR)
55 << "Could not fetch AOT symbols from loaded ELF. Attempts "
56 "to launch the Dart VM with these AOT symbols will fail. Error: "
57 << error;
58 return {};
59 }
60
61 symbols.loaded_elf.reset(loaded_elf);
62
63 return symbols;
64#endif // OS_FUCHSIA
65}
66
68 std::string elf_split_filename) {
70 return {};
71 }
72
73 const auto elf_path =
74 fml::paths::JoinPaths({GetFixturesPath(), std::move(elf_split_filename)});
75
76 if (!fml::IsFile(elf_path)) {
77 // We do not log here, as there is no expectation for a split library to
78 // exist.
79 return {};
80 }
81
82 ELFAOTSymbols symbols;
83
84#if OS_FUCHSIA
85 // TODO(gw280): https://github.com/flutter/flutter/issues/50285
86 // Dart doesn't implement Dart_LoadELF on Fuchsia
87 FML_LOG(ERROR) << "Dart doesn't implement Dart_LoadELF on Fuchsia";
88 return {};
89#else
90 // Must not be freed.
91 const char* error = nullptr;
92
93 auto loaded_elf =
94 Dart_LoadELF(elf_path.c_str(), // file path
95 0, // file offset
96 &error, // error (out)
97 &symbols.vm_isolate_data, // vm isolate data (out)
98 &symbols.vm_isolate_instrs // vm isolate instr (out)
99 );
100 if (loaded_elf != nullptr) {
101 symbols.vm_snapshot_data = symbols.vm_isolate_data;
102 symbols.vm_snapshot_instrs = symbols.vm_isolate_instrs;
103 }
104
105 if (loaded_elf == nullptr) {
106 FML_LOG(ERROR)
107 << "Could not fetch AOT symbols from loaded ELF. Attempts "
108 "to launch the Dart VM with these AOT symbols will fail. Error: "
109 << error;
110 return {};
111 }
112
113 symbols.loaded_elf.reset(loaded_elf);
114
115 return symbols;
116#endif
117}
118
120 const ELFAOTSymbols& symbols) {
122 return false;
123 }
124 settings.vm_snapshot_data = [&]() {
125 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_data, 0u);
126 };
127 settings.isolate_snapshot_data = [&]() {
128 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_data, 0u);
129 };
130 settings.vm_snapshot_instr = [&]() {
131 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_instrs,
132 0u);
133 };
134 settings.isolate_snapshot_instr = [&]() {
135 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_instrs,
136 0u);
137 };
138 return true;
139}
140
141} // namespace flutter::testing
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition dart_vm.cc:177
const uint8_t uint32_t uint32_t GError ** error
#define FML_LOG(severity)
Definition logging.h:101
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary(std::string elf_filename)
Attempts to resolve AOT symbols from the portable ELF loader. This location is automatically resolved...
Definition elf_loader.cc:16
bool PrepareSettingsForAOTWithSymbols(Settings &settings, const ELFAOTSymbols &symbols)
Prepare the settings objects various AOT mappings resolvers with the symbols already loaded....
ELFAOTSymbols LoadELFSplitSymbolFromFixturesIfNeccessary(std::string elf_split_filename)
Attempts to resolve split loading unit AOT symbols from the portable ELF loader. If the dart code doe...
Definition elf_loader.cc:67
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
bool IsFile(const std::string &path)
MappingCallback isolate_snapshot_instr
Definition settings.h:123
MappingCallback isolate_snapshot_data
Definition settings.h:121
MappingCallback vm_snapshot_data
Definition settings.h:116
MappingCallback vm_snapshot_instr
Definition settings.h:118
const uint8_t * vm_snapshot_data
Definition elf_loader.h:34
const uint8_t * vm_snapshot_instrs
Definition elf_loader.h:35
const uint8_t * vm_isolate_instrs
Definition elf_loader.h:37
const uint8_t * vm_isolate_data
Definition elf_loader.h:36