SVF-tools / SVF

Static Value-Flow Analysis Framework for Source Code
http://svf-tools.github.io/SVF/
Other
1.42k stars 435 forks source link

dump and restore point-to analysis #1139

Open tregua87 opened 1 year ago

tregua87 commented 1 year ago

Is there a way to store the result of a point-to-analysis (or PTACallGraph)?

My problem is that the point to analysis takes hours for big projects (such as OpenSSL). I want to store their results in a file so that I can re-use them later.

Is this feature included in SVF? In case, could I have some pointers to implement it myself, please?

yuleisui commented 1 year ago

You may wish to try this: https://github.com/SVF-tools/SVF/blob/8ec46074f2009f9cb064efa1ee4a07186c3097ea/svf/lib/Util/Options.cpp#L744

tregua87 commented 1 year ago

I try to write and read the point to information, but the program crashes. Here is a small snippet:

FlowSensitive* point_to_analysys = FlowSensitive::createFSWPA(pag);
point_to_analysys->writeToFile("point_to.txt");
SVFUtil::outs() << "[INFO] point_to_analysys STORED\n";
FlowSensitive* point_to_analysys_2 = new FlowSensitive(pag);
point_to_analysys_2->readFromFile("point_to.txt");
SVFUtil::outs() << "[INFO] point_to_analysys LOADED\n";

To replicate the error I leave a minimal example in pointto.zip. Modify env.sh to point to the correct SVF version, then:

./bootstrap.sh
make -j
./bin/extractor library.o.bc

I used the SVF commit: 9ce2cb473df64f14c340ff0d1c7e918d98912740.

NOTE: I noticed that rarely the program does not crash, but the majority of the time it crashes.

pointto.zip

yuleisui commented 1 year ago

Thanks for reporting this @JasonZhongZexin could you take a look at this issue?

@tregua87 have you tried to write and read Andersen's analysis using -write-ander and -read-ander?

tregua87 commented 1 year ago

I am not sure what you want me to try.

I run this simple example:

./Debug-build/bin/wpa ./library.o.bc -ander  -write-ander aaa.txt
./Debug-build/bin/wpa ./library.o.bc -ander  -read-ander aaa.txt

No crash observed (and aaa.txt is generated).

For the sake of clarity, I tried:

Andersen* point_to_analysys = AndersenWaveDiff::createAndersenWaveDiff(pag);
point_to_analysys->writeToFile("point_to.txt");
SVFUtil::outs() << "[INFO] point_to_analysys STORED\n";
Andersen *point_to_analysys_2 = new Andersen(pag);
point_to_analysys_2->readFromFile("point_to.txt");
SVFUtil::outs() << "[INFO] point_to_analysys LOADED\n";
exit(1);

I notice that the first time it works fine. From the second time ahead, I have to clean point_to.txt file, otherwise my program crashes.

When using FlowSensitive (the attempt in the first post), the program always crashes.

JasonZhongZexin commented 1 year ago

Hi @tregua87, thanks for reporting this issue. I am currently investigating this problem. It will be fixed as soon as possible, and I will notify you when it is set.

tregua87 commented 1 year ago

@JasonZhongZexin do you have updates for this issue?

JasonZhongZexin commented 1 year ago

@JasonZhongZexin do you have updates for this issue?

@tregua87 sorry for the late response. In our recently updated, we fixed the read-and-write module for the Andersen point-to analysis. You can now use it by invoking the solveAndwritePtsToFile(filepath) and readPtsFromFile(filePath) methods. For example, in your case, you can do it by the following code:

Andersen* pts = AndersenWaveDiff::createAndersenWaveDiff(pag);    
// solve and write the pts results to file
pts->solveAndwritePtsToFile(filepath);

// read pts results from file
pts->readPtsFromFile(filepath);

For the flow-sensitive analysis, some problems still need to be fixed in analyzing large-scale cases, and the patch is still working in progress. I will notify you when it is done.

JasonZhongZexin commented 1 year ago

Hi @tregua87, sorry for the long wait! We have fixed all the issues with the SVF read and write analysis results in our most recent update. You can fetch our repository to get the latest updates. To learn how to use it, you can follow this guidance.