Flutter Engine
 
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_snapshot_data, // vm snapshot data (out)
46 &symbols.vm_snapshot_instrs, // vm snapshot instrs (out)
47 &symbols.vm_isolate_data, // vm isolate data (out)
48 &symbols.vm_isolate_instrs // vm isolate instr (out)
49 );
50
51 if (loaded_elf == nullptr) {
52 FML_LOG(ERROR)
53 << "Could not fetch AOT symbols from loaded ELF. Attempts "
54 "to launch the Dart VM with these AOT symbols will fail. Error: "
55 << error;
56 return {};
57 }
58
59 symbols.loaded_elf.reset(loaded_elf);
60
61 return symbols;
62#endif // OS_FUCHSIA
63}
64
66 std::string elf_split_filename) {
68 return {};
69 }
70
71 const auto elf_path =
72 fml::paths::JoinPaths({GetFixturesPath(), std::move(elf_split_filename)});
73
74 if (!fml::IsFile(elf_path)) {
75 // We do not log here, as there is no expectation for a split library to
76 // exist.
77 return {};
78 }
79
80 ELFAOTSymbols symbols;
81
82#if OS_FUCHSIA
83 // TODO(gw280): https://github.com/flutter/flutter/issues/50285
84 // Dart doesn't implement Dart_LoadELF on Fuchsia
85 FML_LOG(ERROR) << "Dart doesn't implement Dart_LoadELF on Fuchsia";
86 return {};
87#else
88 // Must not be freed.
89 const char* error = nullptr;
90
91 auto loaded_elf =
92 Dart_LoadELF(elf_path.c_str(), // file path
93 0, // file offset
94 &error, // error (out)
95 &symbols.vm_snapshot_data, // vm snapshot data (out)
96 &symbols.vm_snapshot_instrs, // vm snapshot instrs (out)
97 &symbols.vm_isolate_data, // vm isolate data (out)
98 &symbols.vm_isolate_instrs // vm isolate instr (out)
99 );
100
101 if (loaded_elf == nullptr) {
102 FML_LOG(ERROR)
103 << "Could not fetch AOT symbols from loaded ELF. Attempts "
104 "to launch the Dart VM with these AOT symbols will fail. Error: "
105 << error;
106 return {};
107 }
108
109 symbols.loaded_elf.reset(loaded_elf);
110
111 return symbols;
112#endif
113}
114
116 const ELFAOTSymbols& symbols) {
118 return false;
119 }
120 settings.vm_snapshot_data = [&]() {
121 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_data, 0u);
122 };
123 settings.isolate_snapshot_data = [&]() {
124 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_data, 0u);
125 };
126 settings.vm_snapshot_instr = [&]() {
127 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_instrs,
128 0u);
129 };
130 settings.isolate_snapshot_instr = [&]() {
131 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_instrs,
132 0u);
133 };
134 return true;
135}
136
137} // 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:176
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:65
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