Imports #
"bytes"
"debug/elf"
"debug/macho"
"debug/pe"
"debug/plan9obj"
"encoding/binary"
"errors"
"fmt"
"internal/saferio"
"internal/xcoff"
"io"
"io/fs"
"os"
"runtime/debug"
_ "unsafe"
"bytes"
"debug/elf"
"debug/macho"
"debug/pe"
"debug/plan9obj"
"encoding/binary"
"errors"
"fmt"
"internal/saferio"
"internal/xcoff"
"io"
"io/fs"
"os"
"runtime/debug"
_ "unsafe"
const buildInfoAlign = 16
const buildInfoHeaderSize = 32
The build info blob left by the linker is identified by a 32-byte header, consisting of buildInfoMagic (14 bytes), followed by version-dependent fields.
var buildInfoMagic = *ast.CallExpr
errNotGoExe is returned when a given executable file is valid but does not contain Go build information. errNotGoExe should be an internal detail, but widely used packages access it using linkname. Notable members of the hall of shame include: - github.com/quay/claircore Do not remove or change the type signature. See go.dev/issue/67401. go:linkname errNotGoExe
var errNotGoExe = *ast.CallExpr
errUnrecognizedFormat is returned when a given executable file doesn't appear to be in a known format, or it breaks the rules of that format, or when there are I/O errors reading the file.
var errUnrecognizedFormat = *ast.CallExpr
const searchChunkSize = *ast.BinaryExpr
Type alias for build info. We cannot move the types here, since runtime/debug would need to import this package, which would make it a much larger dependency.
type BuildInfo debug.BuildInfo
type exe interface {
DataStart() (uint64, uint64)
DataReader(addr uint64) (io.ReaderAt, error)
}
elfExe is the ELF implementation of the exe interface.
type elfExe struct {
f *elf.File
}
machoExe is the Mach-O (Apple macOS/iOS) implementation of the exe interface.
type machoExe struct {
f *macho.File
}
peExe is the PE (Windows Portable Executable) implementation of the exe interface.
type peExe struct {
f *pe.File
}
plan9objExe is the Plan 9 a.out implementation of the exe interface.
type plan9objExe struct {
f *plan9obj.File
}
xcoffExe is the XCOFF (AIX eXtended COFF) implementation of the exe interface.
type xcoffExe struct {
f *xcoff.File
}
func (x *elfExe) DataReader(addr uint64) (io.ReaderAt, error)
func (x *plan9objExe) DataReader(addr uint64) (io.ReaderAt, error)
func (x *xcoffExe) DataReader(addr uint64) (io.ReaderAt, error)
func (x *machoExe) DataReader(addr uint64) (io.ReaderAt, error)
func (x *peExe) DataReader(addr uint64) (io.ReaderAt, error)
func (x *machoExe) DataStart() (uint64, uint64)
func (x *peExe) DataStart() (uint64, uint64)
func (x *plan9objExe) DataStart() (uint64, uint64)
func (x *xcoffExe) DataStart() (uint64, uint64)
func (x *elfExe) DataStart() (uint64, uint64)
Read returns build information embedded in a Go binary file accessed through the given ReaderAt. Most information is only available for binaries built with module support.
func Read(r io.ReaderAt) (*BuildInfo, error)
ReadFile returns build information embedded in a Go binary file at the given path. Most information is only available for binaries built with module support.
func ReadFile(name string) (info *BuildInfo, err error)
func decodeString(x exe, addr uint64) (string, uint64, error)
func hasPlan9Magic(magic []byte) bool
func (x *peExe) imageBase() uint64
func readData(x exe, addr uint64, size uint64) ([]byte, error)
func readDataInto(x exe, addr uint64, b []byte) (int, error)
readRawBuildInfo extracts the Go toolchain version and module information strings from a Go binary. On success, vers should be non-empty. mod is empty if the binary was not built with modules enabled.
func readRawBuildInfo(r io.ReaderAt) (vers string, mod string, err error)
readString returns the string at address addr in the executable x.
func readString(x exe, ptrSize int, readPtr func([]byte) uint64, addr uint64) string
searchMagic returns the aligned first instance of buildInfoMagic in the data range [addr, addr+size). Returns false if not found.
func searchMagic(x exe, start uint64, size uint64) (uint64, error)
Generated with Arrow