Gener Omer
2010-May-04 18:26 UTC
[LLVMdev] Call graph node for function: 'main' Calls external node
Hello, On the following code, // #include <stdio.h> void f2(); int main(){ f2(); return 0; } void f2(){ printf("f2()\n"); } // I have obtained the .bc file and run opt -print-callgraph finename.bc. For the main function, the output of the above command is: Call graph node for function: 'main' Calls external node However, the function called by main(which is f2) is inside the module. Is there any way to detect all function calls, including the one above and those made via pointers to functions? Thanks, Gener -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100504/67b90ebc/attachment.html>
Duncan Sands
2010-May-04 19:11 UTC
[LLVMdev] Call graph node for function: 'main' Calls external node
Hi Gener,> For the main function, the output of the above command is: > > Call graph node for function: 'main' > Calls external nodethis means that callgraph saw that main calls something, but it doesn't know what it is. It might be any function, internal (eg: f2) or external. The reason for this poor quality information is that the use of the forward declaration "void f2();", which should be "void f2(void);", results in some unpleasantness in the bitcode. If you run the optimizers it will be cleaned up. Take a look at this: without optimization and with mild optimization: $ llvm-gcc -c -o - cg.c -emit-llvm -O0 | opt -print-callgraph -disable-output 2>&1 | grep "function: 'main'" -A 2 Call graph node for function: 'main'<<0x2f80c30>> #uses=1 CS<0x2f837b8> calls external node $ llvm-gcc -c -o - cg.c -emit-llvm -O1 | opt -print-callgraph -disable-output 2>&1 | grep "function: 'main'" -A 2 Call graph node for function: 'main'<<0x20536c0>> #uses=1 CS<0x2057468> calls function 'f2' The callgraph code doesn't try to be clever. It assumes that the optimizers have been run. Ciao, Duncan.