Skip to content

[native_assets] Keep a dylib's install name in flutter test when its path does not fit - #194802

Merged
dcharkes merged 5 commits into
flutter:masterfrom
DenisovAV:macos-tester-install-name-fallback
Nov 16, 2026
Merged

dcharkes merged 5 commits into
flutter:masterfrom
DenisovAV:macos-tester-install-name-fallback

Conversation

@DenisovAV

@DenisovAV DenisovAV commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

On macOS, flutter test sets each code asset's install name to its absolute path under build/native_assets/macos/. A prebuilt dylib linked without -headerpad_max_install_names often has no room for that path. Then install_name_tool fails and the whole run exits.

Assets built by the hook itself with CBuilder do not hit this: it links with -encryptable, which leaves room.

With this change, the tester falls back only when install_name_tool reports that the larger load commands do not fit, and only when the dylib's directory is a canonical path:

  • the dylib keeps its own install name, and its dependencies are still changed;
  • dylibs that depend on it still reference it by the absolute path, and so does the manifest;
  • a non-fatal warning names the asset and the install name it kept.

flutter run -d flutter-tester copies code assets the same way, so the fallback applies there too.

Dylibs whose new name fits are unchanged, so they keep the guarantee from #190819 that the install name equals the manifest path. App builds (macOS, iOS) still fail on any install_name_tool error.

Keeping the install name is safe here because dyld matches a load against the path an image was loaded from. The manifest and the dependents all use the same absolute path. I checked this outside Flutter:

  • I replaced the file under a running process and loaded it again by the same path. dyld returned the same image, both with the short install name and with the path as the install name.
  • With a non-canonical path (a symlink, or /./), this holds until the file is replaced. dyld records an image under its real path, so after a replacement, a load through a symlinked directory gave a second copy unless the install name was the requested path. That is why the tester keeps the install name only when the directory resolves to itself. Through a symlink it fails as before.

A kept install name also stays visible to dyld for the rest of the process. If it is an @rpath/ name, a later load of that name, or of the dylib's bare file name, gets this image.

There is one limitation: a dylib without room still fails if changing its references to other code assets makes its load commands larger, as for a prebuilt that references them by @rpath/ names.

Under -v, the warning still fails a run with --fatal-warnings. That is an older, separate issue: VerboseLogger ignores fatal: false for every warning.

Tests:

  • unit tests for setInstallNamesDylib, with the exact error message whether or not the retry ran;
  • unit tests for the tester: two dylibs, one of them without room, and a symlinked build directory, where it still fails;
  • tests that app builds still fail, on macOS and on iOS;
  • a macOS integration test that links the package's main library with plain clang and the install name @rpath/m.dylib, then runs flutter test. Without the fix, it fails with the error from the issue. The short install name makes the test take the fallback for any temp path. Before, with TMPDIR=/tmp, the new name fit, and the test failed for lack of the warning.

I also ran the repro from the issue. I also ran a package where Dart calls into a dylib without room both directly and through a dylib that depends on it. A counter in that dylib goes 1, 2, 3, so the process has one copy.

Fixes #194800

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

…path does not fit

On macOS, flutter test sets each code asset's install name to its absolute
path under build/native_assets/macos/. A prebuilt dylib linked without
-headerpad_max_install_names has no room for a long path, install_name_tool
fails, and the whole run exits.

The tester now falls back only when install_name_tool reports that the
larger load commands do not fit: the dylib keeps its own install name, its
dependents are still pointed at the absolute path, and a warning names the
asset. App builds are unchanged.

Fixes flutter#194800
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. a: desktop Running on desktop team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Oct 19, 2026
The tester now gets its logger as a parameter instead of using globals.
The warning names the install name the dylib kept and is not fatal, so
--fatal-warnings does not fail a run whose assets load. The docs state
why keeping the install name is safe and when it still fails.

Tests cover two dylibs where only one keeps its install name, app builds
still failing, and a macOS integration test that links a library with
plain clang, which leaves no header room.

@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 implements a fallback mechanism for macOS native assets when a dylib's header has no room for its absolute path, allowing the tool to keep the original install name and update only its dependencies. The review feedback recommends optimizing this process by filtering out redundant self-references in dependency changes, adding a check to avoid running install_name_tool when there are no dependencies to change, and updating the corresponding tests.

Comment on lines +110 to +116
final changeDependencies = <String>[
for (final MapEntry<String, String> entry in oldToNewInstallNames.entries) ...<String>[
'-change',
entry.key,
entry.value,
],
];

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

We can optimize the dependency changes by filtering out self-references where entry.value == newInstallName. Since a dylib does not depend on itself, passing its own mapping to -change is redundant and can be avoided.

Suggested change
final changeDependencies = <String>[
for (final MapEntry<String, String> entry in oldToNewInstallNames.entries) ...<String>[
'-change',
entry.key,
entry.value,
],
];
final changeDependencies = <String>[
for (final MapEntry<String, String> entry in oldToNewInstallNames.entries)
if (entry.value != newInstallName) ...<String>[
'-change',
entry.key,
entry.value,
],
];
References
  1. Suggest simplification and refactoring to enhance readability and maintainability. (link)

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.

I'll leave this as is. A dylib does not load itself, so -change with its own install name matches no load command and does nothing: on a dylib with no header room it exits 0 even with a 3000-character new path. Passing every asset's mapping, its own included, is also what main does today; this PR only moves the list into a variable, so filtering it would change the app build's commands too.

Comment on lines +128 to +135
if (keepInstallNameIfItDoesNotFit &&
setInstallNamesResult.stderr.contains(_loadCommandsDoNotFit)) {
final RunResult changeDependenciesResult = await globals.processUtils.run(<String>[
'xcrun',
'install_name_tool',
...changeDependencies,
dylibFile.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

If changeDependencies is empty (which can happen if there are no other dependencies to change after filtering out self-references), running install_name_tool with no options will fail with a no-option specified error. We should check if changeDependencies is empty and return false directly to avoid an unnecessary and failing process invocation.

Suggested change
if (keepInstallNameIfItDoesNotFit &&
setInstallNamesResult.stderr.contains(_loadCommandsDoNotFit)) {
final RunResult changeDependenciesResult = await globals.processUtils.run(<String>[
'xcrun',
'install_name_tool',
...changeDependencies,
dylibFile.path,
]);
if (keepInstallNameIfItDoesNotFit &&
setInstallNamesResult.stderr.contains(_loadCommandsDoNotFit)) {
if (changeDependencies.isEmpty) {
return false;
}
final RunResult changeDependenciesResult = await globals.processUtils.run(<String>[
'xcrun',
'install_name_tool',
...changeDependencies,
dylibFile.path,
]);
References
  1. Suggest simplification and refactoring to enhance readability and maintainability. (link)

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.

This only applies with the filtering above. Without it the list is never empty here: every dylib's own install names go into the map before any of them is renamed.

Comment on lines +312 to +319
const changeDependencies = <String>[
'-change',
'@rpath/libfoo.dylib',
newInstallName,
'-change',
'@rpath/libbar.dylib',
'/project/build/native_assets/macos/libbar.dylib',
];

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

Update the test's expected changeDependencies to match the filtered list that excludes the self-reference mapping.

Suggested change
const changeDependencies = <String>[
'-change',
'@rpath/libfoo.dylib',
newInstallName,
'-change',
'@rpath/libbar.dylib',
'/project/build/native_assets/macos/libbar.dylib',
];
const changeDependencies = <String>[
'-change',
'@rpath/libbar.dylib',
'/project/build/native_assets/macos/libbar.dylib',
];

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.

Follows the first suggestion, which I'm not taking (see the thread on native_assets_host.dart).

Comment on lines +466 to +538
const changeDependencies = <String>[
'-change',
'@rpath/libbuz.dylib',
buzPath,
'-change',
'@rpath/libbar.dylib',
barPath,
];
processManager.addCommands(<FakeCommand>[
const FakeCommand(
command: <String>['xcrun', 'lipo', '-create', '-output', buzPath, 'arm64/libbuz.dylib'],
),
const FakeCommand(
command: <String>['xcrun', 'otool', '-D', buzPath],
stdout: '$buzPath (architecture arm64):\n@rpath/libbuz.dylib',
),
const FakeCommand(
command: <String>['xcrun', 'lipo', '-create', '-output', barPath, 'arm64/libbar.dylib'],
),
const FakeCommand(
command: <String>['xcrun', 'otool', '-D', barPath],
stdout: '$barPath (architecture arm64):\n@rpath/libbar.dylib',
),
// libbuz has room, and references libbar by its path.
const FakeCommand(
command: <String>[
'xcrun',
'install_name_tool',
'-id',
buzPath,
...changeDependencies,
buzPath,
],
),
const FakeCommand(
command: <String>[
'xcrun',
'codesign',
'--force',
'--sign',
'-',
'--timestamp=none',
buzPath,
],
),
// libbar has no room for its path, so it keeps its install name and
// only its dependencies are changed.
const FakeCommand(
command: <String>[
'xcrun',
'install_name_tool',
'-id',
barPath,
...changeDependencies,
barPath,
],
exitCode: 1,
stderr: doesNotFit,
),
const FakeCommand(
command: <String>['xcrun', 'install_name_tool', ...changeDependencies, barPath],
),
const FakeCommand(
command: <String>[
'xcrun',
'codesign',
'--force',
'--sign',
'-',
'--timestamp=none',
barPath,
],
),

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

Update the test commands to reflect the filtered changeDependencies for each dylib, which now correctly excludes self-references.

        processManager.addCommands(<FakeCommand>[
          const FakeCommand(
            command: <String>['xcrun', 'lipo', '-create', '-output', buzPath, 'arm64/libbuz.dylib'],
          ),
          const FakeCommand(
            command: <String>['xcrun', 'otool', '-D', buzPath],
            stdout: '$buzPath (architecture arm64):\n@rpath/libbuz.dylib',
          ),
          const FakeCommand(
            command: <String>['xcrun', 'lipo', '-create', '-output', barPath, 'arm64/libbar.dylib'],
          ),
          const FakeCommand(
            command: <String>['xcrun', 'otool', '-D', barPath],
            stdout: '$barPath (architecture arm64):\n@rpath/libbar.dylib',
          ),
          // libbuz has room, and references libbar by its path.
          const FakeCommand(
            command: <String>[
              'xcrun',
              'install_name_tool',
              '-id',
              buzPath,
              '-change',
              '@rpath/libbar.dylib',
              barPath,
              buzPath,
            ],
          ),
          const FakeCommand(
            command: <String>[
              'xcrun',
              'codesign',
              '--force',
              '--sign',
              '-',
              '--timestamp=none',
              buzPath,
            ],
          ),
          // libbar has no room for its path, so it keeps its install name and
          // only its dependencies are changed.
          const FakeCommand(
            command: <String>[
              'xcrun',
              'install_name_tool',
              '-id',
              barPath,
              '-change',
              '@rpath/libbuz.dylib',
              buzPath,
              barPath,
            ],
            exitCode: 1,
            stderr: doesNotFit,
          ),
          const FakeCommand(
            command: <String>[
              'xcrun',
              'install_name_tool',
              '-change',
              '@rpath/libbuz.dylib',
              buzPath,
              barPath,
            ],
          ),
          const FakeCommand(
            command: <String>[
              'xcrun',
              'codesign',
              '--force',
              '--sign',
              '-',
              '--timestamp=none',
              barPath,
            ],
          ),
        ]);

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.

Follows the first suggestion, which I'm not taking (see the thread on native_assets_host.dart).

@dcharkes dcharkes 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.

overall lgtm!

}
if (keepInstallNameIfItDoesNotFit &&
setInstallNamesResult.stderr.contains(_loadCommandsDoNotFit)) {
final RunResult changeDependenciesResult = await globals.processUtils.run(<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.

maybe make this a private helper method with the newInstallName as optional param to avoid the command duplication.

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.

Done in 24a56cf: _runInstallNameTool takes newInstallName as an optional parameter and adds -id only when it is given.

'${changeDependenciesResult.stderr}',
);
}
throwToolExit(

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.

can we share this with the code above and have an ${if (keepInstallNameIfItDoesNotFit) ... } to avoid duplicating the error message?

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.

Done in the same commit, with one difference: the suffix depends on whether the retry ran (changeDependenciesResult != null), not on keepInstallNameIfItDoesNotFit. That way a different install_name_tool error with the flag set does not claim a retry happened.

@dcharkes

dcharkes commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

P.S. Feel free to ignore the code review bot comments when they are #$%. 🙃

Also, cc @bkonyi

@dcharkes dcharkes added the CICD Run CI/CD label Nov 4, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled.

…all-name-fallback

# Conflicts:
#	packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart
#	packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets_host.dart
#	packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart
#	packages/flutter_tools/test/general.shard/isolated/macos/native_assets_host_test.dart
…emp path

- dyld records an image under its real path, so through a symlinked build
  directory a dylib replaced under a running tester loaded as a second copy
  when it had kept its install name. The fallback now applies only when the
  dylib's directory has no symlinks; otherwise the tool exits as before.
- The integration test took the fallback only for package roots longer than
  about 57 characters, because rewriting the reference to `add` frees about
  40 bytes. The main library's install name is now `@rpath/m.dylib`, so the
  absolute path does not fit for any root; with TMPDIR=/tmp it failed before
  and passes now.
- Docs say why install names are rewritten, that a kept `@rpath/` name stays
  visible to dyld for the process, and when a dylib without room still fails.
- The warning says the new install name and dependency paths did not fit,
  and the error labels the stderr of the retry.
- Tests pin the error message of both paths, the symlink case and the iOS
  failure.
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 4, 2026
@DenisovAV

Copy link
Copy Markdown
Contributor Author

I merged master (675b044) to resolve the conflicts with #194052. 2f02880 adds three things from my own review of the change. The fallback now only applies when the dylib's directory has no symlinks: through a symlinked build directory, a dylib replaced under a running tester loaded as a second copy. The integration test now takes the fallback for any temp path; before, with TMPDIR=/tmp, it did not. And the docs now mention that a kept @rpath/ install name stays visible to dyld for the rest of the process.

Under -v the warning still fails --fatal-warnings, because VerboseLogger ignores fatal: false for every warning. That predates this PR, so I left it out.

@dcharkes dcharkes added the CICD Run CI/CD label Nov 4, 2026
@dcharkes dcharkes added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 5, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 5, 2026
@auto-submit

auto-submit Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/194802, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a member of flutter-hackers before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@dcharkes

dcharkes commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@vashworth @jmagman We need a second review.

@cbracken
cbracken requested a review from vashworth November 5, 2026 22:32
@dcharkes
dcharkes added this pull request to the merge queue Nov 16, 2026
Merged via the queue into flutter:master with commit c2df24d Nov 16, 2026
32 checks passed
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 16, 2026
flutter/flutter@1b95854...d8bd864

2026-11-16 [email protected] Roll Skia from f2790b0ea630 to 118eaff3deb4 (8 revisions) (flutter/flutter#196661)
2026-11-16 [email protected] [native_assets] Keep a dylib's install name in flutter test when its path does not fit (flutter/flutter#194802)
2026-11-16 [email protected] Reland "[android]: prewarms shaders when the context is created" (flutter/flutter#196579)
2026-11-16 [email protected] [flutter_tools] Bound Browser.close in Chromium.close (flutter/flutter#196211)
2026-11-16 [email protected] Roll Skia from e8ff7a4187ec to f2790b0ea630 (13 revisions) (flutter/flutter#196652)
2026-11-14 [email protected] Revert: Balance web_canvaskit_tests and web_skwasm_tests subshards by duration (flutter/flutter#196580)
2026-11-14 [email protected] Revert: Reland "[android]: prewarms shaders when the context is created" (flutter/flutter#196575)
2026-11-14 [email protected] [flutter_tools] Guard ExtensionManager initialization against concurrent disposal (flutter/flutter#196459)
2026-11-14 [email protected] [ImpellerC] Escape spaces in depfile paths (flutter/flutter#196555)
2026-11-14 [email protected] Reland "[android]: prewarms shaders when the context is created" (flutter/flutter#196549)
2026-11-14 [email protected] Balance web_canvaskit_tests and web_skwasm_tests subshards by duration (flutter/flutter#196260)
2026-11-13 [email protected] Safely return null on malformed stack trace line in StackFrame.fromStackTraceLine (flutter/flutter#194673)
2026-11-13 [email protected] Clarify that super.dispose() must be called synchronously (flutter/flutter#193416)
2026-11-13 [email protected] Consolidate exit-code parameters on runCommand with ExpectedExit (flutter/flutter#196479)
2026-11-13 [email protected] Support multi-view apps in widget test binding (flutter/flutter#194480)
2026-11-13 [email protected] Document using a ListView inside a Column (flutter/flutter#195145)
2026-11-13 [email protected] Add didChangeAlwaysUse24HourFormat to WidgetsBinding and update MediaQuery (flutter/flutter#196117)
2026-11-13 [email protected] Build local engine wasm configs on 32-core Linux bots (flutter/flutter#196284)
2026-11-13 [email protected] [Android] Fix Hybrid Composition resize deadlock (flutter/flutter#196255)
2026-11-13 [email protected] Roll Skia from 11f46cfe8838 to e8ff7a4187ec (9 revisions) (flutter/flutter#196557)
2026-11-13 [email protected] [Impeller] Fix SurfaceContextVK submission tracking and double HostBuffer reset (flutter/flutter#196064)
2026-11-13 [email protected] Manual roll Packages from 14f9933 to 015df97 (5 revisions) (flutter/flutter#196558)
2026-11-13 [email protected] Remove routes_transition_test from widgets (flutter/flutter#186620)
2026-11-13 [email protected] [flutter_tools] Replace TargetPlatform.simpleName with cpuArch (flutter/flutter#196264)
2026-11-13 [email protected] Add a deferred platform-view-created path to the shell and use it on Android (flutter/flutter#196342)
2026-11-13 [email protected] Optimize RenderSliverVariedExtentList and introduce protected itemExtentOf API in RenderSliverFixedExtentBoxAdaptor (flutter/flutter#192384)
2026-11-13 [email protected] Revert: [android]: prewarms shaders when the context is created (flutter/flutter#196468)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD team-ios Owned by iOS platform team team-macos Owned by the macOS 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.

[native assets] macOS flutter test fails when a bundled prebuilt dylib has no room for its absolute install name

3 participants