<!-- A maintainer will only start reviewing once CodeRabbit has approved and CI is green. Please wait for those to pass before expecting human review. --> ## Summary Release binaries have shipped with their symbol table since pnpm 12.23.0 and pnpr 0.1.0-alpha.22. This restores `strip = "symbols"` for them and adds a release gate that rejects an unstripped binary. ### Cause pnpm/pnpm#16589 added `[profile.release.package.<root crate>]` overrides so that fat LTO keeps optimizing at level 3. A package override that does not set `strip` resets it to Cargo's default. With `debug = false` that default is `debuginfo`, which keeps the symbol table. The root crate's value is the one the linker gets. A two-line Cargo project reproduces it: `strip = "symbols"` in `[profile.release]` plus a `[profile.release.package.<name>]` section with only `opt-level` gives an unstripped binary, and adding `strip` to the override strips it again. ### Effect on the published artifacts Stripping each published ELF and Mach-O binary with `llvm-strip` removes: | Artifact | Binaries | Smallest reduction | Largest reduction | |---|---|---|---| | `pnpm` 12.23.0 | 14 | 10.5 MB (Linux s390x) | 13.4 MB (Linux arm64) | | `@pnpm/napi` 12.23.0 | 12 | 9.2 MB (macOS x64) | 11.7 MB (Linux arm64) | | `pnpr` 0.1.0-alpha.22 | 6 | 11.5 MB (macOS) | 14.4 MB (Linux arm64) | On Linux x64, `pnpm` goes from 70.4 MB to 59.3 MB. Windows is not affected, because its symbols are in a separate PDB. ### Changes - `Cargo.toml`: each root-crate override repeats `strip = "symbols"`. `release-debug` inherits those overrides, so it sets `strip = false` for the same crates to keep its symbols. - `.github/scripts/assert-stripped.mjs`: rejects an ELF binary with a `SHT_SYMTAB` section and a Mach-O binary whose `LC_DYSYMTAB` counts local symbols. It fails on any other format. - `release.yml`: the gate runs on the pnpm and NAPI artifacts in `verify-rust-artifacts` and on the pnpr artifacts in `verify-pnpr-artifacts`, next to the existing Windows runtime check. - `pacquet-integrated-benchmark.yml`: the gate also runs on the HEAD `pnpm` and `pnpr` binaries of the build job. That job is the only one on a pull request that builds with the release profile, so a profile change that keeps the symbol table fails there. A `head_ref` dispatch builds another revision, so the step skips it. The NAPI addon has no release-profile build on a pull request and is covered at release time only. ### Verification - Cargo's unit graph resolves `strip` to `symbols` for `pnpm`, `pnpr`, `pnpm_napi` and `micro-benchmark` under `release` and `napi-release`, and to none under `release-debug`. Before the change it resolved to `debuginfo`. - A Linux x64 release build of `pnpm` is 59.1 MB and passes the gate. The same build on `main` is 70.3 MB and fails it. - On the binaries the benchmark build job produced for the first commit of this PR, the gate passes HEAD's `pnpm` and `pnpr` and rejects both of `main`'s. The step itself has since run and passed in that job. - The gate passes the published 12.21.0, 12.22.0 and 0.1.0-alpha.21 binaries and rejects the 12.23.0 and 0.1.0-alpha.22 ones, across Linux x64 and s390x, macOS, FreeBSD, NetBSD and Android. - Both release workflow steps were run locally in a directory laid out like the verify jobs, including the `pnpm-lock.yaml`, archive, checksum and Windows files they have to skip. Not verified: the release workflow steps themselves only run on a release tag, and I built only the Linux x64 `pnpm` binary locally. The other targets and the NAPI addon rest on the unit graph. ## Checklist - [x] Added a changeset (`pnpm changeset`) if this PR changes any published package. Keep it short and written for pnpm users — it becomes a release note. - [x] Added or updated tests. --- Written by an agent (Claude Code, claude-fable-5-2). 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Improvements** * Release binaries are smaller on Linux and macOS: `pnpm` is 10–13 MB smaller, the NAPI addon is 9–12 MB smaller, and `pnpr` is 11–14 MB smaller. * These binaries no longer include symbol names used only by debuggers. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
110 lines
4 KiB
JavaScript
110 lines
4 KiB
JavaScript
// Release gate for the ELF and Mach-O binaries: a shipped binary carries no
|
|
// symbol table beyond the symbols the dynamic loader needs.
|
|
import { readFileSync } from 'node:fs'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
const ELF_MAGIC = Buffer.from([0x7f, 0x45, 0x4c, 0x46])
|
|
const ELF_CLASS_64 = 2
|
|
const ELF_DATA_LITTLE_ENDIAN = 1
|
|
const ELF_DATA_BIG_ENDIAN = 2
|
|
const SHT_SYMTAB = 2
|
|
const MACH_O_MAGIC_64 = 0xfeedfacf
|
|
const LC_DYSYMTAB = 0xb
|
|
|
|
/**
|
|
* Describes the symbol table a strip would have removed, or returns
|
|
* `undefined` when the binary has none. Throws on a file that is not a 64-bit
|
|
* ELF or a thin 64-bit little-endian Mach-O.
|
|
*/
|
|
export function describeSymbolTable (bytes) {
|
|
const view = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes)
|
|
if (view.length >= 4 && view.subarray(0, 4).equals(ELF_MAGIC)) return describeElfSymbolTable(view)
|
|
if (view.length >= 4 && view.readUInt32LE(0) === MACH_O_MAGIC_64) return describeMachOSymbolTable(view)
|
|
throw new Error('not a 64-bit ELF or Mach-O file')
|
|
}
|
|
|
|
function describeElfSymbolTable (view) {
|
|
if (view.length < 0x40) throw new Error('truncated ELF header')
|
|
if (view[4] !== ELF_CLASS_64) throw new Error(`unsupported ELF class ${view[4]}`)
|
|
const read = elfReader(view)
|
|
const tableOffset = Number(read.uint64(0x28))
|
|
const entrySize = read.uint16(0x3a)
|
|
const entryCount = read.uint16(0x3c)
|
|
if (tableOffset === 0) return undefined
|
|
// A table of 0xff00 sections or more keeps its count in the first entry.
|
|
if (entryCount === 0) throw new Error('unsupported ELF section count')
|
|
if (entrySize < 0x40 || tableOffset + entrySize * entryCount > view.length) {
|
|
throw new Error('truncated ELF section header table')
|
|
}
|
|
for (let index = 0; index < entryCount; index++) {
|
|
if (read.uint32(tableOffset + index * entrySize + 4) === SHT_SYMTAB) return 'a SHT_SYMTAB section'
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
function elfReader (view) {
|
|
switch (view[5]) {
|
|
case ELF_DATA_LITTLE_ENDIAN:
|
|
return {
|
|
uint16: offset => view.readUInt16LE(offset),
|
|
uint32: offset => view.readUInt32LE(offset),
|
|
uint64: offset => view.readBigUInt64LE(offset),
|
|
}
|
|
case ELF_DATA_BIG_ENDIAN:
|
|
return {
|
|
uint16: offset => view.readUInt16BE(offset),
|
|
uint32: offset => view.readUInt32BE(offset),
|
|
uint64: offset => view.readBigUInt64BE(offset),
|
|
}
|
|
default:
|
|
throw new Error(`unsupported ELF data encoding ${view[5]}`)
|
|
}
|
|
}
|
|
|
|
// A stripped Mach-O keeps LC_SYMTAB for its undefined and exported symbols, so
|
|
// the local symbol count in LC_DYSYMTAB is what tells the two apart.
|
|
function describeMachOSymbolTable (view) {
|
|
if (view.length < 32) throw new Error('truncated Mach-O header')
|
|
const commandCount = view.readUInt32LE(16)
|
|
let command = 32
|
|
for (let index = 0; index < commandCount; index++) {
|
|
if (command + 8 > view.length) throw new Error('truncated Mach-O load command')
|
|
const commandSize = view.readUInt32LE(command + 4)
|
|
if (commandSize < 8 || command + commandSize > view.length) throw new Error('truncated Mach-O load command')
|
|
if (view.readUInt32LE(command) === LC_DYSYMTAB) {
|
|
if (commandSize < 16) throw new Error('truncated LC_DYSYMTAB')
|
|
const localSymbolCount = view.readUInt32LE(command + 12)
|
|
return localSymbolCount === 0 ? undefined : `${localSymbolCount} local symbols`
|
|
}
|
|
command += commandSize
|
|
}
|
|
throw new Error('Mach-O file has no LC_DYSYMTAB')
|
|
}
|
|
|
|
function main () {
|
|
const files = process.argv.slice(2)
|
|
if (files.length === 0) {
|
|
console.error('usage: node assert-stripped.mjs <elf-or-mach-o-file>...')
|
|
process.exit(2)
|
|
}
|
|
let failed = false
|
|
for (const file of files) {
|
|
let symbolTable
|
|
try {
|
|
symbolTable = describeSymbolTable(readFileSync(file))
|
|
} catch (error) {
|
|
console.error(`${file}: ${error.message}`)
|
|
failed = true
|
|
continue
|
|
}
|
|
if (symbolTable != null) {
|
|
console.error(`${file} is not stripped: it has ${symbolTable}`)
|
|
failed = true
|
|
}
|
|
}
|
|
if (failed) process.exit(1)
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
main()
|
|
}
|