BUILD/MINOR: strip the symbol table and trim the build path from the binary - #845
BUILD/MINOR: strip the symbol table and trim the build path from the binary#845PixiBixi wants to merge 1 commit into
Conversation
0910439 to
d2bdbd4
Compare
|
@PixiBixi this seems like a good change, but |
…binary Neither the goreleaser build nor the one in build/Dockerfile passes -s, so both ship the symbol table and the DWARF data. On linux/amd64 that is 98.7 MB where 69.5 MB is enough, close to 30 MB carried by every image on every node. -w is not passed with it. The linker derives it from -s unless it is given explicitly, so the two produce the same binary, and naming only -s says what is being asked for. The symbol table is not what a stack trace is read from. Go keeps the pclntab whatever the linker flags are, and -s does not touch it, so a panic still prints the function names and the line numbers, and pprof still symbolises. Measured on the same panic with and without the flag, the two traces are identical. What is lost is source level debugging with delve, go tool nm, and core dump analysis under gdb, none of which is a way anyone works on a running ingress controller. -trimpath goes with it. It keeps the path of the machine that built the binary out of the result, which is 4470 occurrences of a build directory in the current linux/amd64 build, and it is one of the conditions for two builds of the same commit to produce the same bytes. The -X stamping of the version is not affected. It is verified in the same build as these flags.
d2bdbd4 to
5a2facf
Compare
|
You are right on both counts, thanks.
*FlagW = *FlagS // -s implies -w if not explicitly setMeasured on this tree,
The linked issues: fair, they do not belong. They came from the same pass over the The commit message is updated too, so the reasoning for dropping |
The article listed -s and -w as two flags doing two jobs. The linker derives -w from -s unless -w is passed explicitly, so -s -w and -s produce the same binary: cmd/link/internal/ld/main.go carries the rule as a one-liner. Adds the measurement behind it, the four ldflags combinations with their size and their ELF sections, plus what stripping actually costs. The stack trace objection is the one that keeps -s out of projects that would benefit from it, and it is wrong: the pclntab survives, so traces and pprof are untouched. Says plainly that this is not a hardening measure, since selling it as one leads to bad calls elsewhere. Reported by a HAProxy maintainer on haproxytech/kubernetes-ingress#845, where the same -s -w had been proposed.
|
@oktalz any update for it? Not a big change at all 🙂 |
Neither build path passes
-s -w: not.goreleaser.yml, notbuild/Dockerfile:53. Bothship the symbol table and the DWARF data.
Measured
linux/amd64, same commit, sameCGO_ENABLED=0:-ldflags "-s"+ -trimpathClose to 30 MB per image, pulled on every node of every cluster.
Stack traces are not what is lost
This is the usual objection, and it does not hold. A Go stack trace is read from the
pclntab, which the linker keeps whatever the flags are:-sdrops the symbol table andthe DWARF data, and touches neither the
pclntab. Same panic, two binaries:Identical.
net/http/pprofis unaffected for the same reason: symbolisation happens inthe runtime, from the
pclntab, not from the symbol table.-wis deliberately not passed alongside-s. See the discussion below.What is genuinely lost: source-level debugging with delve on a live process,
go tool nm,and core dump analysis under gdb. For a controller that is reached over the network and
observed through its logs and its pprof endpoint, none of those is how anyone works on it.
I would not sell this as hardening.
-sdoes not meaningfully impede reverseengineering; it is a size change.
-trimpath
Almost free in size (0.2 MB) but worth its own line. It keeps the build machine's path out
of the binary, which today is 4470 occurrences of a build directory in the
linux/amd64build, and it is one of the conditions for two builds of the same commit toproduce the same bytes.
Verified
The
-Xversion stamping still applies with-sin the same-ldflagsstring, checkedon a build carrying both.