gen

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package gen contains utilities to generate Go bindings for eBPF ELF files.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTarget = errors.New("unsupported target")

Functions

func CollectGlobalTypes

func CollectGlobalTypes(spec *ebpf.CollectionSpec) []btf.Type

CollectGlobalTypes finds all types which are used in the global scope.

This currently includes the types of variables, map keys and values.

func Compile

func Compile(args CompileArgs) error

Compile C to a BPF ELF file.

func FindTarget

func FindTarget(id string) (Target, GoArches, error)

FindTarget turns a list of identifiers into targets and their respective GoArches.

The following are valid identifiers:

  • bpf: compile generic BPF for host endianness
  • bpfel: compile generic BPF for little endian
  • bpfeb: compile generic BPF for big endian
  • native: compile BPF for host target
  • $GOARCH: compile BPF for $GOARCH target

Generic BPF can run on any target goarch with the correct endianness, but doesn't have access to some arch specific tracing functionality.

func Generate

func Generate(args GenerateArgs) error

Generate bindings for a BPF ELF file.

func TargetsByGoArch

func TargetsByGoArch() map[GoArch]Target

TargetsByGoArch returns all supported targets.

Types

type CompileArgs

type CompileArgs struct {
	// Which compiler to use.
	CC string
	// Command used to strip DWARF from the ELF.
	Strip string
	// Flags to pass to the compiler.
	Flags []string
	// Absolute working directory
	Workdir string
	// Absolute input file name
	Source string
	// Absolute output file name
	Dest string
	// Target to compile for, defaults to compiling generic BPF in host endianness.
	Target           Target
	DisableStripping bool
}

type GenerateArgs

type GenerateArgs struct {
	// Package of the resulting file.
	Package string
	// The prefix of all names declared at the top-level.
	Stem string
	// Build Constraints included in the resulting file.
	Constraints constraint.Expr
	// Maps to be emitted.
	Maps []string
	// Variables to be emitted.
	Variables []string
	// Programs to be emitted.
	Programs []string
	// Types to be emitted.
	Types []btf.Type
	// Filename of the object to embed.
	ObjectFile string
	// Output to write template to.
	Output io.Writer
	// Function which transforms the input into a valid go identifier. Uses the default behaviour if nil
	Identifier func(string) string
}

type GoArch

type GoArch string

GoArch is a Go arch string.

See https://go.dev/doc/install/source#environment for valid GOARCHes when GOOS=linux.

type GoArches

type GoArches []GoArch

func (GoArches) Constraint

func (arches GoArches) Constraint() constraint.Expr

Constraints is satisfied when GOARCH is any of the arches.

type Target

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

func (*Target) IsGeneric

func (tgt *Target) IsGeneric() bool

IsGeneric returns true if the target will compile to generic BPF.

func (*Target) ObsoleteSuffix

func (tgt *Target) ObsoleteSuffix() string

ObsoleteSuffix returns an obsolete suffix for a subset of targets.

It's used to work around an old bug and should not be used in new code.

func (*Target) Suffix

func (tgt *Target) Suffix() string

Suffix returns a a string suitable for appending to a file name to identify the target.

Jump to

Keyboard shortcuts

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