fatbin

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2019 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Overview

Package fatbin implements a simple fat binary format, and provides facilities for creating fat binaries and accessing its variants.

A fatbin binary is a base binary with a zip archive appended, containing copies of the same binary targeted to different GOOS/GOARCH combinations. The zip archive contains one entry for each supported architecture and operating system combination.

Fatbin currently only supports ELF or Mach-O base binaries.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSuchImage is returned when the fatbin does not contain an
	// image for the requested GOOS/GOARCH combination.
	ErrNoSuchImage = errors.New("image does not exist")
	// ErrUnknownImageFormat is returned when a binary cannot be read
	// as a fatbin.
	ErrUnknownImageFormat = errors.New("unknown image format")
)

Functions

func Sniff

func Sniff(r io.ReaderAt) (goos, goarch string, size int64, err error)

Sniff sniffs a binary's goos, goarch, and size. Sniff currently only supports ELF and Mach-O binaries.

Types

type Info

type Info struct {
	Goos, Goarch string
	Size         int64
}

Info provides information for an embedded binary.

func (Info) String

func (info Info) String() string

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads images from a fatbin.

func NewReader

func NewReader(r io.ReaderAt, offset, size int64, goos, goarch string) (*Reader, error)

NewReader returns a new fatbin reader from the provided reader. The offset should be the offset of the fatbin archive; size is the total file size. The provided goos and goarch are that of the base binary.

func OpenFile

func OpenFile(r io.ReaderAt, size int64) (*Reader, error)

OpenFile parses the provided ReaderAt with the provided size. The file's contents is parsed to determine the offset of the fatbin's archive. OpenFile returns an error if the file is not a fatbin.

func Self

func Self() (*Reader, error)

Self reads the currently executing binary image as a fatbin and returns a reader to it.

func (*Reader) GOARCH

func (r *Reader) GOARCH() string

GOARCH returns the base binary GOARCH.

func (*Reader) GOOS

func (r *Reader) GOOS() string

GOOS returns the base binary GOOS.

func (*Reader) List

func (r *Reader) List() []Info

List returns information about embedded binary images.

func (*Reader) Open

func (r *Reader) Open(goos, goarch string) (io.ReadCloser, error)

Open returns a ReadCloser from which the binary with the provided goos and goarch can be read. Open returns ErrNoSuchImage if the fatbin does not contain an image for the requested goos and goarch.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

A Writer is used to append fatbin images to an existing binary.

func NewFileWriter

func NewFileWriter(file *os.File) (*Writer, error)

NewFileWriter returns a writer that can be used to append fatbin images to the binary represented by the provided file. NewFileWriter removes any existing fatbin images that may be attached to the binary. It relies on content sniffing (see Sniff) to determine its offset.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a writer that may be used to append fatbin images to the writer w. The writer should be positioned at the end of the base binary image.

func (*Writer) Close

func (w *Writer) Close() error

Close should be called after all images have been written. No more images can be written after a call to Close.

func (*Writer) Create

func (w *Writer) Create(goos, goarch string) (io.Writer, error)

Create returns a Writer into which the image for the provided goos and goarch should be written. The image's contents must be written before the next call to Create or Close.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush flushes the unwritten data to the underlying file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL