Skip to content
This repository was archived by the owner on Oct 30, 2026. It is now read-only.

Fix signing issue with xtool - #2

Closed
TheEdgeOfRage wants to merge 1 commit into
xtool-org:masterfrom
TheEdgeOfRage:master
Closed

TheEdgeOfRage wants to merge 1 commit into
xtool-org:masterfrom
TheEdgeOfRage:master

Conversation

@TheEdgeOfRage

Copy link
Copy Markdown

When signing an app with xtool I often get this error:

[Signing]
>>> Can't find free space of LoadCommands for CodeSignature!
>>> Failed!

Error: signer(Optional("Signing failed"))

Now, I'm gonna be honest, I just pointed an agent at it and asked to fix it and this is what it came up with, along with the following explanation:

zsign needs unused space in the executable header to add a code-signature command. It used to check only the __text section, so it could miss available space elsewhere. The change checks all sections and uses the smallest available gap, fixing that false “no free space” error.

Given this is a 100% vibe coded fix, I fully understand if you don't want to merge this and I can just continue using my fork. It was just a small enough fix that I thought I might as well offer it 🤷

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 940016b5-eb2d-41bb-bf92-4420938d9f2e

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@TartanLeGrand

Copy link
Copy Markdown

Hi @TheEdgeOfRage, I ran into the same error from xtool and dug into it while signing app extensions on Linux. Two notes in case they help, and to avoid duplicate work:

  1. In my case the binary that failed was an app extension with no __text section at all (the linker had dead-stripped the extension's code, which is an xtool bug of its own). zsign then measured zero free space, even with about 15 KB actually free after the load commands. Taking the smallest gap over all sections, as this PR does, fixes that. Zerofill sections (offset 0) and sections in other segments are worth handling too.
  2. ReallocCodeSignSpace resizes __LINKEDIT before checking whether LC_CODE_SIGNATURE fits. The header is a shared mapping of the file, so when the check fails the binary is left with a half-applied header. Checking first avoids that.

I have a branch that does both, with xtool tests built on hand-made Mach-O fixtures (a cramped binary fails and its bytes are unchanged; a binary whose first section is not __text signs). I'll open it as a separate PR that references this one, so the maintainers can pick whichever shape they prefer, or I can fold my changes into this PR if you'd rather. Happy either way.

@TheEdgeOfRage

Copy link
Copy Markdown
Author

@TartanLeGrand if yours handles my issue as well then let's just keep that one :) Closing this for now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants