-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
122 lines (97 loc) · 3.44 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# ========================================
# base
# ========================================
FROM ubuntu:14.04 as klee-coreutils-base
# installing dependencies
RUN apt-get update \
&& apt-get install -y \
wget \
build-essential
# downloading source code
RUN wget "http://ftp.gnu.org/gnu/coreutils/coreutils-6.10.tar.gz" \
&& tar xf "coreutils-6.10.tar.gz" \
&& mv "coreutils-6.10" coreutils
# modifying source code according to the documentation of the original experiment
RUN sed -i \
's/^#define INPUT_FILE_SIZE_GUESS (1024 \* 1024)$/#define INPUT_FILE_SIZE_GUESS 1024/g' \
coreutils/src/sort.c
# ========================================
# llvm
# ========================================
FROM klee-coreutils-base as klee-coreutils-llvm
# installing dependencies
RUN apt-get install -y \
clang \
llvm \
python3-pip
# Newer versions are no longer compatible with the latest python version available on Ubuntu 14.04
RUN pip3 install --upgrade -v "wllvm==1.1.5"
ENV LLVM_COMPILER clang
ENV CC wllvm
# compiling code to llvm bytecode (.bc)
WORKDIR /coreutils/obj-llvm
RUN ../configure \
--build x86_64-pc-linux-gnu \
--disable-nls \
LLVM_COMPILER=clang \
CC=wllvm \
CFLAGS="-O0 -D__NO_STRING_INLINES -D_FORTIFY_SOURCE=0 -U__OPTIMIZE__" \
&& make \
&& make -C src arch hostname
# extracting llvm bytecode from object files
WORKDIR /coreutils/obj-llvm/src
RUN find . -executable -type f | xargs -I '{}' extract-bc '{}'
# ========================================
# gcov
# ========================================
FROM klee-coreutils-base as klee-coreutils-gcov
# compiling code to binaries instrumented with gcov
WORKDIR /coreutils/obj-cov
RUN ../configure \
--build x86_64-pc-linux-gnu \
--disable-nls \
CFLAGS="-O2 -g -fprofile-arcs -ftest-coverage" \
&& find .. -type f -name '*.c' -exec sed -i -E 's/\b_exit\(/exit(/g' {} + \
&& make \
&& make -C src arch hostname
ENV COVERAGE_DATA_DIR /out/cov/src
ENV UTIL echo
WORKDIR /coreutils/obj-cov/src
CMD echo "Starting coverage gathering" \
&& echo "Copying coverage files" \
&& cp -r "$COVERAGE_DATA_DIR"/* "/coreutils/obj-cov/src/" \
&& echo "Running gcov" \
&& gcov "$UTIL" > "/out/cov.txt" \
&& echo "Coverage gathering done"
# ========================================
# exec
# ========================================
FROM klee/klee AS klee-coreutils-exec
# setting up klee env
RUN wget "http://www.doc.ic.ac.uk/~cristic/klee/testing-env.sh" \
&& env -i /bin/bash -c '(source testing-env.sh; env >test.env)' \
&& wget "http://www.doc.ic.ac.uk/~cristic/klee/sandbox.tgz" \
&& tar xzfv sandbox.tgz \
&& mv sandbox.tgz /tmp \
&& mv sandbox /tmp
# copying files from build stage
COPY --from=klee-coreutils-llvm --chown=klee /coreutils/ ./coreutils-llvm/
COPY --from=klee-coreutils-gcov --chown=klee /coreutils/ ./coreutils-gcov/
# copying run scripts
COPY analyze.sh ./
# setting default values for analyze script
# can be overridden using -e in docker run
ENV KLEE_MAX_TIME_MIN 60
ENV UTIL echo
ENV SKIP_KLEE_ANALYSIS ""
CMD bash ./analyze.sh \
--llvm-dir ./coreutils-llvm/obj-llvm/src \
--cov-dir ./coreutils-gcov/obj-cov/src \
--skip-klee-analysis "${SKIP_KLEE_ANALYSIS}" \
--klee-max-time "${KLEE_MAX_TIME_MIN}" \
--out-dir ./out \
"${UTIL}"
# to keep files output by klee, run the container as follows:
# `docker run [docker_args] \
# -v <path/on/your/system>:/home/klee/out \
# <image-name>`