Repository navigation
[native_assets] Keep a dylib's install name in flutter test when its path does not fit - #194802
Conversation
…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
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.
There was a problem hiding this comment.
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.
| final changeDependencies = <String>[ | ||
| for (final MapEntry<String, String> entry in oldToNewInstallNames.entries) ...<String>[ | ||
| '-change', | ||
| entry.key, | ||
| entry.value, | ||
| ], | ||
| ]; |
There was a problem hiding this comment.
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.
| 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
- Suggest simplification and refactoring to enhance readability and maintainability. (link)
There was a problem hiding this comment.
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.
| if (keepInstallNameIfItDoesNotFit && | ||
| setInstallNamesResult.stderr.contains(_loadCommandsDoNotFit)) { | ||
| final RunResult changeDependenciesResult = await globals.processUtils.run(<String>[ | ||
| 'xcrun', | ||
| 'install_name_tool', | ||
| ...changeDependencies, | ||
| dylibFile.path, | ||
| ]); |
There was a problem hiding this comment.
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.
| 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
- Suggest simplification and refactoring to enhance readability and maintainability. (link)
There was a problem hiding this comment.
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.
| const changeDependencies = <String>[ | ||
| '-change', | ||
| '@rpath/libfoo.dylib', | ||
| newInstallName, | ||
| '-change', | ||
| '@rpath/libbar.dylib', | ||
| '/project/build/native_assets/macos/libbar.dylib', | ||
| ]; |
There was a problem hiding this comment.
Update the test's expected changeDependencies to match the filtered list that excludes the self-reference mapping.
| 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', | |
| ]; |
There was a problem hiding this comment.
Follows the first suggestion, which I'm not taking (see the thread on native_assets_host.dart).
| 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, | ||
| ], | ||
| ), |
There was a problem hiding this comment.
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,
],
),
]);There was a problem hiding this comment.
Follows the first suggestion, which I'm not taking (see the thread on native_assets_host.dart).
| } | ||
| if (keepInstallNameIfItDoesNotFit && | ||
| setInstallNamesResult.stderr.contains(_loadCommandsDoNotFit)) { | ||
| final RunResult changeDependenciesResult = await globals.processUtils.run(<String>[ |
There was a problem hiding this comment.
maybe make this a private helper method with the newInstallName as optional param to avoid the command duplication.
There was a problem hiding this comment.
Done in 24a56cf: _runInstallNameTool takes newInstallName as an optional parameter and adds -id only when it is given.
| '${changeDependenciesResult.stderr}', | ||
| ); | ||
| } | ||
| throwToolExit( |
There was a problem hiding this comment.
can we share this with the code above and have an ${if (keepInstallNameIfItDoesNotFit) ... } to avoid duplicating the error message?
There was a problem hiding this comment.
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.
|
P.S. Feel free to ignore the code review bot comments when they are #$%. 🙃 Also, cc @bkonyi |
|
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.
|
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 Under |
|
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.
|
|
@vashworth @jmagman We need a second review. |
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
On macOS,
flutter testsets each code asset's install name to its absolute path underbuild/native_assets/macos/. A prebuilt dylib linked without-headerpad_max_install_namesoften has no room for that path. Theninstall_name_toolfails and the whole run exits.Assets built by the hook itself with
CBuilderdo not hit this: it links with-encryptable, which leaves room.With this change, the tester falls back only when
install_name_toolreports that the larger load commands do not fit, and only when the dylib's directory is a canonical path:flutter run -d flutter-testercopies 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_toolerror.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:
/./), 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:VerboseLoggerignoresfatal: falsefor every warning.Tests:
setInstallNamesDylib, with the exact error message whether or not the retry ran;clangand the install name@rpath/m.dylib, then runsflutter 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, withTMPDIR=/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-assistbot 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.