Predicting the Go Linker
Edit one line of a Go program and the linker regenerates half the binary, because most of a Go executable is metadata tables derived from the function list. Presage predicts nearly all of those changes from the old binary. For a one-line edit in a 30 MB program, its patch is 1.1 KB versus 150 KB for bsdiff.
| Method | Bytes | |
|---|---|---|
| Full download (xz -9) | 7,917,688 | |
| xdelta3 | 1,390,889 | |
| Zucchini | 173,060 | |
| bsdiff | 150,475 | |
| presage | 1,100 |
A Presage patch tells the decoder how to predict the new binary from the old one, then supplies a correction for the bytes the prediction misses. Applied to Chrome, it halved the patch shipped by Zucchini, Chrome's own updater. Go suits the approach even better, because the Go linker derives more of the file using rules simple enough to follow exactly.
What the Linker Derives
In a stripped Prometheus 3.13.2 binary, machine code is less than half of the 97.6 MB file. The rest is metadata tables.
The runtime's symbol table, .gopclntab, holds each function's name and address and maps machine instructions to source lines, stack depths, and which stack slots hold pointers. Because Go's runtime needs that table for stack traces and garbage collection, stripping debug symbols leaves it intact. The .rodata section holds Go's type descriptors for reflection and interfaces, and each descriptor references its methods and element types by offset.
Every build regenerates those tables from scratch. The linker lays out the code package by package, then rebuilds each table from the resulting layout. When a single function grows, every function after it shifts, along with every table entry that names an address. A byte-level differ finds the moved code, but it can't know that a 35 MB table is derived from the function list, so it ships the differences.
What One Line Does
Adding w.Header().Set("X-Foo", "bar") to one handler in the 30 MB Go HTTP service above makes that handler grow by 192 bytes. It lives in main, the last package in the layout, so only the remaining functions after it shift. Still, 14% of the file's bytes change, and fewer than 200 of them are the compiled edit.
Nearly all of the rest is offsets shifted by fixed constants. Each function's metadata tables sit back to back in one shared blob inside .gopclntab, and each function record stores offsets pointing into that blob. The edited function's tables grew by 34 bytes in total.
In every function record after the edited handler, the entry address offset increases by 192 and the three table offsets stored in the record (pcsp, pcfile, and pcln) increase by 34. Those same two numbers account for every shift across the function index, the stack maps, and the type descriptors. A decoder holding the old binary and those two numbers can predict all of it.
Predicting It
Presage's Go module builds a plan from the old function list with any additions, removals, size changes, and data-section shifts. For the one-line edit, that is a single resized function.
From the plan and the old binary, the decoder predicts the whole new file. It copies each function to its new address and updates the relative calls, jumps, and data loads inside it. Next it regenerates .gopclntab, rewrites the offsets in the type descriptors, and recomputes both the ELF headers and the FIPS integrity checksum over the crypto module that Go's runtime checks at startup. For functions whose bodies actually changed, Presage predicts them in pieces from matching instruction sequences elsewhere in the old code, since the compiler emits the same instruction sequences for common patterns.
The encoder runs the same prediction and ships a correction for the bytes that differ from the real binary. Here the correction is 330 bytes, mostly the compiled edit and two build-ID hashes that depend on the build inputs. With the plan and integrity hashes, the patch is 1,100 bytes. A wrong prediction only costs bytes, because the decoder verifies the reconstructed file's hash before anything uses it.
A Release
Prometheus 3.13.1 to 3.13.2 edits 2 source files and bumps a few dependencies. Fewer than 100 of its 114k functions are added or resized, yet 84% of the file's bytes change.
| Method | Bytes | |
|---|---|---|
| Full download (xz -9) | 21,671,396 | |
| xdelta3 | 11,238,692 | |
| Zucchini | 3,012,208 | |
| bsdiff | 2,714,204 | |
| presage | 80,425 |
rsync requires byte-for-byte block matches, so a shifted relative address every few dozen bytes forces it to send most of the file. xdelta3 and bsdiff find the moved code, then still pay to encode those changed addresses. Zucchini would translate them, but it doesn't recognize a Go binary and patches it raw. Presage misses only 0.16% of the file, mostly new functions, their table entries, and resized function bodies. Encoding takes 4s, applying takes 1s.
On bigger releases, that gap narrows. The next minor release, 3.14.0, adds ~6k functions and resizes hundreds more; its patch is 4.8 MB vs. bsdiff's 9.8 MB (~2x smaller instead of ~34x).
Debug Information
Upstream ships Prometheus unstripped with 38 MB of symbol tables and compressed DWARF debug data on top. On that binary, the same patch release costs bsdiff 28 MB. Debug information is full of code addresses, and a compressed stream whose input changes near its start differs all the way to its end. Because DWARF is derived from the function list too, Presage unwraps the compression, predicts the DWARF from the function map it already built, and recompresses it with the same compressor the Go linker uses. For the unstripped Prometheus release, the patch drops to 468 KB; for the one-line edit with debug information, it is 1.9 KB.
Which Linker
The prediction is exact because it models a specific version of the Go linker, so it has to keep up when the linker changes. Go 1.27 moved the type descriptors into their own section and replaced the debug compressor, so a Go 1.26 model predicts a 1.27 binary wrong from the first descriptor. The Go module reads the Go version embedded in the binary, models Go 1.26 or 1.27 today, and falls back to the generic ELF module that patched Chrome for any other version.
Presage is on GitHub at wjordan/presage.