SRI-CSL / whole-program-llvm

A toolkit for building whole-program LLVM bitcode files
MIT License
73 stars 11 forks source link

What is the difference between bitcode generated by wllvm and directly using clang? #27

Closed arnab-security closed 5 years ago

arnab-security commented 5 years ago

I generated a bitcode using clang directly using the command. clang -I ../include -emit-llvm -c -g -O0 -Xclang -disable-O0-optnone bzip2.c Also generated same bitcode by replacing gcc by wllvm in the Makefile and using extract_bc. The two bitcode file sizes are different. The first bitcode file works with all other tools that takes bitcode as input but the second larger bitcode is giving errors. I am now wondering if I can eliminate the difference in the two bitcode files and still be able to use other tools that takes bitcode as input. Please suggest if there is any way to do that.

ianamason commented 5 years ago

The bitcode generated by wllvm IS generated by clang, using the —emit-llvm flag. So the difference you see in your experiment is caused either by different versions of clang, or by different flags used to generate the bitcode. If you are using gcc and dragonegg then I could believe there would be differences.

arnab-security commented 5 years ago

I know that the bitcode generated by wllvm is actually done by clang. But the bitcode is actually extracted from binary and probably contains some extra code (library may be) which was only linked during binary generation. Now, when I used the command as mentioned in my last post, that does not link any library or any other file. This could only explain why the size of the wllvm generated code is larger. I suspect that the bitcode structure of the extra code is causing the errors that I am getting. I am not sure about it but this is the only explanation I could think because the directly generated bitcode is not giving any error.

ianamason commented 5 years ago

When you extract-bc from an executable, you get the llvm-link of all the bitcode that was used to make the executable. You can see this by looking at the manifest. Use the -m flag when you do the extraction. You can also turn up the level of logging and watch it all happen.

ianamason commented 5 years ago

Can I close this @arnab-security ?

arnab-security commented 5 years ago

Please close it. Thanks again for all of your kind answers.