Skip to content

Use codesign to sign patched binaries on Intel - #23429

Merged
MikeMcQuaid merged 1 commit into
mainfrom
ruby-macho-x86-signing
Aug 4, 2026
Merged

Use codesign to sign patched binaries on Intel#23429
MikeMcQuaid merged 1 commit into
mainfrom
ruby-macho-x86-signing

Conversation

@MikeMcQuaid

Copy link
Copy Markdown
Member
  • 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: ruby-macho 6.0 re-signs relocated x86_64 binaries with signatures macOS rejects (kills hardened-runtime apps)聽#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.

Fixes #23418


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Claude Fable 5 max with local review and testing.


- 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.
Copilot AI lite review requested due to automatic review settings August 4, 2026 12:13

Copilot AI 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.

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_binary on macOS to use /usr/bin/codesign to re-sign only binaries whose existing signature is detected as broken on Intel, while continuing to use MachO.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.

Comment thread Library/Homebrew/test/os/mac/keg_spec.rb
Comment thread Library/Homebrew/extend/os/mac/keg.rb
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Aug 4, 2026
Merged via the queue into main with commit d6de855 Aug 4, 2026
51 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the ruby-macho-x86-signing branch August 4, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruby-macho 6.0 re-signs relocated x86_64 binaries with signatures macOS rejects (kills hardened-runtime apps)

3 participants