镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

docs: fix go tool nm usage in binary-size.md - #2457

Open
kolyshkin wants to merge 1 commit into
urfave:mainfrom
kolyshkin:docs-nm-binary-size
Open

kolyshkin wants to merge 1 commit into
urfave:mainfrom
kolyshkin:docs-nm-binary-size

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • documentation

What this PR does / why we need it:

The binary size doc 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.

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 size lists the largest symbols first,
while | sort -nr orders them by address.

Release Notes

NONE

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>
@kolyshkin
kolyshkin requested a review from a team as a code owner October 5, 2026 22:06
@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Low risk] Fixes documentation about binary inspection tools.

The documentation change appears safe to merge.

Summary

The documentation now rebuilds the binary with symbols before inspecting it and asks go tool nm to sort symbols by size.

Reviews (1) · Last reviewed commit: "docs: fix go tool nm usage in binary-siz..."

Comment thread docs/v3/binary-size.md
```sh-session
go build -trimpath -o myapp ./cmd/myapp
go version -m myapp
go tool nm -size myapp | sort -nr | head -40

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolyshkin can you should me a before and after of the command output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 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 much

after

# input
ls "~/camels" | rg liquid | xargs drink.sh

# output
this was okay, and I feel satisfied

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants