llvm-analysis-0.3.0: A Haskell library for analyzing LLVM bitcode

Safe HaskellNone




This module defines a call graph and related functions. The call graph is a static view of the calls between functions in a Module. The nodes of the graph are global functions and the edges are calls made to other functions.

This call graph attempts to provide as much information as possible about calls through function pointers. Direct calls have a single outgoing edge. Indirect calls that can be augmented with information from a points-to analysis can induce many IndirectCall edges.

For now, all indirect calls also induce an UnknownCall edge, under the assumption that externally-obtained function pointers may also be called somehow. This restriction will eventually be lifted and indirect calls that can be identified as completely internal will not have the UnknownCall edge. The preconditions for this will be:

  • The Module must have an entry point (otherwise it is a library)
  • The function pointer must not be able to alias the result of a dlopen or similar call

Again, the more sophisticated callgraph is still pending.



data CallGraph Source

An opaque wrapper for the callgraph. The nodes are functions and the edges are calls between them.




:: PointsToAnalysis a 
=> Module 
-> a

A points-to analysis (to resolve function pointers)

-> [Function]

The entry points to the Module

-> CallGraph 

Build a call graph for the given Module using a pre-computed points-to analysis. The String parameter identifies the program entry point.

FIXME: entryPoint is not respected.

FIXME: Function pointers can be bitcasted - be sure to respect those when adding indirect edges.


callValueTargets :: CallGraph -> Value -> [Value]Source

Given the value called by a Call or Invoke instruction, return all of the possible Functions or ExternalFunctions that it could be.

callSiteTargets :: CallGraph -> Instruction -> [Value]Source

Given a Call or Invoke instruction, return the list of possible callees. All returned Values will be either Functions or ExternalFunctions.

Passing a non-call/invoke instruction will trigger a noisy pattern matching failure.

callGraphFunctions :: CallGraph -> [Function]Source

Get all of the functions defined in this module from the CallGraph

functionCallees :: CallGraph -> Function -> [Value]Source

allFunctionCallees :: CallGraph -> Function -> [Value]Source

functionCallers :: CallGraph -> Function -> [Value]Source

allFunctionCallers :: CallGraph -> Function -> [Value]Source