Skip to content

Add --windows-aot-format to optionally build Windows x64 AOT snapshots as ELF again instead of PE/COFF - #194854

Open
krll-kov wants to merge 3 commits into
flutter:masterfrom
krll-kov:windows-aot-format
Open

krll-kov wants to merge 3 commits into
flutter:masterfrom
krll-kov:windows-aot-format

Conversation

@krll-kov

@krll-kov krll-kov commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Towards: #187594

PR adds optional flutter build windows --windows-aot-format=elf, which brings back optional builds for Windows x64 AOT snapshot as ELF, as before #187594 (functionality for ELF was still present for Windows ARM and Linux). The engine picks the loader from the file's magic number. For apps that choose ELF, this avoids the following PE/COFF problems (discussion from pr 187594):

Description PE/COFF ELF
app.so size with --obfuscate --split-debug-info (counter app) 3,395,584 bytes, +21.9% 2,786,264 bytes
Stack trace symbolization the PDB has 2 public symbols and no Dart functions, so bUa (Byb:21) can't be decoded .symbols decodes to innerFrame (main.dart:21:22) with package:native_stack_traces
Replacing app.so while the app runs (in-place updaters) file is locked can be overwritten
Antivirus detections (false positives even on default counter app) counter app: 1 (Cynet), larger app: 3 (Cynet, Elastic, Huorong) 0
Reproducible builds 28 bytes differ (TimeDateStamp and PDB GUID) identical output
PDB path in app.so absolute path from the build machine none
Requires Visual Studio link.exe yes no
  • ARM64 Windows untouched, it uses ELF as before
  • PE/COFF stays the default, with all the issues above. The option avoids them and does not fix them.
  • Choosing ELF gives up the PE/COFF benefits: about 4 MB less private memory, AOT load in 0.71 ms vs 2.5 ms for ELF, and native debugger support.

Also fixes a crash when app.so is missing or invalid in a non-ASCII path: streaming aot_library_path_ into FML_LOG converts it to the ANSI code page. Both logs now use the UTF-8 path_string. Regressed in #174471, missed by #179528.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.

@krll-kov
krll-kov marked this pull request as ready for review October 20, 2026 11:55
@krll-kov
krll-kov requested a review from a team as a code owner October 20, 2026 11:55
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop team-windows Owned by the Windows platform team labels Oct 20, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables support for both ELF and PE/COFF AOT snapshot formats on Windows x64. It replaces architecture-based compile-time checks with runtime magic-number detection of the AOT library format in FlutterProjectBundle::LoadAotData, and introduces a --windows-aot-format build option to configure the target format. Feedback suggests explicitly including the Abseil header for absl::StatusOr to follow the "Include What You Use" style guide, and refactoring GetAotDataSourceType to accept const std::filesystem::path& to avoid redundant path conversions on Windows.

Comment on lines +12 to 14
#include <memory>
#include <optional>
#include <string_view>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the Google C++ Style Guide (referenced in the Flutter Repository Style Guide), you should directly include the headers for all symbols used in the file ("Include What You Use"). Since absl::StatusOr is used in this file, please explicitly include <third_party/abseil-cpp/absl/status/statusor.h>.

Suggested change
#include <memory>
#include <optional>
#include <string_view>
#include <memory>
#include <optional>
#include <string_view>
#include "third_party/abseil-cpp/absl/status/statusor.h"
References
  1. The Google C++ Style Guide (followed by Flutter C++ code) mandates 'Include What You Use' to avoid relying on transitive includes. (link)

@krll-kov krll-kov Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

it's already there, gemini glitched

Comment on lines +77 to +83
absl::StatusOr<FlutterEngineAOTDataSourceType> GetAotDataSourceType(
const std::string& path) {
constexpr uint8_t kElfMagic[] = {0x7f, 'E', 'L', 'F'};
constexpr uint8_t kPeMagic[] = {'M', 'Z'};

std::unique_ptr<fml::FileMapping> mapping =
fml::FileMapping::CreateReadOnly(path);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid unnecessary path conversions and potential issues with non-ASCII characters on Windows, GetAotDataSourceType should take const std::filesystem::path& instead of const std::string&. This allows us to pass aot_library_path_ directly and use the wide-string overload of fml::FileMapping::CreateReadOnly via path.wstring().

Suggested change
absl::StatusOr<FlutterEngineAOTDataSourceType> GetAotDataSourceType(
const std::string& path) {
constexpr uint8_t kElfMagic[] = {0x7f, 'E', 'L', 'F'};
constexpr uint8_t kPeMagic[] = {'M', 'Z'};
std::unique_ptr<fml::FileMapping> mapping =
fml::FileMapping::CreateReadOnly(path);
absl::StatusOr<FlutterEngineAOTDataSourceType> GetAotDataSourceType(
const std::filesystem::path& path) {
constexpr uint8_t kElfMagic[] = {0x7f, 'E', 'L', 'F'};
constexpr uint8_t kPeMagic[] = {'M', 'Z'};
std::unique_ptr<fml::FileMapping> mapping =
fml::FileMapping::CreateReadOnly(path.wstring());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileMapping::CreateReadOnly has no wide-string overload. path_string is UTF-8 and fml::OpenFile converts it with Utf8ToWideString, so non-ASCII paths work (checked with Cyrillic and CJK paths).

Comment on lines +175 to +176
absl::StatusOr<FlutterEngineAOTDataSourceType> type =
GetAotDataSourceType(path_string);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Pass aot_library_path_ directly to GetAotDataSourceType now that it accepts const std::filesystem::path&.

Suggested change
absl::StatusOr<FlutterEngineAOTDataSourceType> type =
GetAotDataSourceType(path_string);
absl::StatusOr<FlutterEngineAOTDataSourceType> type =
GetAotDataSourceType(aot_library_path_);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant