Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SymQEMU tests and Dockefile #39

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fa1089f
add util function for vec expr
damienmaier Nov 29, 2023
65592a8
instrument tcg_gen_mov_vec
damienmaier Nov 29, 2023
9eec6e4
instumented tcg_gen_ld_vec
damienmaier Nov 29, 2023
63d0b6b
add tcgv_vec_expr util function
damienmaier Nov 29, 2023
6fb428a
simplify sym_store_host helper
damienmaier Nov 29, 2023
1d0aa71
instrumented tcg_gen_st_vec
damienmaier Nov 29, 2023
9752b46
instrument tcg_gen_stl_vec
damienmaier Nov 29, 2023
83fbd7c
add malloc and free helper functions
damienmaier Nov 30, 2023
d2fe1d1
util functions for vector intrumentation
damienmaier Nov 30, 2023
da5127d
instrumented tcg_gen_and_vec
damienmaier Nov 30, 2023
7927d40
implemented sym helper for and vec
damienmaier Nov 30, 2023
d5d9af3
generalized sym_and_vec implementation
damienmaier Dec 1, 2023
bc93cce
refactor
damienmaier Dec 1, 2023
34c8485
refactor
damienmaier Dec 1, 2023
f41cfa6
fix free temp
damienmaier Dec 1, 2023
b6b5add
instrumented vec or,xor,add,sub,mul
damienmaier Dec 1, 2023
cbd03ea
typo
damienmaier Dec 1, 2023
9f08fb8
make vector operations andc,orc,nand,nor,eqv be built with instrument…
damienmaier Dec 2, 2023
848e568
make vector operations not and neg be built with instrumented operations
damienmaier Dec 2, 2023
d906a0e
make vector operations abs be built with instrumented operations
damienmaier Dec 2, 2023
e9cdce2
refactor
damienmaier Dec 2, 2023
b5a60b3
refactor
damienmaier Dec 2, 2023
8fc5505
add build_symbol_for_vector_int32_op function
damienmaier Dec 2, 2023
fbde819
instrumented vec vec shifts and rotates ops
damienmaier Dec 2, 2023
17171ca
instrumented vec i32 shifts and rotates ops
damienmaier Dec 2, 2023
46d7b39
instrumented vec immediate shifts and rotates ops
damienmaier Dec 2, 2023
ccfd8c1
refactor
damienmaier Dec 3, 2023
c8c6b3b
add support of helper functions with 8 and 9 args
damienmaier Dec 3, 2023
45204fa
instrumented tcg_gen_cmp_vec
damienmaier Dec 3, 2023
b287728
concretize not yet instrumented vec ops results to avoid crash
damienmaier Dec 3, 2023
01a2d0e
fix bux related to expr version of constants and add assert to avoid …
damienmaier Dec 3, 2023
3b838fc
fix vector load bug
damienmaier Dec 3, 2023
826b74b
fix split_symbol function, add asserts
damienmaier Dec 3, 2023
9902878
fix extract symbol logic
damienmaier Dec 4, 2023
c4381e7
fix endianess issue in apply_op_and_merge function
damienmaier Dec 5, 2023
c369e5a
instrumented saturating signed/unsigned sub/add vec instructions
damienmaier Dec 5, 2023
c212307
make sure cmpsel and bitsel instructions are generated using already …
damienmaier Dec 5, 2023
17142e2
remove forgotten concretization
damienmaier Dec 5, 2023
7c4b7be
instrumented tcg_gen_dup_i64_vec,tcg_gen_dup_i32_vec functions
damienmaier Dec 5, 2023
f83bda8
instrumented min max functions
damienmaier Dec 5, 2023
679ed4e
instrumented tcg_gen_dup_mem_vec
damienmaier Dec 5, 2023
4949502
fix wront assert in sym_load_and_duplicate_into_vec
damienmaier Dec 6, 2023
bdb5a3e
refactor : put vec helpers in separate file
damienmaier Dec 16, 2023
a5f4144
documentation and refactoring
damienmaier Dec 17, 2023
b44e1fa
refactor
damienmaier Jan 10, 2024
88e18a3
fix rotate functions for PR
damienmaier Feb 4, 2024
ec3c4c1
added todo comments to clarify situation for indirectly instrumented …
damienmaier Feb 11, 2024
ccab95f
add todo for returning expressions instad of pushing path constraints
damienmaier Feb 11, 2024
3b961e7
mention files related to vec instructions in README
damienmaier Feb 11, 2024
066b926
add testing script and simple test binary
damienmaier Feb 11, 2024
fe7ee6f
add symcc as submodule
damienmaier Feb 11, 2024
90510eb
do not include existing build artifacts in docker image
damienmaier Feb 6, 2024
0e4cc23
added Dockerfile for building and running e2e tests
damienmaier Feb 11, 2024
cae00b6
use debug build in Dockerfile
damienmaier Feb 11, 2024
f5ce706
make SymQEMU Dockerfile rely on SymCC Dockerfile
damienmaier Feb 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@
[submodule "tests/lcitool/libvirt-ci"]
path = tests/lcitool/libvirt-ci
url = https://gitlab.com/libvirt/libvirt-ci.git
[submodule "symcc"]
path = symcc
url = https://github.com/eurecom-s3/symcc.git
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM symcc AS symcc

FROM ubuntu:22.04

RUN apt update
RUN apt install -y \
ninja-build \
libglib2.0-dev \
llvm \
python3 \
python3-pip

COPY . /symqemu_source
WORKDIR /symqemu_source

# Meson gives an error if symcc is in a subdirectory of symqemu
RUN mv /symqemu_source/symcc /symcc

# The only symcc artifact needed by symqemu is libSymRuntime.so
# Instead of compiling symcc in this image, we rely on the existing symcc docker image and
# we just copy libSymbolize.so at the location where symqemu expects it
COPY --from=symcc /symcc_build/SymRuntime-prefix/src/SymRuntime-build/libSymRuntime.so /symcc/build/SymRuntime-prefix/src/SymRuntime-build/libSymRuntime.so

RUN ./configure \
--audio-drv-list= \
--disable-sdl \
--disable-gtk \
--disable-vte \
--disable-opengl \
--disable-virglrenderer \
--disable-werror \
--target-list=x86_64-linux-user \
--enable-debug \
--symcc-source=/symcc \
--symcc-build=/symcc/build

RUN make -j

WORKDIR /symqemu_source/tests/symqemu
RUN python3 -m unittest test.py
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ fuzzing helper will automatically pick up the setting and use QEMU mode too.)

## Documentation

The [paper](http://www.s3.eurecom.fr/tools/symbolic_execution/symqemu.html)
contains details on how SymQEMU works. A large part of the implementation is the
run-time support in `accel/tcg/tcg-runtime-sym.{c,h}` (which delegates any
actual symbolic computation to SymCC's symbolic backend), and we have modified
most code-generating functions in `tcg/tcg-op.c` to emit calls to the runtime.
For development, configure with `--enable-debug` for run-time assertions; there
are tests for the symbolic run-time support in `tests/check-sym-runtime.c`.
The [paper](http://www.s3.eurecom.fr/tools/symbolic_execution/symqemu.html) contains
details on how SymQEMU works. A large part of the implementation is the run-time support
in `accel/tcg/tcg-runtime-sym.{c,h}` and `accel/tcg/tcg-runtime-sym-vec.{c,h}` (which
delegates any actual symbolic computation to SymCC's symbolic backend), and we have
modified most code-generating functions in `tcg/tcg-op.c`, `tcg/tcg-op-vec.c` and
`include/tcg/tcg-op-common.h` to emit calls to the runtime.

For development, configure with `--enable-debug` for run-time assertions; there are tests
for the symbolic run-time support in `tests/check-sym-runtime.c`.

More information about the port to QEMU 8 and internals of (Sym)QEMU
can be found in the QEMU 8 merge commit message
Expand Down
2 changes: 2 additions & 0 deletions accel/tcg/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ tcg_ss.add(files(
'tcg-runtime-gvec.c',
'tcg-runtime.c',
'tcg-runtime-sym.c',
'tcg-runtime-sym-vec.c',
'tcg-runtime-sym-common.c',
'translate-all.c',
'translator.c',
))
Expand Down
95 changes: 95 additions & 0 deletions accel/tcg/tcg-runtime-sym-common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "exec/helper-proto.h"
#include "exec/cpu_ldst.h"
#include "qemu/qemu-print.h"
#include "tcg/tcg.h"
#include "exec/translation-block.h"

#include "accel/tcg/tcg-runtime-sym-common.h"

/* Include the symbolic backend, using void* as expression type. */

#define SymExpr void*
#include "RuntimeCommon.h"

void *build_and_push_path_constraint(CPUArchState *env, void *arg1_expr, void *arg2_expr, uint32_t comparison_operator, uint8_t is_taken){
void *(*handler)(void *, void*);
switch (comparison_operator) {
case TCG_COND_EQ:
handler = _sym_build_equal;
break;
case TCG_COND_NE:
handler = _sym_build_not_equal;
break;
case TCG_COND_LT:
handler = _sym_build_signed_less_than;
break;
case TCG_COND_GE:
handler = _sym_build_signed_greater_equal;
break;
case TCG_COND_LE:
handler = _sym_build_signed_less_equal;
break;
case TCG_COND_GT:
handler = _sym_build_signed_greater_than;
break;
case TCG_COND_LTU:
handler = _sym_build_unsigned_less_than;
break;
case TCG_COND_GEU:
handler = _sym_build_unsigned_greater_equal;
break;
case TCG_COND_LEU:
handler = _sym_build_unsigned_less_equal;
break;
case TCG_COND_GTU:
handler = _sym_build_unsigned_greater_than;
break;
default:
g_assert_not_reached();
}

void *condition_symbol = handler(arg1_expr, arg2_expr);
_sym_push_path_constraint(condition_symbol, is_taken, get_pc(env));

return condition_symbol;
}

/* Architecture-independent way to get the program counter */
target_ulong get_pc(CPUArchState *env)
{
target_ulong pc, cs_base;
uint32_t flags;

cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);

return pc;
}

void *sym_rotate_left(void *arg1_expr, void *arg2_expr) {
/* The implementation follows the alternative implementation of
* tcg_gen_rotl_i64 in tcg-op.c (which handles architectures that don't
* support rotl directly). */

uint8_t bits = _sym_bits_helper(arg1_expr);
return _sym_build_or(
_sym_build_shift_left(arg1_expr, arg2_expr),
_sym_build_logical_shift_right(
arg1_expr,
_sym_build_sub(_sym_build_integer(bits, bits), arg2_expr)));
}

void *sym_rotate_right(void *arg1_expr, void *arg2_expr) {

/* The implementation follows the alternative implementation of
* tcg_gen_rotr_i64 in tcg-op.c (which handles architectures that don't
* support rotr directly). */

uint8_t bits = _sym_bits_helper(arg1_expr);
return _sym_build_or(
_sym_build_logical_shift_right(arg1_expr, arg2_expr),
_sym_build_shift_left(
arg1_expr,
_sym_build_sub(_sym_build_integer(bits, bits), arg2_expr)));
}
4 changes: 4 additions & 0 deletions accel/tcg/tcg-runtime-sym-common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void *build_and_push_path_constraint(CPUArchState *env, void *arg1_expr, void *arg2_expr, uint32_t comparison_operator, uint8_t is_taken);
target_ulong get_pc(CPUArchState *env);
void *sym_rotate_left(void *arg1_expr, void *arg2_expr);
void *sym_rotate_right(void *arg1_expr, void *arg2_expr);
Loading
Loading