fix(sea): skip mach-O __LINKEDIT patch for SEA binaries#247
Open
robertsLando wants to merge 2 commits intomainfrom
Open
fix(sea): skip mach-O __LINKEDIT patch for SEA binaries#247robertsLando wants to merge 2 commits intomainfrom
robertsLando wants to merge 2 commits intomainfrom
Conversation
The classic pkg flow appends the VFS payload to the end of the binary and uses patchMachOExecutable to extend __LINKEDIT so codesign hashes cover the payload. For SEA, postject creates a dedicated NODE_SEA segment — patching __LINKEDIT on top of that corrupts the SEA blob on macOS arm64 once the payload is non-trivial (reported for NestJS apps in discussion #236, 9 MB enhanced-SEA blob → segfault at LoadSingleExecutableApplication). Split the ad-hoc-sign path used by SEA into signMacOSSeaIfNeeded, which matches the Node.js SEA docs: just codesign, no LINKEDIT patch. signMacOSIfNeeded still patches for the non-SEA producer path. Refs: #236
Per review on #247 — a dedicated second function was more code than the branch deserved. Replace it with a single isSea parameter that skips the __LINKEDIT patch when true. Call sites read clearer too.
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.
Summary
v8::ToLocalChecked Empty MaybeLocalinsidenode::sea::LoadSingleExecutableApplication) when the payload was non-trivial, e.g. a NestJS app bundled via enhanced SEA (~9 MB blob). Reported in discussion Did anyone successfully package a NestJS app with pkg and SEA? #236.signMacOSIfNeededinlib/sea.tscallspatchMachOExecutablebeforecodesign. That helper exists for the classic pkg flow (VFS payload appended to the end of the binary,__LINKEDITextended socodesignhashes cover it). For SEA, postject already insertsNODE_SEAas a properLC_SEGMENT_64— patching__LINKEDITon top of that corrupts the SEA blob on macOS arm64.signMacOSSeaIfNeeded, which matches the Node.js SEA docs —codesign --sign -, no__LINKEDITpatching. The non-SEA producer path keepssignMacOSIfNeededunchanged.Test plan
test-00-sea,test-85-sea-enhanced,test-86-sea-assets,test-87-sea-esm,test-89-sea-fs-ops,test-90-sea-worker-threads,test-91-sea-esm-entry,test-92-sea-tla).julianpoemp/yao-pkg-nestjs-sea-example) on Linux x64 — enhanced-SEA NestJS binary boots and servesGET /api→{"message":"Hello API"}.yarn lintclean.Notes
Vanilla
--sea(no bootstrap) remains incompatible with NestJS regardless of this fix: Node's built-in SEArequire()only resolves builtin modules, sorequire("@nestjs/common")inside a webpack bundle throwsERR_UNKNOWN_BUILTIN_MODULE. Enhanced SEA (pkg --sea .) is the right path for framework apps like NestJS.Refs: discussion #236