diff --git a/engine/src/flutter/runtime/dart_snapshot.cc b/engine/src/flutter/runtime/dart_snapshot.cc index 4483ecd6c74..1c47cffd2ff 100644 --- a/engine/src/flutter/runtime/dart_snapshot.cc +++ b/engine/src/flutter/runtime/dart_snapshot.cc @@ -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 ResolveVMData(const Settings& settings) { if (settings.vm_snapshot_data_path.size() > 0) { if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( @@ -29,6 +45,14 @@ std::unique_ptr 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); @@ -47,7 +71,7 @@ std::unique_ptr ResolveVMInstructions( auto library = fml::NativeLibrary::Create(settings.application_library_path.c_str()); if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( - library, DartSnapshot::kVMInstructionsSymbol)) { + library, kVMInstructionsSymbolSo)) { return source; } } @@ -67,6 +91,15 @@ std::unique_ptr 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); @@ -86,7 +119,7 @@ std::unique_ptr ResolveIsolateInstructions( auto library = fml::NativeLibrary::Create(settings.application_library_path.c_str()); if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( - library, DartSnapshot::kIsolateInstructionsSymbol)) { + library, kIsolateInstructionsSymbolSo)) { return source; } } diff --git a/engine/src/flutter/shell/common/switches.cc b/engine/src/flutter/shell/common/switches.cc index 9e768824183..d53bdb1adfc 100644 --- a/engine/src/flutter/shell/common/switches.cc +++ b/engine/src/flutter/shell/common/switches.cc @@ -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); @@ -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(