How to inspect Go package files (.a files)?

Viewed 332

How to inspect the content of Go package/object files (.a, .o)

The only thing I found is showing the full disassembly with go tool objdump.

But how to show the file structure, like imported and exported symbols, code, data and other sections, other metadata etc.?

1 Answers

Compiled Go packages are stored in Unix ar archive files, so you can extract the files within them using ar or go tool pack x pkg.a.

Package files contain compiled code (_go_.o), used by the linker to build binaries, and export data (__.PKGDEF), used by the compiler when building dependent packages. If the package contained assembly files or cgo code, there may be additional .o files, too.

You can use golang.org/x/tools/go/gcexportdata to read export data into a format that can be understood by go/types.

It sounds like you've already found go tool objdump for disassembly. You might also find go tool nm useful for listing symbols.

Related