Use codesign to sign patched binaries on Intel - #23429
Merged
Merged
Conversation
- Since the switch to `MachO.codesign!` in ruby-macho 6.0, Intel macOS rejects the ad-hoc signatures on larger relocated binaries (e.g. `libruby`, the Python framework) and kills hardened-runtime programs such as MacVim's `vim` at launch with `CODESIGNING, Invalid Page`: #23418 - The signatures have correct page hashes and pass `codesign --verify` on newer macOS, so this looks like an Intel macOS verifier quirk rather than simple corruption. - Restore the pre-6.0 behaviour on Intel: leave unsigned binaries unsigned and use `codesign` to re-sign only the binaries whose existing signature our modifications have just broken, e.g. MacVim's Xcode-ad-hoc-signed hardened-runtime `vim`. - Restore the fatal preinstall developer tools check, now skipped on Apple Silicon rather than gated to it, as `codesign` requires the Command Line Tools while ruby-macho does not. - Keep `MachO.codesign!` on Apple Silicon, where it is required, proven and avoids a `codesign` subprocess per relocated file.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts macOS bottle relocation code signing to avoid Intel macOS rejecting ruby-macho ad-hoc signatures on some larger binaries, while retaining ruby-macho signing on Apple Silicon where it鈥檚 required.
Changes:
- Update
Keg#codesign_patched_binaryon macOS to use/usr/bin/codesignto re-sign only binaries whose existing signature is detected as broken on Intel, while continuing to useMachO.codesign!on Apple Silicon. - Reinstate the fatal preinstall developer tools check on Intel macOS (needed for
codesign), while skipping it on Apple Silicon. - Add/update macOS-specific specs covering the new Intel vs Apple Silicon behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Library/Homebrew/extend/os/mac/keg.rb | Implements Intel-specific codesign verify/re-sign flow and keeps ruby-macho signing on Apple Silicon. |
| Library/Homebrew/extend/os/mac/diagnostic.rb | Makes developer tools a fatal preinstall requirement on Intel (for codesign). |
| Library/Homebrew/test/os/mac/keg_spec.rb | Updates/adds specs for Intel vs Apple Silicon signing behavior. |
| Library/Homebrew/test/os/mac/diagnostic_spec.rb | Adds spec coverage for Intel requiring developer tools in fatal preinstall checks. |
馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
p-linnane
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MachO.codesign!in ruby-macho 6.0, Intel macOS rejects the ad-hoc signatures on larger relocated binaries (e.g.libruby, the Python framework) and kills hardened-runtime programs such as MacVim'svimat launch withCODESIGNING, Invalid Page: ruby-macho 6.0 re-signs relocated x86_64 binaries with signatures macOS rejects (kills hardened-runtime apps)聽#23418codesign --verifyon newer macOS, so this looks like an Intel macOS verifier quirk rather than simple corruption.codesignto re-sign only the binaries whose existing signature our modifications have just broken, e.g. MacVim's Xcode-ad-hoc-signed hardened-runtimevim.codesignrequires the Command Line Tools while ruby-macho does not.MachO.codesign!on Apple Silicon, where it is required, proven and avoids acodesignsubprocess per relocated file.Fixes #23418
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Fable 5 max with local review and testing.