-
Notifications
You must be signed in to change notification settings - Fork 147
Whole Program Analysis (using WLLVM)
In the PhASAR tool, analysis is done on LLVM bitcode files (It is created from human readable .ll
code). In order to produce LLVM bitcode, firstly the project should be compiled. For more complex C/C++ projects, the WLLVM tool, which provides tools for building whole-program LLVM bitcode files, can be used.
In this tool a python-based compiler wrappers, at first invokes the compiler. Then, a bitcode compiler is called to produce a LLVM bitcode file for each object file, which is stored in the object file allocated segment. After linking the object files, their contents are appended. After completion of the build process, WLLVM utility can be used to link all the bitcodes into one whole-program bitcode file.
WLLVM is a pip package. You can just install it by either of these commands:
$ pip install wllvm
$ sudo pip install wllvm
Then set LLVM_COMPILER
environment variable to clang
by the following command:
export LLVM_COMPILER=clang
Two following examples show how WLLVM can be used to produce bitcode file for C++ projects:
First, download two example projects from PhASAR website. Then, do the following.
Change:
$ CXX = clang++
Into
$ CXX = wllvm++
In Makefile of simple_makefile_project.
Change:
$ set(CMAKE_C_COMPILER clang)
$ set(CMAKE_CXX_COMPILER clang++)
Into
$ set(CMAKE_C_COMPILER wllvm)
$ set(CMAKE_CXX_COMPILER wllvm++)
In CMakeLists.txt file of simple_cmake_project.
The modification in any project should be done in the highest level of CMakeLists and Makefile files.
After compiling each project, run the extract-bc
command on each .exe
file:
extract-bc main
for simple_makefile_project and extract-bc myprogram
for simple_cmakefile_project.
Above commands produce llvm bitcode files of the whole project. To create human readable .ll
file of the produced .bc
file, run the llvm-dis main.bc
and llvm-dis mypogram.bc
for simple_makefile_project and simple_cmakefile_project respectively.
You can read more about WLLM on WLLVM git and WLLVM Project description.
- Home
- Reference Material
- Getting Started:
- Building PhASAR
- Using PhASAR with Docker
- A few uses of PhASAR
- Coding Conventions
- Contributing to PhASAR
- Errors and bug reporting
- Update to Newer LLVM Versions
- OS Support
- FAQ