link

package
v0.0.0-...-093a1a0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

View Source
const (
	FillNone = iota // no fill
	FillLink        // fill as linking offset for jump instructions
	FillLow         // fill with the lower 16 bits
	FillHigh        // fill with the higher 16 bits
)

Constant fill-later methods.

View Source
const (
	SymNone = iota // for default return value
	SymFunc
	SymVar
)

Linking symbol types

Variables

This section is empty.

Functions

func BareFunc

func BareFunc(f *Func) ([]byte, error)

BareFunc produces a image of a single function that has no links.

func Main

func Main(pkgs map[string]*Pkg, funcs []*PkgSym) ([]*image.Section, error)

Main is a short hand for NewJob(pkgs, path, start).Link(out)

func SinglePkg

func SinglePkg(pkg *Pkg, start string) ([]*image.Section, error)

SinglePkg call LinkMain with only one single package.

Types

type Func

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

Func is a relocatable code section

func NewFunc

func NewFunc() *Func

NewFunc creates a new relocatable code section.

func (*Func) AddInst

func (f *Func) AddInst(i uint32)

AddInst appends an instruction at the end of the function.

func (f *Func) AddLink(fill int, ps *PkgSym)

AddLink links the last instruction in inst to the symbol pkg.sym, where pkg and sym are using the indexing of the object file. fill field must be less than 4 so that it fits in the lowest 2 bits in the offset field. The other bits of the offset fields will be automatically calculated based on the number of instructions in insts.

func (*Func) Size

func (f *Func) Size() uint32

Size returns the size of the function.

func (*Func) TooLarge

func (f *Func) TooLarge() bool

TooLarge checks if the function size is larger than 4GB.

type FuncMeta

type FuncMeta struct {
	Frame uint32
	Pos   *lexing.Pos
}

FuncMeta stores the meta data of a function for generating debug symbol.

type Job

type Job struct {
	Pkgs   map[string]*Pkg
	Funcs  []*PkgSym
	InitPC uint32

	FuncDebug func(pkg, name string, addr, size uint32)
}

Job is a linking job.

func NewJob

func NewJob(pkgs map[string]*Pkg, funcs []*PkgSym) *Job

NewJob creates a new linking job which init pc is the default one.

func (j *Job) Link() ([]*image.Section, error)

Link performs the linking job and writes the output to out.

type Pkg

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

Pkg is the compiling object of a package. It is the linking unit for programs.

func NewPkg

func NewPkg(p string) *Pkg

NewPkg creates a new package for path p.

func (*Pkg) DeclareFunc

func (p *Pkg) DeclareFunc(name string)

DeclareFunc declares a function (code block).

func (*Pkg) DeclareVar

func (p *Pkg) DeclareVar(name string)

DeclareVar declares a variable (data block)

func (*Pkg) DefineFunc

func (p *Pkg) DefineFunc(name string, f *Func)

DefineFunc instantiates a function object.

func (*Pkg) DefineVar

func (p *Pkg) DefineVar(name string, v *Var)

DefineVar instantiates a variable object.

func (*Pkg) Func

func (p *Pkg) Func(name string) *Func

Func returns the function of index.

func (*Pkg) HasFunc

func (p *Pkg) HasFunc(name string) bool

HasFunc checks if the package has a function of a particular name.

func (*Pkg) Path

func (p *Pkg) Path() string

Path returns the package's path string.

func (*Pkg) PrintSymbols

func (p *Pkg) PrintSymbols(out io.Writer)

PrintSymbols prints all symbols out to a writer.

func (*Pkg) SymbolByName

func (p *Pkg) SymbolByName(name string) *Symbol

SymbolByName returns the symbol with the particular name.

func (*Pkg) Var

func (p *Pkg) Var(name string) *Var

Var returns the variable of index.

type PkgSym

type PkgSym struct {
	// Pkg is the package path
	Pkg string

	// Sym is the symbol name
	Sym string
}

PkgSym is a link to a symbol in a particular package

func NewPkgSym

func NewPkgSym(pkg, sym string) *PkgSym

NewPkgSym creates a new package symbol.

type Symbol

type Symbol struct {
	Name string
	Type int
}

Symbol is a linking symbol in an object file

type Var

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

Var reprsents a variable object

func NewVar

func NewVar(align uint32) *Var

NewVar creates a new relocatable data section.

func (*Var) IsZeros

func (v *Var) IsZeros() bool

IsZeros checks if the variable section is a BSS section.

func (*Var) Pad

func (v *Var) Pad(n uint32)

Pad pads n bytes into this data section

func (*Var) Size

func (v *Var) Size() uint32

Size returns the current size of the section

func (*Var) TooLarge

func (v *Var) TooLarge() bool

TooLarge checks if the size is larger than 2GB

func (*Var) Write

func (v *Var) Write(buf []byte) (int, error)

Write appends bytes to this data section.

func (v *Var) WriteLink(pkg, sym string) error

WriteLink writes a symbol link into the data section.

func (*Var) Zeros

func (v *Var) Zeros(n uint32)

Zeros set this variable as a BSS section.

Jump to

Keyboard shortcuts

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