Skip to content

Commit 45b4700

Browse files
rmalmainsebastianpoeplauaurelf
authored
SymCC Runtime Integration (#55)
* Removed SymCC submodule & added SymCC-RT submodule. * SymCC Runtime Integration * Option to change SymCC RT backend * Option to compile SymCC RT statically and dynamically * Update working distributions * Adapt Dockerfile and GitHub workflow. * Make it possible to build against all possible LLVM versions as a command line switch TODO: LLVM 18 is not currently working... --------- Co-authored-by: Sebastian Poeplau <[email protected]> Co-authored-by: Aurelien Francillon <[email protected]>
1 parent ba782cb commit 45b4700

File tree

12 files changed

+159
-120
lines changed

12 files changed

+159
-120
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build
2+
.git

.github/workflows/main.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
on:
2-
workflow_dispatch:
3-
push:
4-
pull_request:
5-
6-
jobs:
7-
build-and-test:
8-
runs-on: ubuntu-latest
9-
steps:
10-
- uses: actions/checkout@v4
11-
- run: git submodule update --init --recursive symcc
12-
- run: docker build -t symcc symcc
13-
- run: docker build -t symqemu .
1+
on:
2+
workflow_dispatch:
3+
push:
4+
pull_request:
5+
jobs:
6+
build-and-test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- run: git submodule update --init --recursive subprojects/symcc-rt
11+
# build and test with default LLVM version 15
12+
- run: docker build -t symqemu .
13+
# LLVM version 14
14+
- run: docker build --build-arg LLVM_VERSION=14 -t symqemu .

.gitmodules

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
[submodule "tests/lcitool/libvirt-ci"]
4444
path = tests/lcitool/libvirt-ci
4545
url = https://gitlab.com/libvirt/libvirt-ci.git
46-
[submodule "symcc"]
47-
path = symcc
48-
url = https://github.com/eurecom-s3/symcc.git
46+
[submodule "subprojects/symcc-rt"]
47+
path = subprojects/symcc-rt
48+
url = https://github.com/eurecom-s3/symcc-rt.git
49+
branch = main

Dockerfile

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,58 @@
11
# prepare machine
22
FROM ubuntu:22.04 as builder
33

4-
RUN apt update
5-
RUN apt install -y \
4+
RUN apt update && apt install -y \
65
ninja-build \
76
libglib2.0-dev \
87
llvm \
98
git \
109
python3 \
11-
python3-pip
12-
13-
#
14-
FROM builder as symqemu
10+
python3-pip \
11+
cmake \
12+
wget \
13+
lsb-release \
14+
software-properties-common \
15+
gnupg \
16+
z3 \
17+
libz3-dev \
18+
libz3-dev \
19+
libzstd-dev
20+
21+
RUN pip install --user meson
22+
23+
# This is passed along to symcc and qsym backend
24+
arg LLVM_VERSION=15
25+
26+
# installing/building with the right LLVM version, currently:
27+
# - no plan to support < 11
28+
# - 12 to 15 are in official packages,
29+
# - 16 and 17 provided by llvm.org
30+
# - TODO 18 should be fixed
31+
RUN if [ $LLVM_VERSION -le 11 ]; then echo "LLVM <= 11 not supported" ; false ;fi
32+
RUN if [ $LLVM_VERSION -ge 18 ]; then echo "LLVM >= 18 currently not supported" ; false ;fi
33+
RUN if [ $LLVM_VERSION -eq 12 ] || [ $LLVM_VERSION -eq 13 ] || [ $LLVM_VERSION -eq 14 ] || [ $LLVM_VERSION -eq 15 ]; then \
34+
apt install -y llvm-${LLVM_VERSION} clang-${LLVM_VERSION} ; \
35+
else mkdir /llvm && cd /llvm && wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh ${LLVM_VERSION}; \
36+
fi
1537

1638
COPY . /symqemu_source
1739
WORKDIR /symqemu_source
1840

19-
# Meson gives an error if symcc is in a subdirectory of symqemu
20-
RUN mv /symqemu_source/symcc /symcc
21-
22-
# The only symcc artifact needed by symqemu is libSymRuntime.so
23-
# Instead of compiling symcc in this image, we rely on the existing symcc docker image and
24-
# we just copy libSymRuntime.so at the location where symqemu expects it
25-
COPY --from=symcc /symcc_build/SymRuntime-prefix/src/SymRuntime-build/libSymRuntime.so /symcc/build/SymRuntime-prefix/src/SymRuntime-build/libSymRuntime.so
26-
27-
RUN ./configure \
41+
RUN mkdir build && cd build && ../configure \
2842
--audio-drv-list= \
2943
--disable-sdl \
3044
--disable-gtk \
3145
--disable-vte \
3246
--disable-opengl \
3347
--disable-virglrenderer \
34-
--disable-werror \
35-
--target-list=x86_64-linux-user,riscv64-linux-user \
48+
--target-list=x86_64-linux-user,riscv64-linux-user \
3649
--enable-debug \
37-
--symcc-source=/symcc \
38-
--symcc-build=/symcc/build \
3950
--enable-debug-tcg \
40-
--enable-werror
51+
--symcc-rt-llvm-version="$LLVM_VERSION"
4152

42-
RUN make -j
53+
RUN cd build && make -j
4354

44-
RUN make check
55+
RUN cd build && make check
4556

4657
WORKDIR /symqemu_source/tests/symqemu
4758
RUN python3 -m unittest test.py

README.md

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,25 @@
22

33
This is SymQEMU, a binary-only symbolic executor based on QEMU and SymCC. It
44
currently extends QEMU 8.1 and works with the most recent version of SymCC.
5-
(See README.orig for QEMU's original README file.)
6-
A separate branch is available for the [old version of SymQEMU based on QEMU 4.1.1](https://github.com/eurecom-s3/symqemu/tree/4.1.1) we don't expect much
5+
(See README.orig for QEMU's original README file.) A separate branch is
6+
available for the [old version of SymQEMU based on QEMU
7+
4.1.1](https://github.com/eurecom-s3/symqemu/tree/4.1.1) we don't expect much
78
changes to happen there, but PR may be accepted.
89

910
## How to build
1011

11-
SymQEMU requires [SymCC](https://github.com/eurecom-s3/symcc), so please
12-
download and build SymCC first. For best results, configure it with the QSYM
13-
backend as explained in the README. For the impatient, here's a quick summary of
14-
the required steps that may or may not work on your system:
12+
First of all, make sure the
13+
[symcc-rt](https://github.com/eurecom-s3/symcc-rt.git) submodule is initialized:
1514

1615
``` shell
17-
$ git clone https://github.com/eurecom-s3/symcc.git
18-
$ cd symcc
19-
$ git submodule update --init
20-
$ mkdir build
21-
$ cd build
22-
$ cmake -G Ninja -DQSYM_BACKEND=ON ..
23-
$ ninja
16+
$ git submodule update --init --recursive subprojects/symcc-rt
2417
```
2518

26-
Next, make sure that QEMU's build dependencies are installed. Most package
27-
managers provide a command to get them, e.g., `apt build-dep qemu` on Debian and
28-
Ubuntu, or `dnf builddep qemu` on Fedora and CentOS.
19+
Make sure that QEMU's build dependencies are installed. Most package managers
20+
provide a command to get them, e.g., `apt build-dep qemu` on Debian and Ubuntu,
21+
or `dnf builddep qemu` on Fedora and CentOS.
2922

30-
We've extended QEMU's configuration script to accept pointers to SymCC's source
31-
and binaries. The following invocation is known to work on Debian 10, Arch and
32-
Fedora 33:
23+
The following invocation is known to work on Ubuntu 22.04 and Arch:
3324

3425
``` shell
3526
$ mkdir build
@@ -42,9 +33,7 @@ $ ../configure \
4233
--disable-opengl \
4334
--disable-virglrenderer \
4435
--disable-werror \
45-
--target-list=x86_64-linux-user \
46-
--symcc-source=../symcc \
47-
--symcc-build=../symcc/build
36+
--target-list=x86_64-linux-user
4837
$ make -j
4938
```
5039

@@ -54,6 +43,15 @@ target architectures is possible in principle but will require a bit of work
5443
because the current implementation assumes that we can pass around host pointers
5544
in guest registers.
5645

46+
## SymQEMU compilation options
47+
48+
Several compilation options are available:
49+
- `enable-symcc-shared`: Compile SymQEMU with the shared library of `SymCC
50+
Runtime` instead of a static library.
51+
- `symcc-backend`: Choose a specific backend from `SymCC Runtime`. Please have a
52+
look at [symcc-rt](https://github.com/eurecom-s3/symcc-rt.git) to get an
53+
exhaustive list of available backends.
54+
5755
## Running SymQEMU
5856

5957
If you built SymQEMU as described above, the binary will be in
@@ -84,23 +82,14 @@ This is a very basic use of symbolic execution. See SymCC's documentation for
8482
more advanced scenarios. Since SymQEMU is based on it, it understands all the
8583
same
8684
[settings](https://github.com/eurecom-s3/symcc/blob/master/docs/Configuration.txt),
87-
and you can even run SymQEMU with `symcc_fuzzing_helper` for [hybrid fuzzing](https://github.com/eurecom-s3/symcc/blob/master/docs/Fuzzing.txt): just
85+
and you can even run SymQEMU with `symcc_fuzzing_helper` for [hybrid
86+
fuzzing](https://github.com/eurecom-s3/symcc/blob/master/docs/Fuzzing.txt): just
8887
prefix the target command with `x86_64-linux-user/symqemu-x86_64`. (Note that
8988
you'll have to run AFL in QEMU mode by adding `-Q` to its command line; the
9089
fuzzing helper will automatically pick up the setting and use QEMU mode too.)
9190
9291
## Build with Docker
93-
First, make sure to have an up-to-date Docker image of SymCC. If you
94-
don't have one, either in the submodule, run:
95-
96-
``` shell
97-
git submodule update --init --recursive symcc
98-
cd symcc
99-
docker build -t symcc .
100-
cd ..
101-
```
102-
103-
Then build the SymQEMU image with (this will also run the tests):
92+
Build the SymQEMU image with (this will also run the tests):
10493
```shell
10594
docker build -t symqemu .
10695
```
@@ -146,23 +135,23 @@ Also, refer to [QEMU's own tests suite documentation](https://www.qemu.org/docs/
146135
147136
## Documentation
148137
149-
The [paper](http://www.s3.eurecom.fr/tools/symbolic_execution/symqemu.html) contains
150-
details on how SymQEMU works. A large part of the implementation is the run-time support
151-
in `accel/tcg/tcg-runtime-sym.{c,h}` and `accel/tcg/tcg-runtime-sym-vec.{c,h}` (which
152-
delegates any actual symbolic computation to SymCC's symbolic backend), and we have
153-
modified most code-generating functions in `tcg/tcg-op.c`, `tcg/tcg-op-vec.c` and
138+
The [paper](http://www.s3.eurecom.fr/tools/symbolic_execution/symqemu.html)
139+
contains details on how SymQEMU works. A large part of the implementation is the
140+
run-time support in `accel/tcg/tcg-runtime-sym.{c,h}` and
141+
`accel/tcg/tcg-runtime-sym-vec.{c,h}` (which delegates any actual symbolic
142+
computation to SymCC's symbolic backend), and we have modified most
143+
code-generating functions in `tcg/tcg-op.c`, `tcg/tcg-op-vec.c` and
154144
`include/tcg/tcg-op-common.h` to emit calls to the runtime.
155145
156-
For development, configure with `--enable-debug` for run-time assertions; there are tests
157-
for the symbolic run-time support in `tests/check-sym-runtime.c`.
146+
For development, configure with `--enable-debug` for run-time assertions; there
147+
are tests for the symbolic run-time support in `tests/check-sym-runtime.c`.
158148
159-
More information about the port to QEMU 8 and internals of (Sym)QEMU
160-
can be found in the QEMU 8 merge commit message
161-
[23e570bf42](https://github.com/eurecom-s3/symqemu/commit/23e570bf42531bcac66a54283eafd4c9c233891a) which
162-
gives some information about the adaptations performed. There are also
163-
some detailed explanations about potential problems in section 5.1 of
164-
Damien Maier's [bachelor
165-
thesis](https://dmaier.ch/bachelor-thesis.pdf).
149+
More information about the port to QEMU 8 and internals of (Sym)QEMU can be
150+
found in the QEMU 8 merge commit message
151+
[23e570bf42](https://github.com/eurecom-s3/symqemu/commit/23e570bf42531bcac66a54283eafd4c9c233891a)
152+
which gives some information about the adaptations performed. There are also
153+
some detailed explanations about potential problems in section 5.1 of Damien
154+
Maier's [bachelor thesis](https://dmaier.ch/bachelor-thesis.pdf).
166155
167156
## License
168157

configure

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ default_cflags='-O2 -g'
242242
git_submodules_action="update"
243243
docs="auto"
244244
EXESUF=""
245-
symcc_source=""
246-
symcc_build=""
247245
system="yes"
248246
linux_user=""
249247
bsd_user=""
@@ -696,10 +694,6 @@ for opt do
696694
;;
697695
--static) static="yes"
698696
;;
699-
--symcc-source=*) symcc_source="$optarg"
700-
;;
701-
--symcc-build=*) symcc_build="$optarg"
702-
;;
703697
--host=*|--build=*|\
704698
--disable-dependency-tracking|\
705699
--sbindir=*|--sharedstatedir=*|\
@@ -880,8 +874,6 @@ Advanced options (experts only):
880874
start the emulator (only use if you are including
881875
desired devices in configs/devices/)
882876
--with-devices-ARCH=NAME override default configs/devices
883-
--symcc-source=PATH PATH to SymCC source code
884-
--symcc-build=PATH PATH to the build directory of SymCC with Qsym backend
885877
--enable-debug enable common debug build options
886878
--cpu=CPU Build for host CPU [$cpu]
887879
--disable-containers don't use containers for cross-building
@@ -1678,19 +1670,6 @@ if test "$targetos" = windows; then
16781670
echo "CONFIG_WIN32=y" >> contrib/plugins/$config_host_mak
16791671
fi
16801672

1681-
echo "# SymQEMU config" >> $config_host_mak
1682-
if test -e "$symcc_source/runtime/RuntimeCommon.h"; then
1683-
echo "SYMCC_INC=$symcc_source/runtime" >> $config_host_mak
1684-
else
1685-
error_exit "SymCC (source)" "Point --symcc-source to the SymCC source code"
1686-
fi
1687-
if test -e "$symcc_build/SymRuntime-prefix/src/SymRuntime-build/libSymRuntime.so"; then
1688-
echo "SYMCC_BUILD=$symcc_build/SymRuntime-prefix/src/SymRuntime-build" >> $config_host_mak
1689-
echo "SYMCC_LIBS=$symcc_build/SymRuntime-prefix/src/SymRuntime-build/libSymRuntime.so" >> $config_host_mak
1690-
else
1691-
error_exit "SymCC (runtime)" "Point --symcc-build to the SymCC build directory"
1692-
fi
1693-
16941673
# tests/tcg configuration
16951674
(config_host_mak=tests/tcg/config-host.mak
16961675
mkdir -p tests/tcg

0 commit comments

Comments
 (0)