stacksize

package
Version: v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package stacksize tries to determine the call graph for ELF binaries and tries to parse stack size information from DWARF call frame information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallGraph

func CallGraph(f *elf.File, callsIndirectFunction []string) (map[string][]*CallNode, error)

CallGraph parses the ELF file and reads DWARF call frame information to determine frame sizes for each function, as far as that's possible. Because at this point it is not possible to determine indirect calls, a list of indirect function calling functions needs to be supplied separately.

This function does not attempt to determine the stack size for functions. This is done by calling StackSize on a function in the call graph.

Types

type CallNode

type CallNode struct {
	Names         []string
	Address       uint64      // address at which the function is linked (without T bit on ARM)
	Size          uint64      // symbol size, in bytes
	Children      []*CallNode // functions this function calls
	FrameSize     uint64      // frame size, if FrameSizeType is Bounded
	FrameSizeType SizeType    // can be Undefined or Bounded
	// contains filtered or unexported fields
}

CallNode is a node in the call graph (that is, a function). Because this is determined after linking, there may be multiple names for a single function (due to aliases). It is also possible multiple functions have the same name (but are in fact different), for example for static functions in C.

func (*CallNode) StackSize

func (node *CallNode) StackSize() (uint64, SizeType, *CallNode)

StackSize tries to determine the stack size of the given call graph node. It returns the maximum stack size, whether this size can be known at compile time and the call node responsible for failing to determine the maximum stack usage. The stack size is only valid if sizeType is Bounded.

func (*CallNode) String

func (n *CallNode) String() string

type SizeType

type SizeType uint8

SizeType indicates whether a stack or frame size could be determined and if not, why.

const (
	Undefined SizeType = iota // not yet calculated
	Unknown                   // child has unknown stack size
	Bounded                   // stack size is fixed at compile time (no recursion etc)
	Recursive
	IndirectCall
)

Results after trying to determine the stack size of a function in the call graph. The goal is to find a maximum (bounded) stack size, but sometimes this is not possible for some reasons such as recursion or indirect calls.

func (SizeType) String

func (s SizeType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to