0

I am trying to generate a CFG from 3 C source files using LLVM tools. clang -emit-llvm -c a.c b.c c.c main.c Thereafter I use llvm-link to link the bytecode together. llvm-link -o out a.bc b.bc c.bc main.bc

However by doing this I get an unexpected CFG.

Here are my source files:

#include "m.h"
void a(){
b();
}
void b(){
c();
}

a.c

#include "m.h"

void c(){
e();
}

void d(){
f();
}

b.c

#include "m.h"

void e(){
f();
}

void f(){
d();
}

c.c

#include "m.h"
int main(){
a();
e();
return 0;
}

main.c

The m.h file has the function prototypes.

What could be the problem here?

nkigen
  • 410
  • 1
  • 6
  • 15
  • Do you get a different answer if you just paste all this C code into a single C file? I find it very unlikely that LLVM IR-level linking messes up with your CFG – Eli Bendersky Aug 21 '15 at 19:56
  • @EliBendersky yes I get a totally different answer. https://www.dropbox.com/s/k90ovwk08bq5hap/callgraph.png?dl=0 which is the correct answer . Any idea on the problem or I've done something wrong? – nkigen Aug 24 '15 at 17:48
  • Just compare the IRs with and without linking – Eli Bendersky Aug 24 '15 at 19:55

0 Answers0