LinuxCommandLibrary

go-tool

Compile, test, and analyze Go code

TLDR

List available tools

$ go tool
copy

Run the go link tool
$ go tool link [path/to/main.o]
copy

Print the command that would be executed, but do not execute it (similar to whereis)
$ go tool -n [command] [arguments]
copy

View documentation for a specified tool
$ go tool [command] --help
copy

List all available cross-compilation targets
$ go tool dist list
copy

SYNOPSIS

go tool [-n] [toolname] [tool args ...]

PARAMETERS

-n
    Print commands that would be executed without running them

DESCRIPTION

go tool is a gateway command in the Go programming language toolchain on Linux and other Unix-like systems. It provides direct access to low-level build tools bundled with the Go distribution, such as compilers, linkers, disassemblers, and analyzers.

Normally, users rely on high-level go subcommands like go build, go test, or go run, which orchestrate these tools automatically. However, go tool enables manual invocation for advanced scenarios, like custom compilation flags, debugging binaries, or integrating into build scripts.

Without arguments, it lists all available tools (e.g., compile, link, asm, objdump, nm, pprof). Specifying a tool name runs it with passed arguments, mimicking direct executable calls while respecting Go's environment.

This command is essential for toolchain development, reverse engineering Go binaries, or when higher-level commands fall short. It operates within the $GOROOT/pkg/tool directory, where platform-specific binaries reside.

CAVEATS

Primarily for advanced users; misuse can lead to incompatible binaries. Tools are platform-specific and version-locked to the Go release.

COMMON TOOLS

compile: Compiles Go packages.
link: Links object files into executables.
asm: Go assembler.
objdump: Disassembles binaries.
pprof: Profiles CPU/memory.

USAGE NOTE

List tools with go tool; find binaries in $GOROOT/pkg/tool/linux_amd64.

HISTORY

Introduced in Go 1.0 (2012), evolving from pre-release toolchain (6g/8g compilers). Modernized with Go modules in 1.11+; tool list expands per release (e.g., trace in 1.7).

SEE ALSO

go(1)

Copied to clipboard