Skip to content

Use PE/COFF AOT snapshots for Windows x64#187594

Open
linzj wants to merge 2 commits into
flutter:masterfrom
linzj:port-windows-aot-app-object
Open

Use PE/COFF AOT snapshots for Windows x64#187594
linzj wants to merge 2 commits into
flutter:masterfrom
linzj:port-windows-aot-app-object

Conversation

@linzj
Copy link
Copy Markdown

@linzj linzj commented Jun 5, 2026

Summary

Enables Windows x64 profile/release AOT bundles to consume a PE/COFF AOT DLL instead of the previous ELF snapshot path.

This change:

  • adds an embedder AOT data source for native DLL paths on Windows
  • routes Windows x64 bundles through the DLL AOT data source
  • keeps Windows ARM64 on the existing ELF AOT data source
  • updates flutter_tools to request app-aot-pecoff-obj for Windows x64 only
  • links the generated COFF object with MSVC link.exe
  • keeps generated PDBs out of the shipped app bundle; with --split-debug-info, the PDB is written only to the split symbols directory

Companion Dart SDK PR: dart-lang/sdk#63532

Validation

  • Ran dart format over the changed flutter_tools Dart files and clang-format over the changed engine C++ files.
  • python flutter/testing/run_tests.py --variant=host_debug_unopt --type=engine --engine-filter=flutter_windows_unittests
    • ran flutter_windows_unittests.exe --repeat=2
    • completed 744 test executions successfully
  • ninja -C out/host_profile_unopt gen_snapshot flutter_windows
  • Built a default flutter create Windows x64 profile app with the local engine and --extra-gen-snapshot-options=--no-strip.
  • Verified build/windows/x64/runner/Profile/data/app.so is COFF-x86-64 and exports only _kDartSnapshotData and _kDartSnapshotText.
  • Verified the shipped app data directory contains no PDB; the CodeView debug directory points at .dart_tool/flutter_build/.../app.pdb.
  • Verified llvm-readobj --unwind app.so reports 8211 RuntimeFunction entries and 47 shared UnwindInfoAddress values.
  • Verified with cdb that a breakpoint in app!RenderObject.layout+0xb unwinds through Dart AOT frames, Flutter native frames, and Windows system frames.

Representative cdb kv stack excerpt:

app!RenderObject.layout+0xb [package:flutter/src/rendering/object.dart @ 2797]
app!RenderView.performLayout+0x7c [package:flutter/src/rendering/view.dart @ 292]
app!PipelineOwner.flushLayout+...
app!stub InvokeDartCode+0xdf
flutter_windows!dart::InvokeDartCode+0x8a [flutter/third_party/dart/runtime/vm/dart_entry.cc @ 126]
flutter_windows!dart::DartEntry::InvokeFunction+...
flutter_windows!flutter::TaskRunnerWindow::WndProc+...
USER32!UserCallWinProcCheckWow+...
USER32!DispatchMessageWorker+...
KERNEL32!BaseThreadInitThunk+0x10
ntdll!RtlUserThreadStart+0x2b

@linzj linzj requested review from a team and loic-sharma as code owners June 5, 2026 03:49
@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 Jun 5, 2026
Copy link
Copy Markdown
Contributor

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

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 adds support for compiling and linking Windows x64 AOT snapshots into a DLL using Visual Studio's linker. Feedback on the changes includes a recommendation to remove {BUILD_DIR}/app.pdb from the build target outputs to prevent breaking incremental builds when --split-debug-info is enabled. Additionally, it is suggested to simplify embedder.cc by removing the redundant ResolveAOTSnapshotSymbol helper function and calling ResolveSymbol directly.

Comment on lines +436 to +439
if (targetPlatform == TargetPlatform.windows_x64) ...const <Source>[
Source.pattern('{BUILD_DIR}/app.o'),
Source.pattern('{BUILD_DIR}/app.pdb'),
],
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.

high

Listing {BUILD_DIR}/app.pdb in the target's outputs will break incremental builds when --split-debug-info is enabled.

When --split-debug-info is used, the PDB is written to the split symbols directory and any stale PDB in {BUILD_DIR} is deleted (as implemented in AOTSnapshotter.build). Because {BUILD_DIR}/app.pdb is listed as an output but does not exist after a split-debug-info build, the Flutter build system's dependency tracker will always treat this target as out-of-date and force a full AOT compilation on every subsequent build.

Since debug symbols are not required outputs for downstream targets (similar to how .dSYM or other debug symbols are not listed in outputs for iOS/macOS/Android), we should remove {BUILD_DIR}/app.pdb from the outputs list.

Suggested change
if (targetPlatform == TargetPlatform.windows_x64) ...const <Source>[
Source.pattern('{BUILD_DIR}/app.o'),
Source.pattern('{BUILD_DIR}/app.pdb'),
],
if (targetPlatform == TargetPlatform.windows_x64) ...const <Source>[
Source.pattern('{BUILD_DIR}/app.o'),
],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in d9cefc7: {BUILD_DIR}/app.pdb is no longer listed as an AOT target output. The snapshotter still produces/copies PDBs through the existing linker/split-debug-info path, but the build dependency tracker no longer requires {BUILD_DIR}/app.pdb to exist after split-debug-info builds.

Comment on lines +1707 to +1711
static const uint8_t* ResolveAOTSnapshotSymbol(
const fml::RefPtr<fml::NativeLibrary>& library,
const char* symbol_name) {
return library->ResolveSymbol(symbol_name);
}
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

This helper function is redundant and can be removed since we can call ResolveSymbol directly on the NativeLibrary instance.

References
  1. Suggest simplification and refactoring to enhance readability and maintainability. (link)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in d9cefc7: removed ResolveAOTSnapshotSymbol and call NativeLibrary::ResolveSymbol directly.

Comment on lines +1786 to +1789
aot_data->vm_snapshot_data = ResolveAOTSnapshotSymbol(
aot_data->native_library, "_kDartSnapshotData");
aot_data->vm_snapshot_instrs = ResolveAOTSnapshotSymbol(
aot_data->native_library, "_kDartSnapshotText");
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

The ResolveAOTSnapshotSymbol helper function is redundant as it only forwards the call to library->ResolveSymbol. We can simplify the code and improve maintainability by calling ResolveSymbol directly.

      aot_data->vm_snapshot_data =
          aot_data->native_library->ResolveSymbol("_kDartSnapshotData");
      aot_data->vm_snapshot_instrs =
          aot_data->native_library->ResolveSymbol("_kDartSnapshotText");
References
  1. Suggest simplification and refactoring to enhance readability and maintainability. (link)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in d9cefc7: both _kDartSnapshotData and _kDartSnapshotText now resolve directly through aot_data->native_library->ResolveSymbol(...).

@linzj linzj force-pushed the port-windows-aot-app-object branch from d9cefc7 to bf60403 Compare June 5, 2026 06:36
@linzj linzj force-pushed the port-windows-aot-app-object branch from bf60403 to b5aed1f Compare June 5, 2026 06:41
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