This blog shares about how to set up Alive2 on Ubuntu 20.04 LTS from scratch. It took me several days to make it work properly T_T. Anyway, let’s start.
According to Alive2 Github page, Alive2 needs recent versions of:
- cmake
- gcc/clang
- re2c
- Z3
- LLVM
I’ll elaborate how to set these up one by one, but at first, given a newly installed Ubuntu, we need to install some necessary packages.
Necessary packages
- git, for cloning repos from Github
- Ninja, for building repos cloned
- Python3 (I think Ubuntu contains installed Python3 by default)
- python-is-python3. This package allows you call
python3
withpython
Thus all the commands you will need are:
1 | sudo apt-get install git |
GCC
It’d be better to use gcc-10 for supporting some c++ 20 features. Thanks to this blog, How to Install GCC (build-essential) on Ubuntu 20.04, to configure gcc-10 on our Ubuntu, we need following commands:
1 | sudo apt install g++-10 |
After executing successfully, by checking g++ -v
you would see gcc version is 10.2.0.
re2c
re2c is not hard to install. sudo apt-get install re2c
is enough.
Z3
Github page of Z3 is pretty exhaustive. After cloning the repo, you should run following commands at repo folder.
1 | python scripts/mk_make.py |
One thing needs to notice is that if you want to remove z3 for some reason in the future, you might need CheckInstall for removing installed package. Thus, if you use CheckInstall to install, those commands should become:
1 | python scripts/mk_make.py |
LLVM
After cloning LLVM repo, cd
our working directory to the new generated repo (normally the folder name is llvm-project
) and execute
1 | mkdir build |
Commands above would build LLVM with ninja. Some problems would occur if you run ninja
with sudo ninja
. Finally, to install LLVM into system, you should run
1 | ninja install |
To test if LLVM works well, you should run
1 | ninja check |
Alive2
After cloning Alive2, cd
working directory into the new generated repo (the name is alive2
by default) and run following commands
1 | mkdir build |
Notice, the argument named -DCMAKE_PREFIX_PATH
should be pointed the build folder we created in LLVM section.
If everything works well, by running
1 | ninja check |
we should pass all test. If so, congratulations! You alive2 is set and ready to go~ You could run commands such as
1 | ~/llvm/build/bin/llvm-lit -vv -Dopt=$HOME/alive2/build/opt-alive.sh ~/llvm/llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll |
or
1 | ~/llvm/build/bin/llvm-lit -vv -Dopt=$HOME/alive2/build/opt-alive.sh ~/llvm/llvm/test/Transforms |
to see results. Finally, if you see some errors like ‘filecheck error: < stdin> is empty’ when you running Alive2 on /test/Transforms
folder, don’t be panic. Some files contain bug that make Alive2 exit beforehand. Those files are reported at here. You could check them by clicking, for example. 1da2c7d25c09
on the page and redirect to files.