From bee060c5edb90a0f7c877b1342a720f7045ecf69 Mon Sep 17 00:00:00 2001 From: Theo Browne <6751787+t3dotgg@users.noreply.github.com> Date: Sat, 24 Oct 2026 22:53:57 -0700 Subject: [PATCH 1/3] ci(release): strip the shipped tsc and fold identical code on Linux The linux-x64 tsc is 48.0 MB, about twice Go's 24.5 MB. 5.0 MB of it is the symbol table, and about 0.27 MB is identical functions that GNU ld cannot fold. - Strip the Linux tsc (strip --strip-all) and the macOS tsc (strip -x) after all checks. The Linux step fails if the program headers change. The unstripped tsc is the artifact unstripped-tsc-, for perf work. The strip is not a cargo profile setting: a profile change changes -C metadata, and the use build would then match no function of the profile. - Both Linux PGO builds link with rustup's rust-lld and --icf=all, through a new PGO_RUSTFLAGS in build-pgo.sh (it sets RUSTFLAGS itself). The plain tsc keeps GNU ld, so the PGO check compares a folded tsc with an unfolded one. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 38 +++++++++++++++++++++++++++ crates/ts_goport/scripts/build-pgo.sh | 12 ++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d64c698bb..83dda78d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,9 @@ # is experimental, macOS has no perf branch sampling for its profile, and BOLT has no PE support. # Linux is static musl and non-PIE, so it starts on any x86-64 or arm64 Linux, Alpine too # (npm/README.md, "Linux libc"). Each Linux tsc builds natively on a Blacksmith runner of its arch. +# Linux PGO builds link with rustup's rust-lld and fold identical functions (--icf=all). The Linux +# and macOS tsc ship without their symbol tables (stripped after the checks); the artifact +# unstripped-tsc- keeps the unstripped tsc for perf and profiles. # Windows (x86_64-pc-windows-msvc, aarch64-pc-windows-msvc) builds in Git Bash, with the C runtime # linked in (+crt-static), so tsc.exe needs no Visual C++ redistributable. jemalloc does not build # there: it uses the system allocator. Each PGO tsc builds natively, so its training runs on its @@ -194,6 +197,9 @@ jobs: run: scripts/goport/pgo-train.sh setup "$RUNNER_TEMP/train" # The same build with -Cprofile-generate, the training set, then -Cprofile-use. PGO_LINK (from # the Build step) gives the RUSTFLAGS of the plain build. Separate target dirs (not cached). + # Linux: both builds link with rustup's rust-lld (gcc-ld/ld.lld; GNU ld has no --icf) and fold + # identical functions: about 0.27 MB less, the same instructions run. The plain tsc keeps GNU + # ld, so the check below compares the folded tsc with an unfolded one. - name: PGO build if: ${{ !matrix.no-pgo }} env: @@ -202,6 +208,11 @@ jobs: PGO_CARGO: cargo CARGO_FEATURES: --features noembed run: | + if [[ $RUNNER_OS == Linux ]]; then + gccld="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin/gcc-ld" + [[ -x $gccld/ld.lld ]] || { echo "::error::no $gccld/ld.lld"; exit 1; } + export PGO_RUSTFLAGS="-Clink-arg=-fuse-ld=lld -Clink-arg=-B$gccld -Clink-arg=-Wl,--icf=all" + fi PGO_TRAIN="scripts/goport/pgo-train.sh run $RUNNER_TEMP/train" crates/ts_goport/scripts/build-pgo.sh "$RUNNER_TEMP/pgo" mkdir -p "$RUNNER_TEMP/out" cp "$RUNNER_TEMP/pgo/target-use/goport/tsgo${{ matrix.exe }}" "$RUNNER_TEMP/out/tsc${{ matrix.exe }}" @@ -241,6 +252,33 @@ jobs: echo "::error::tsc.exe imports the Visual C++ runtime (vcruntime140.dll)" exit 1 fi + # Strip the symbol tables after the checks (about 5 MB on Linux). The code does not change. Not + # a cargo profile strip: a profile change changes -C metadata, and a use build then matches no + # function of the profile (a no-PGO tsc, with no warning). The program headers must not move: + # Linux before 5.18 finds them from the first segment, and musl's static start reads PT_TLS + # there. macOS: strip -x (local symbols) with Apple's strip, which signs a linker-signed arm64 + # tsc again. macOS stops an arm64 tsc with a bad signature, so the --version run catches it. + - name: Strip the tsc + if: runner.os != 'Windows' + run: | + out="$RUNNER_TEMP/out" dir="$RUNNER_TEMP/check" + mkdir -p "$RUNNER_TEMP/unstripped" + cp "$out/tsc" "$RUNNER_TEMP/unstripped/tsc" + if [[ $RUNNER_OS == Linux ]]; then + strip --strip-all "$out/tsc" + cmp <(readelf -lW "$RUNNER_TEMP/unstripped/tsc") <(readelf -lW "$out/tsc") + else + /usr/bin/strip -x "$out/tsc" + fi + cp "$out/tsc" "$dir/tsc" + [[ $("$dir/tsc" --version) == "Version 7."* ]] + wc -c "$RUNNER_TEMP/unstripped/tsc" "$out/tsc" + - if: runner.os != 'Windows' + uses: actions/upload-artifact@v4 + with: + name: unstripped-tsc-${{ matrix.platform }} + path: ${{ runner.temp }}/unstripped/tsc + if-no-files-found: error - uses: actions/upload-artifact@v4 with: name: tsc-${{ matrix.platform }} diff --git a/crates/ts_goport/scripts/build-pgo.sh b/crates/ts_goport/scripts/build-pgo.sh index 7e83314a3..a2b7c72cc 100755 --- a/crates/ts_goport/scripts/build-pgo.sh +++ b/crates/ts_goport/scripts/build-pgo.sh @@ -31,8 +31,10 @@ # build-bolt.sh refuses static bins, so they only make the file bigger. # The build prints the .text and .rela.text sections of tsgo # (readelf -S). Expect .text.hot, .text.unlikely and .rela.text. GNU ld (the -# linker of the musl target) ignores keep-text-section-prefix, but its default -# script already puts the hot and the unlikely code together inside .text. +# default linker of the musl target) ignores keep-text-section-prefix, but its +# default script already puts the hot and the unlikely code together inside +# .text. release.yml links the musl tsc with lld (PGO_RUSTFLAGS), which keeps +# the sections. # Other platforms (macOS) get neither flag. # # Environment: @@ -80,6 +82,10 @@ # and proc macros do not get the flags. The bins are # copied to the usual /goport path. The build # checks the ELF type and INTERP of tsgo. +# PGO_RUSTFLAGS more RUSTFLAGS for both builds. The script sets +# RUSTFLAGS itself, so the caller's RUSTFLAGS do not +# reach cargo. release.yml passes the lld link args +# here (identical code folding on Linux). # # Choosing PGO_LINK (integrator, once a round): build the default and # PGO_LINK=static. On cup2 (under its lock) time 'tsgo --version' and query @@ -189,7 +195,7 @@ triple="${PGO_TARGET:-}" # Each step needs its own target (other RUSTFLAGS). sccache is off: it could # reuse an object built with an older profile at the same path. build() { # build - local target="$out/$1" flags="$2 $link_flags" target_args="" + local target="$out/$1" flags="$2 $link_flags ${PGO_RUSTFLAGS:-}" target_args="" # Both builds get the same link mode, so the profile of the generate build # matches the code of the use build. [[ -n $triple ]] && target_args="--target $triple" From fc92793b726302a8dacaf945fbe5dcd6451035c3 Mon Sep 17 00:00:00 2001 From: Theo Browne <6751787+t3dotgg@users.noreply.github.com> Date: Sun, 25 Oct 2026 00:26:44 -0700 Subject: [PATCH 2/3] ci(release): say what icf folds Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 83dda78d2..083517059 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -198,8 +198,8 @@ jobs: # The same build with -Cprofile-generate, the training set, then -Cprofile-use. PGO_LINK (from # the Build step) gives the RUSTFLAGS of the plain build. Separate target dirs (not cached). # Linux: both builds link with rustup's rust-lld (gcc-ld/ld.lld; GNU ld has no --icf) and fold - # identical functions: about 0.27 MB less, the same instructions run. The plain tsc keeps GNU - # ld, so the check below compares the folded tsc with an unfolded one. + # identical functions: about 0.27 MB less, almost all of it cold code, and the same code runs. + # The plain tsc keeps GNU ld, so the check below compares the folded tsc with an unfolded one. - name: PGO build if: ${{ !matrix.no-pgo }} env: From 18308c5e980c511156e15af3085ae2f65cdda077 Mon Sep 17 00:00:00 2001 From: Theo Browne <6751787+t3dotgg@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:06:24 -0700 Subject: [PATCH 3/3] ci(release): keep the unstripped tsc artifacts for 90 days Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 083517059..cf22fa411 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -279,6 +279,7 @@ jobs: name: unstripped-tsc-${{ matrix.platform }} path: ${{ runner.temp }}/unstripped/tsc if-no-files-found: error + retention-days: 90 - uses: actions/upload-artifact@v4 with: name: tsc-${{ matrix.platform }}