buildinfo

Imports

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"

Constants & Variables

buildInfoAlign const #

const buildInfoAlign = 16

buildInfoHeaderSize const #

const buildInfoHeaderSize = 32

buildInfoMagic var #

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 var #

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 var #

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

searchChunkSize const #

const searchChunkSize = *ast.BinaryExpr

Type Aliases

BuildInfo type #

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

Interfaces

exe interface #

type exe interface {
DataStart() (uint64, uint64)
DataReader(addr uint64) (io.ReaderAt, error)
}

Structs

elfExe struct #

elfExe is the ELF implementation of the exe interface.

type elfExe struct {
f *elf.File
}

machoExe struct #

machoExe is the Mach-O (Apple macOS/iOS) implementation of the exe interface.

type machoExe struct {
f *macho.File
}

peExe struct #

peExe is the PE (Windows Portable Executable) implementation of the exe interface.

type peExe struct {
f *pe.File
}

plan9objExe struct #

plan9objExe is the Plan 9 a.out implementation of the exe interface.

type plan9objExe struct {
f *plan9obj.File
}

xcoffExe struct #

xcoffExe is the XCOFF (AIX eXtended COFF) implementation of the exe interface.

type xcoffExe struct {
f *xcoff.File
}

Functions

DataReader method #

func (x *elfExe) DataReader(addr uint64) (io.ReaderAt, error)

DataReader method #

func (x *plan9objExe) DataReader(addr uint64) (io.ReaderAt, error)

DataReader method #

func (x *xcoffExe) DataReader(addr uint64) (io.ReaderAt, error)

DataReader method #

func (x *machoExe) DataReader(addr uint64) (io.ReaderAt, error)

DataReader method #

func (x *peExe) DataReader(addr uint64) (io.ReaderAt, error)

DataStart method #

func (x *machoExe) DataStart() (uint64, uint64)

DataStart method #

func (x *peExe) DataStart() (uint64, uint64)

DataStart method #

func (x *plan9objExe) DataStart() (uint64, uint64)

DataStart method #

func (x *xcoffExe) DataStart() (uint64, uint64)

DataStart method #

func (x *elfExe) DataStart() (uint64, uint64)

Read function #

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 function #

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)

decodeString function #

func decodeString(x exe, addr uint64) (string, uint64, error)

hasPlan9Magic function #

func hasPlan9Magic(magic []byte) bool

imageBase method #

func (x *peExe) imageBase() uint64

readData function #

func readData(x exe, addr uint64, size uint64) ([]byte, error)

readDataInto function #

func readDataInto(x exe, addr uint64, b []byte) (int, error)

readRawBuildInfo function #

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 function #

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 function #

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