pointer

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 10 Imported by: 0

README

Unification based pointer analysis for Go

This repository contains a Go adaptation of Steensgaard's pointer analysis algorithm.

The analysis is field-sensitive and context-insensitive.

Having field-sensitivity means that the analysis cannot run in $O(n\cdot\alpha(n))$ time (where $n$ is the size of the program), which is the runtime of the algorithm presented in the paper. Other details, such as handling dynamic dispatch for interface methods, also prevent us from obtaining the above runtime. It should still be fast, though. The goal is that this implementation should be significantly faster than the implementation of Andersen's pointer analysis algorithm provided by the Go team (with a precision trade-off).

This implementation makes many of the same design choices as the implementation of Andersen's algorithm. Notably, arrays (and slices) are modelled as having 1 element, conversions using unsafe.Pointer are not modelled soundly, and the effects of opaque code (runtime, Cgo, etc.) is under-approximated. The API is also similar.

Contrary to the implementation of Andersen's algorithm, no special modelling is offered for reflection (which is available under a flag there). Also, in this implementation constraint generation is interleaved with constraint solving. This makes it easy to only generate constraints for reachable code, which the Andersen implementation does not do.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

Functions

func FieldIndex

func FieldIndex(t *types.Struct, fieldName string) int

func PointerLike

func PointerLike(t types.Type) bool

func PrintSSAFun

func PrintSSAFun(fun *ssa.Function)

Types

type AllocationSite

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

func (AllocationSite) Path

func (a AllocationSite) Path() string

func (AllocationSite) Site

func (a AllocationSite) Site() ssa.Value

func (AllocationSite) Type

func (a AllocationSite) Type() types.Type

type AnalysisConfig

type AnalysisConfig struct {
	Program *ssa.Program

	// Functions in this list will be treated as program entry points.
	EntryFunctions []*ssa.Function
	// Packages in this list will have their main & init functions treated as
	// program entry points.
	EntryPackages []*ssa.Package

	// When TreatMethodsAsRoots is true, all methods of all types in
	// prog.RuntimeTypes() are implicitly called.
	// This is mainly useful for soundness comparison with the analysis in
	// "golang.org/x/tools/go/pointer" which does the same thing.
	TreatMethodsAsRoots bool
}

type Array

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

func (Array) String

func (a Array) String() string

type Chan

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

func (Chan) String

func (c Chan) String() string

type Closure

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

func (Closure) String

func (c Closure) String() string

type ElementPointer

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

func (ElementPointer) Path

func (ep ElementPointer) Path() string

func (ElementPointer) Site

func (ep ElementPointer) Site() ssa.Value

func (ElementPointer) Type

func (ep ElementPointer) Type() types.Type

type FieldPointer

type FieldPointer struct {
	Field int
	// contains filtered or unexported fields
}

func (FieldPointer) Path

func (fp FieldPointer) Path() string

func (FieldPointer) Site

func (fp FieldPointer) Site() ssa.Value

func (FieldPointer) Type

func (fp FieldPointer) Type() types.Type

type Fresh

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

func (Fresh) String

func (f Fresh) String() string

type Interface

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

func (Interface) String

func (i Interface) String() string

type Label

type Label interface {
	// Allocation site of the object denoted by the label.
	Site() ssa.Value
	// Returns an access path to the object that is compatible with the paths
	// provided for labels in the Go team implementation of Andersen's pointer
	// analysis. Specifically field names are resolved from ssa indices.
	Path() string
	// Returns the type of a pointer pointing to the object denoted by the
	// label. (Label).Type().Underlying() == (*types.Pointer) except for
	// allocation sites for slices (where the returned type is (*types.Slice)).
	Type() types.Type
}

Label denotes an abstract object. A label is either an AllocationSite, representing the object allocated at a given instruction, or a FieldPointer & ElementPointer, representing a subobject of another object (field of a struct or element of slice/array, respectively).

type Map

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

func (Map) String

func (m Map) String() string

type Pointer

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

A Pointer is an equivalence class of pointer-like values.

func (Pointer) MayAlias

func (p Pointer) MayAlias(o Pointer) bool

MayAlias reports, in constant time, whether the receiver pointer may alias the argument pointer.

func (Pointer) PointsTo

func (p Pointer) PointsTo() []Label

PointsTo returns a set of labels representing objects that the pointer may point to.

type PointsTo

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

func (PointsTo) String

func (c PointsTo) String() string

type Result

type Result struct {
	// Reachable contains all function discovered during analysis.
	Reachable map[*ssa.Function]bool
	CallGraph *callgraph.Graph
	// contains filtered or unexported fields
}

Result exposes some public members and an API to query analysis results.

func Analyze

func Analyze(config AnalysisConfig) Result

func (*Result) Pointer

func (r *Result) Pointer(v ssa.Value) Pointer

Pointer retrieves the abstract pointer associated with the given ssa Value.

type Struct

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

func (Struct) String

func (s Struct) String() string

type Term

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

func T

func T(x termTag) *Term

func (*Term) String

func (t *Term) String() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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