Repository navigation
Conversation
The example ran go tool nm on a binary built with -ldflags="-s -w", which has no symbol table, so nm only reports "no symbols". Also, piping the output to "sort -nr" sorts by the first column, which is the symbol address (in hex), not the size. Run nm on a binary built without -s -w, and use its own -sort size option. Fixes: 679f715 ("Document v3 binary size checks") Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
|
| ```sh-session | ||
| go build -trimpath -o myapp ./cmd/myapp | ||
| go version -m myapp | ||
| go tool nm -size myapp | sort -nr | head -40 |
There was a problem hiding this comment.
@kolyshkin can you should me a before and after of the command output?
There was a problem hiding this comment.
Please try it yourself -- all you need is Go installed.
Basically, "before" doesn't work because the binary is stripped, and even when it's not, the output is sorted by address (rather than size).
After is what the original author had in mind (I guess).
There was a problem hiding this comment.
😅 the purpose of the ask is to provide documentation, not for me to see the diff personally
Here's a format for you
before
# input
ls "~/camels"| rg water | xargs drink.sh
# output
wow I love this, but it wasnt muchafter
# input
ls "~/camels" | rg liquid | xargs drink.sh
# output
this was okay, and I feel satisfied
What type of PR is this?
What this PR does / why we need it:
The binary size doc ran
go tool nmon a binary built with-ldflags="-s -w",which has no symbol table, so nm only reports
no symbols.Also, piping the output to
sort -nrsorts by the first column, which is thesymbol address (in hex), not the size.
Run nm on a binary built without
-s -w, and use its own-sort sizeoption.Which issue(s) this PR fixes:
None (fixes 679f715, "Document v3 binary size checks").
Testing
Checked with a hello-world binary: stripped one gives
no symbol section/no symbols;go tool nm -size -sort sizelists the largest symbols first,while
| sort -nrorders them by address.Release Notes