Skip to content

Signing fails on app extension targets: appex stub has no __text section, zsign aborts on free-space check #379

In progress

Description

@duketopceo

Bug

xtool dev build --sign fails on an app whose package declares an extension when zsign processes the appex trampoline stub:

>>> Can't find free space of LoadCommands for CodeSignature!
Error: Signing failed

Root cause

The -Extension-product link step emits a stub Mach-O whose __TEXT segment contains only __stubs and __got — there is no __text section. The bundled zsign fork computes load-command free space as

m_uLoadCommandsFreeSpace = __text.offset - sizeofcmds - headerSize

(ZArchO::Init, archo.cpp). With no __text section the value is 0, so ReallocCodeSignSpace refuses to append LC_CODE_SIGNATURE and aborts. A __text-less stub is legal Mach-O — codesign signs these fine; the abort is specific to zsign's free-space shortcut.

Repro

xtool 1.21.0, aarch64 Linux (Arch/Asahi), Darwin SDK artifactbundle. Any SwiftPM app package with an extensions: entry in xtool.yml — in my case a WidgetKit ControlWidget extension. The stub binary at .build/out/Products/Debug-iphoneos/<Name>-Extension has ncmds=24, __TEXT with __stubs at fileoff 16384 and no __text section.

Workaround that unblocked me

Post-link hook in the artifactbundle's toolset/bin/ld64.lld wrapper: after orig/ld64.lld succeeds, inject an empty LC_CODE_SIGNATURE { dataoff: filesize, datasize: 0 } into the stub's load-command padding (it has ~15 KB free). zsign then takes its existing-pcslc path, skips the free-space check, and writes the real signature at dataoff — both app and appex sign and the bundle deploys.

Possible fixes

  • Emit a __text section in the extension stub link (e.g. a real entry-point object), or
  • Patch zsign's ZArchO::Init to fall back to the __TEXT segment's fileoff/filesize when no __text section exists.

Happy to send a PR against whichever side you prefer.

Activity

  1. kabiroberai commented on Nov 16, 2026

    @kabiroberai
    Member

    This should be resolved by v2.0.0-beta.1. Please check and let me know!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions