Giter Site home page Giter Site logo

overcg's Introduction

OverCG

Generate call graph of c program from its corresponding LLVM IR

Usage

python OverCG.py -h
usage: OverCG.py [-h] [-i INPUT] [-o OUTPUT] [-e] [-s]

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        the input file
  -o OUTPUT, --output OUTPUT
                        the output file
  -e, --externalNode    make call graph with external node
  -s, --show            show the call graph using xdot

Requirements

First, you should install clang and LLVM, such that you can get the IR file.

Second, to show the call graph by '-s', you should install xdot and graphviz.

example

If we want to get the call graph of the following c program,

#include<stdio.h>

void foo(){printf("hello foo!");}
void goo(){printf("hello goo!");}

void main(){
  int x = 1;
  void (*r)() = &foo;
  void (*s)() = &goo;
  void (*p)();
  if(x)
    p = r;
  else
    p = s;
  p(); // print the called function name
}

we can use the opt tool in LLVM, like this,

opt --dot-callgraph test1.ll --disable-output
xdot callgraph.dot

The above command will output the following call graph,

cg1

it is not accurate, since the opt tool can noly process the directly call. However, when using OverCG, we can get the following call graph,

cg2

Another example bitcnts is from cbench that is a collection of open-source programs with multiple datasets assembled by the community. The source files can be find in the bitcnts directory. It uses an array to store the function pointers and calls the actual function through the function pointer, the code snippet is as following.

	static int (* CDECL pBitCntFunc[FUNCS])(long) = {
	    bit_count,
	    bitcount,
	    ntbl_bitcnt,
	    ntbl_bitcount,
	    /*            btbl_bitcnt, DOESNT WORK*/
	    BW_btbl_bitcount,
	    AR_btbl_bitcount,
	    bit_shifter
	  };
	  ......
	  for (j = n = 0, seed = 1; j < iterations; j++, seed += 13)
		 n += pBitCntFunc[i](seed);

The following graph is the call graph of bitcnts generated by opt tool. cg3

From the graph, we can see that there does not exist any edge from main function to function bit_count, bitcount, ..., bit_shifter. But it can be done by OverCG, see the following graph. cg4

overcg's People

Contributors

coffezhou avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.