SVF
SVF copied to clipboard
The Call Graph Problem of Virtual Functions
I recently attempted to analyze the entire project using SVF and encountered a problem with identifying virtual function calls. Here is a simple case I reproduced
#include <stdio.h>
namespace name1
{
class name1_base
{
public:
/* pure virtual function */
virtual void action(int * data);
};
class int_name1 : public name1_base
{
public:
void action(int * data);
};
void int_name1::action(int * data)
{
printf("%d",*data);
}
void test()
{
int * data;
data = nullptr;
name1_base* baseObject = new int_name1;
baseObject->action(data);
delete baseObject;
}
}
#include <stdio.h>
namespace name2
{
class name2_base
{
public:
virtual void action(char * data);
};
class long_name2 : public name2_base
{
public:
void action(char * data);
};
void long_name2::action(char * data)
{
printf("%d",*data);
}
void test()
{
char * data;
data = nullptr;
name2_base* baseObject = new long_name2;
baseObject->action(data);
delete baseObject;
}
}
Two namespaces were used in each of the two CPP files; The content is basically consistent (except for class and parameter names that are different), then compile and link them separately with llvm-link name1.bc name2.bc -o test.bc. Generate a call graph for the linked BC file, and it is found that there is a missing call to a function.
But if all the content is written in one file, then the result is normal.
Can you give me some help? Thank you! The test files and callgraph are as follows: test24-1-3.zip