Skip to content

Commit 4be3ef3

Browse files
authored
feat: strip debug symbols from Node binaries before SEA injection (#16)
## Summary Strip debug symbols from Node binaries before postject SEA injection. Node.js ships with full symbol tables (~17 MiB on linux-x64) that aren't needed at runtime. ### Why before injection? `strip` must run BEFORE postject injection. Postject corrupts the ELF section-to-segment layout, causing `strip` to fail with: ``` strip: section .text can't be allocated in segment 2 ``` ### Pipeline ``` download → copy (+ unsign on macOS/Win) → strip → inject SEA blob → sign ``` ### Per-platform behavior | Platform | Strip command | Savings | Notes | |----------|-------------|---------|-------| | Linux | `strip --strip-unneeded` | **~17 MiB** | Removes symbols + debug sections | | macOS | `strip -x` | ~5-10 MiB | Local symbols; binary already unsigned by `macho-unsign` | | Windows | skipped | 0 | PE releases don't ship debug symbols | | Cross-compile | silently skipped | 0 | `strip` can't process foreign binary formats | ### Results (linux-x64, Sentry CLI) | Metric | Before | After | Change | |--------|--------|-------|--------| | Raw binary | 125 MiB | 108 MiB | **-14%** | | Compressed | 34 MiB | 30 MiB | **-12%** | | Startup | unchanged | unchanged | — |
1 parent af81980 commit 4be3ef3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/impl.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ export default async function (
234234
flags.noCache ? null : flags.cacheDir,
235235
path.join(flags.outDir, outputName)
236236
);
237+
// Strip debug symbols before SEA injection. Node.js ships with full
238+
// symbol tables (~17 MiB on linux-x64). Must strip BEFORE postject
239+
// injection — postject corrupts the ELF section-to-segment layout.
240+
// Windows PE binaries don't ship debug symbols in release builds.
241+
if (!platform.startsWith("win")) {
242+
try {
243+
const stripCmd = platform.startsWith("darwin")
244+
? ["strip", "-x", fossilizedBinary]
245+
: ["strip", "--strip-unneeded", fossilizedBinary];
246+
await run(stripCmd[0]!, ...stripCmd.slice(1));
247+
} catch {
248+
// Non-fatal: may fail when cross-stripping (e.g., macOS Mach-O on Linux)
249+
console.warn(` Warning: strip failed for ${platform} (non-fatal)`);
250+
}
251+
}
252+
237253
// Use the code-cache blob for the host platform, base blob for others
238254
const blobForPlatform = (hasCodeCacheBlob && platform === currentPlatform)
239255
? codeCacheBlobPath

0 commit comments

Comments
 (0)