feat(relinker): write an ad-hoc code signature into macOS output #18450
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18450"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by SHOnnay on 2026-11-11T14:50:40Z.
What
macOS output, both executables and guest-module dylibs, now carries a built-in ad-hoc code signature. Users no longer need
codesign -s -before running it, andcodesign --verify --strictaccepts the output as written.Implementation. New
core/relinker/elfpatcher/src/macos/MacOsCodeSignature.cpp/.hpp, with SHA-256 implemented in-repo, since the relinker had none. It writes whatcodesign -s -writes on macOS 27.0.1, confirmed against a codesign-signed dump.Signature layout.
LC_CODE_SIGNATUREis the last load command. It points at a 16-byte-aligned SuperBlob (0xfade0cc0) at the end of__LINKEDIT, which grows to cover it. The SuperBlob holds:0x20400,CS_ADHOC, SHA-256, 4096-byte pagesexecSegBase/execSegLimit=__TEXTfileoff/filesize, andCS_EXECSEG_MAIN_BINARYfor executables0xfade0b01wrapper, slot 0x10000Identifier and ordering.
codesign -s - -fstill works and keeps the entry stub.Sources:
osfmk/kern/cs_blobs.hlld/MachO/SyntheticSections.cppCodeSignatureSectionsrc/ld/LinkEdit.hppCodeSignatureAtomDocs.
docs/user/USAGE.mdnotes that output is signed, that re-signing replaces the signature, and that output edited withinstall_name_toolorstripmust be signed again.Debt. One entry: verified only on M1 with macOS 27.0.1, and not marked
CS_LINKER_SIGNED. ld64 and lld set that flag, which lets editing tools re-sign automatically. Switching is a one-flag change plus dropping two blobs; reviewers can say if they prefer it.Tested
macOS 27 on Apple M1, relinker-only Release build.
ctest --test-dir build-relinker -j 4: 780 of 780 on this branch, 779 of 779 onmain.macos_code_signature(TIMEOUT 60, RUN_SERIAL on Apple):hashlibcodesign --verify --strictand-dvvv(Signature=adhoc,CodeDirectory v=20400,Hash type=sha256)dlopens the signed guest modulecodesign -s - -fand checks the entry stub survivesmain:AssertionError: executable: 0 LC_CODE_SIGNATURE commandsmacOS code signature tests passed__LINKEDITnot grown, a byte changed after signing.ctest -j 8 -R ^macos_×3 passed 11 of 11 on bothmainand this branch with similar times, so this PR does not claim to fix #13208.Overlap. No open PR emits a code signature; I searched for "code signature", "codesign" and "ad-hoc signature macOS".
pr_overlap.pycould only report "cannot confirm" PRs. None of their diffs contains signature terms (LC_CODE_SIGNATURE,0xfade0c,CodeDirectory,codesign). TheMacOsImage.cppchange is about 19 lines, so conflicts with #18373 and #10861 should be small.Not verified: Intel Macs, macOS before 27, real titles, and the web converter path, which shares this code.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:26:17Z.
Review: COMMENTED
Reviewed the macOS ad-hoc code signature — no blocking findings
The diff at head
7cb53a29af0af180868561aec7c0ba87eaa934b4writes a valid-looking ad-hoc signature for macOS output; I found no concrete defect, but I ran no build or test, so the layout is checked by reading only.What I ran
7cb53a29af0af180868561aec7c0ba87eaa934b4, basemain.ctest, nocodesignrun here (no macOS host).files.jsonunderreviewed.MacOsMachOPatcher,MacOsImageInput,PadToandLoadRva, and for the test helpers the new test imports.Reader calls
Results
ctestmacos_code_signaturetestConversion.cppand the guest writer__TEXTrange used for the exec segmentLoadRvaFindings
Blocking
None.
Non-blocking
core/relinker/relinker/tests/test_macos_code_signature.py:134: when the executable reportsBad CPU typeand the host is not CI,run_nativereturns before thedlopencheck. A non-CI run then passes without launching the signed executable or loading the module. Make that branch print a skip notice, or fail it.core/relinker/relinker/src/pipeline/Conversion.cpp:162: the identifier isOutputPath.filename(). If that is empty (a path ending in a separator, understd::filesystemrules; not run), the conversion finishes and only thenAppendCodeSignaturerefuses it. Checking it before the conversion starts would fail sooner.Sources
I linked no behaviour claims. The external references in the description (xnu-11215.1.10, lld llvmorg-19.1.0, ld64-957.1) were not checked.
Not verified
codesignand Rosetta launch: only the author's M1 run is reported.0x400load-command reserve: I did not find the check that keeps the newLC_CODE_SIGNATUREinside it.hashliborcodesign.To get this to a good state
test_macos_code_signature.pyfail or print a clear skip (line 134).Conversion.cpp:162).ctest --test-dir build-relinker -R ^macos_code_signature$, then the full suite.