Flutter Engine
The Flutter Engine
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
5#include "flutter/testing/elf_loader.h"
6
7#include <utility>
8
9#include "flutter/fml/file.h"
10#include "flutter/fml/paths.h"
11#include "flutter/runtime/dart_vm.h"
12#include "flutter/testing/testing.h"
13
14namespace flutter {
15namespace testing {
16
19 return {};
20 }
21
22 const auto elf_path =
23 fml::paths::JoinPaths({GetFixturesPath(), std::move(elf_filename)});
24
25 if (!fml::IsFile(elf_path)) {
26 FML_LOG(ERROR) << "App AOT file does not exist for this fixture. Attempts "
27 "to launch the Dart VM with these AOT symbols will fail.";
28 return {};
29 }
30
32
33#if OS_FUCHSIA
34 // TODO(gw280): https://github.com/flutter/flutter/issues/50285
35 // Dart doesn't implement Dart_LoadELF on Fuchsia
36 FML_LOG(ERROR) << "Dart doesn't implement Dart_LoadELF on Fuchsia";
37 return {};
38#else
39 // Must not be freed.
40 const char* error = nullptr;
41
42 auto loaded_elf =
43 Dart_LoadELF(elf_path.c_str(), // file path
44 0, // file offset
45 &error, // error (out)
46 &symbols.vm_snapshot_data, // vm snapshot data (out)
47 &symbols.vm_snapshot_instrs, // vm snapshot instrs (out)
48 &symbols.vm_isolate_data, // vm isolate data (out)
49 &symbols.vm_isolate_instrs // vm isolate instr (out)
50 );
51
52 if (loaded_elf == nullptr) {
54 << "Could not fetch AOT symbols from loaded ELF. Attempts "
55 "to launch the Dart VM with these AOT symbols will fail. Error: "
56 << error;
57 return {};
58 }
59
60 symbols.loaded_elf.reset(loaded_elf);
61
62 return symbols;
63#endif // OS_FUCHSIA
64}
65
67 std::string elf_split_filename) {
69 return {};
70 }
71
72 const auto elf_path =
73 fml::paths::JoinPaths({GetFixturesPath(), std::move(elf_split_filename)});
74
75 if (!fml::IsFile(elf_path)) {
76 // We do not log here, as there is no expectation for a split library to
77 // exist.
78 return {};
79 }
80
82
83#if OS_FUCHSIA
84 // TODO(gw280): https://github.com/flutter/flutter/issues/50285
85 // Dart doesn't implement Dart_LoadELF on Fuchsia
86 FML_LOG(ERROR) << "Dart doesn't implement Dart_LoadELF on Fuchsia";
87 return {};
88#else
89 // Must not be freed.
90 const char* error = nullptr;
91
92 auto loaded_elf =
93 Dart_LoadELF(elf_path.c_str(), // file path
94 0, // file offset
95 &error, // error (out)
96 &symbols.vm_snapshot_data, // vm snapshot data (out)
97 &symbols.vm_snapshot_instrs, // vm snapshot instrs (out)
98 &symbols.vm_isolate_data, // vm isolate data (out)
99 &symbols.vm_isolate_instrs // vm isolate instr (out)
100 );
101
102 if (loaded_elf == nullptr) {
104 << "Could not fetch AOT symbols from loaded ELF. Attempts "
105 "to launch the Dart VM with these AOT symbols will fail. Error: "
106 << error;
107 return {};
108 }
109
110 symbols.loaded_elf.reset(loaded_elf);
111
112 return symbols;
113#endif
114}
115
117 const ELFAOTSymbols& symbols) {
119 return false;
120 }
121 settings.vm_snapshot_data = [&]() {
122 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_data, 0u);
123 };
124 settings.isolate_snapshot_data = [&]() {
125 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_data, 0u);
126 };
127 settings.vm_snapshot_instr = [&]() {
128 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_snapshot_instrs,
129 0u);
130 };
131 settings.isolate_snapshot_instr = [&]() {
132 return std::make_unique<fml::NonOwnedMapping>(symbols.vm_isolate_instrs,
133 0u);
134 };
135 return true;
136}
137
138} // namespace testing
139} // namespace flutter
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:205
const uint8_t uint32_t uint32_t GError ** error
#define FML_LOG(severity)
Definition: logging.h:82
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:17
bool PrepareSettingsForAOTWithSymbols(Settings &settings, const ELFAOTSymbols &symbols)
Prepare the settings objects various AOT mappings resolvers with the symbols already loaded....
Definition: elf_loader.cc:116
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:66
std::string JoinPaths(std::initializer_list< std::string > components)
Definition: paths.cc:14
bool IsFile(const std::string &path)
Definition: file_posix.cc:146
DART_EXPORT Dart_LoadedElf * Dart_LoadELF(const char *filename, uint64_t file_offset, const char **error, const uint8_t **vm_snapshot_data, const uint8_t **vm_snapshot_instrs, const uint8_t **vm_isolate_data, const uint8_t **vm_isolate_instrs)
Please see documentation for Dart_LoadElf_Fd.
Definition: elf_loader.cc:590
#define ERROR(message)
Definition: elf_loader.cc:260