Skip to content

Commit

Permalink
Restore functionality to run from .so file on Android (flutter#5278)
Browse files Browse the repository at this point in the history
Flutter AOT builds can be done on Android using .so files (instead of
separate instruction/data snapshots) using the `--build-shared-library`
flag.

Running from .so files stopped working after the engine refactoring in
58e84c8, which this CL restores.

Issue flutter/flutter#17236
  • Loading branch information
mkustermann authored May 23, 2018
1 parent 4197e89 commit 812423d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
37 changes: 35 additions & 2 deletions runtime/dart_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ const char* DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData";
const char* DartSnapshot::kIsolateInstructionsSymbol =
"kDartIsolateSnapshotInstructions";

#if defined(OS_ANDROID)
// When assembling the .S file of the application, dart_bootstrap will prefix
// symbols via an `_` to ensure Mac's `dlsym()` can find it (Mac ABI prefixes C
// symbols with underscores).
// But Linux ABI does not prefix C symbols with underscores, so we have to
// explicitly look up the prefixed version.
#define SYMBOL_PREFIX "_"
#else
#define SYMBOL_PREFIX ""
#endif

static const char* kVMDataSymbolSo = SYMBOL_PREFIX "kDartVmSnapshotData";
static const char* kVMInstructionsSymbolSo = SYMBOL_PREFIX "kDartVmSnapshotInstructions";
static const char* kIsolateDataSymbolSo = SYMBOL_PREFIX "kDartIsolateSnapshotData";
static const char* kIsolateInstructionsSymbolSo = SYMBOL_PREFIX "kDartIsolateSnapshotInstructions";

std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
if (settings.vm_snapshot_data_path.size() > 0) {
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
Expand All @@ -29,6 +45,14 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
}
}

if (settings.application_library_path.size() > 0) {
auto shared_library = fml::NativeLibrary::Create(settings.application_library_path.c_str());
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
shared_library, kVMDataSymbolSo)) {
return source;
}
}

auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess();
return DartSnapshotBuffer::CreateWithSymbolInLibrary(
loaded_process, DartSnapshot::kVMDataSymbol);
Expand All @@ -47,7 +71,7 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
auto library =
fml::NativeLibrary::Create(settings.application_library_path.c_str());
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
library, DartSnapshot::kVMInstructionsSymbol)) {
library, kVMInstructionsSymbolSo)) {
return source;
}
}
Expand All @@ -67,6 +91,15 @@ std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
}
}

if (settings.application_library_path.size() > 0) {
auto library =
fml::NativeLibrary::Create(settings.application_library_path.c_str());
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
library, kIsolateDataSymbolSo)) {
return source;
}
}

auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess();
return DartSnapshotBuffer::CreateWithSymbolInLibrary(
loaded_process, DartSnapshot::kIsolateDataSymbol);
Expand All @@ -86,7 +119,7 @@ std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
auto library =
fml::NativeLibrary::Create(settings.application_library_path.c_str());
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
library, DartSnapshot::kIsolateInstructionsSymbol)) {
library, kIsolateInstructionsSymbolSo)) {
return source;
}
}
Expand Down
8 changes: 7 additions & 1 deletion shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ blink::Settings SettingsFromCommandLine(const fxl::CommandLine& command_line) {
command_line.GetOptionValue(FlagForSwitch(Switch::Packages),
&settings.packages_file_path);

std::string aot_shared_library_path;
command_line.GetOptionValue(FlagForSwitch(Switch::AotSharedLibraryPath),
&aot_shared_library_path);

std::string aot_snapshot_path;
command_line.GetOptionValue(FlagForSwitch(Switch::AotSnapshotPath),
&aot_snapshot_path);
Expand All @@ -191,7 +195,9 @@ blink::Settings SettingsFromCommandLine(const fxl::CommandLine& command_line) {
FlagForSwitch(Switch::AotIsolateSnapshotInstructions),
&aot_isolate_snapshot_instr_filename);

if (aot_snapshot_path.size() > 0) {
if (aot_shared_library_path.size() > 0) {
settings.application_library_path = aot_shared_library_path;
} else if (aot_snapshot_path.size() > 0) {
settings.vm_snapshot_data_path = fml::paths::JoinPaths(
{aot_snapshot_path, aot_vm_snapshot_data_filename});
settings.vm_snapshot_instr_path = fml::paths::JoinPaths(
Expand Down

0 comments on commit 812423d

Please sign in to comment.