Repository navigation
Expand file tree
/
Copy pathDockerfile.dev
More file actions
423 lines (387 loc) · 19.9 KB
/
Copy pathDockerfile.dev
File metadata and controls
423 lines (387 loc) · 19.9 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
############################################################
# Dockerfile.dev - Map2Check 2.0 Development Environment
# Based on Ubuntu 22.04 with LLVM 16 + KLEE 3.1
#
# Usage:
# $ docker build -t map2check-dev -f Dockerfile.dev .
# $ docker run -it --rm -v $(pwd):/workspace map2check-dev /bin/bash
#
# Migration Phase 1.1 — Task 1.1.1, 1.1.2, 1.1.3
############################################################
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
# ============================================================
# 1. Base system + build tools (Task 1.1.3)
# ============================================================
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
ninja-build \
git \
wget \
curl \
python3 \
python3-pip \
software-properties-common \
lsb-release \
gnupg \
zlib1g-dev \
libboost-all-dev \
vim \
sudo \
ca-certificates \
subversion \
cppcheck \
&& rm -rf /var/lib/apt/lists/*
# ============================================================
# 2. LLVM 16 via apt.llvm.org (Task 1.1.2)
# ============================================================
RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421 && \
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" > /etc/apt/sources.list.d/llvm-16.list && \
apt-get update && apt-get install -y \
clang-16 \
llvm-16 \
llvm-16-dev \
llvm-16-tools \
libclang-16-dev \
&& rm -rf /var/lib/apt/lists/*
# Symlinks for convenience
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100 && \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 100 && \
update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-16 100 && \
update-alternatives --install /usr/bin/opt opt /usr/bin/opt-16 100 && \
update-alternatives --install /usr/bin/llvm-link llvm-link /usr/bin/llvm-link-16 100
# ============================================================
# 3. Z3 Solver (via apt — version 4.8.12)
# ============================================================
RUN apt-get update && apt-get install -y libz3-dev z3 && \
rm -rf /var/lib/apt/lists/*
# ============================================================
# 4. STP Solver (from source — requires minisat first)
# ============================================================
RUN apt-get update && apt-get install -y \
libboost-program-options-dev \
bison \
flex \
libgmp-dev \
&& rm -rf /var/lib/apt/lists/*
# minisat (STP fork)
RUN git clone --depth 1 https://github.com/stp/minisat.git /tmp/minisat && \
cd /tmp/minisat && mkdir build && cd build && \
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local && \
make -j$(nproc) && make install && \
ldconfig && rm -rf /tmp/minisat
# STP
RUN git clone --depth 1 -b 2.3.4 https://github.com/stp/stp.git /tmp/stp && \
cd /tmp/stp && mkdir build && cd build && \
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON && \
make -j$(nproc) && make install && \
ldconfig && rm -rf /tmp/stp
# ============================================================
# 5. klee-uclibc (built with clang-16)
# ============================================================
RUN git clone --depth 1 https://github.com/klee/klee-uclibc.git /opt/klee-uclibc && \
cd /opt/klee-uclibc && \
./configure --make-llvm-lib \
--with-cc /usr/bin/clang-16 \
--with-llvm-config /usr/bin/llvm-config-16 && \
make -j$(nproc)
# ============================================================
# 6. KLEE 3.1 (with LLVM 16 + Z3 + STP + uclibc)
# ============================================================
RUN apt-get update && apt-get install -y \
libgoogle-perftools-dev \
libsqlite3-dev \
&& rm -rf /var/lib/apt/lists/*
RUN git clone --depth 1 -b v3.1 https://github.com/klee/klee.git /tmp/klee && \
cd /tmp/klee && mkdir build && cd build && \
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
-DENABLE_SOLVER_Z3=ON \
-DENABLE_SOLVER_STP=ON \
-DENABLE_POSIX_RUNTIME=ON \
-DKLEE_UCLIBC_PATH=/opt/klee-uclibc \
-DCMAKE_INSTALL_PREFIX=/opt/klee \
-DENABLE_UNIT_TESTS=OFF \
-DENABLE_SYSTEM_TESTS=OFF && \
make -j$(nproc) && make install && \
rm -rf /tmp/klee
# Add KLEE to PATH
ENV PATH="/opt/klee/bin:${PATH}"
ENV LD_LIBRARY_PATH="/opt/klee/lib"
# ============================================================
# 7. AFL++ 4.40c (LLVM 16, PCGUARD)
# ============================================================
# Tag-pinned like KLEE above: AFL++ has versioned releases, so -b v4.40c is
# the reproducible pin (the SHA pins in 7b/7c are for projects with none).
# PCGUARD is AFL++'s own SanitizerCoveragePCGUARD pass plugin, built against
# the image's LLVM 16 and loaded by afl-clang-fast; it is the default and most
# robust LLVM mode, lighter than the LTO one.
RUN git clone --depth 1 -b v4.40c https://github.com/AFLplusplus/AFLplusplus.git /tmp/afl++ && \
cd /tmp/afl++ && \
make -j"$(nproc)" && \
make install && \
rm -rf /tmp/afl++
ENV PATH="/usr/local/bin:${PATH}"
# afl-cc locates its runtime relative to its own install; AFL_PATH is a safety
# net for the non-LLVM modes.
ENV AFL_PATH=/usr/local/lib/afl
# Headless, container-safe defaults: afl-fuzz aborts under CI/containers on the
# UI, CPU-affinity, cpufreq-governor and core-pattern checks. PCGUARD is the
# instrumentation mode afl-clang-fast must use everywhere.
ENV AFL_NO_UI=1 \
AFL_NO_AFFINITY=1 \
AFL_SKIP_CPUFREQ=1 \
AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 \
AFL_LLVM_INSTRUMENT=PCGUARD
# Fail the image build if AFL++ cannot actually instrument — the same failure
# mode section 7c guards against for sbt-slicer. afl-showmap exits non-zero on
# an uninstrumented binary, and the map is empty, so both checks must pass.
RUN printf 'int main(void){return 0;}\n' > /tmp/aflcheck.c && \
/usr/local/bin/afl-clang-fast -o /tmp/aflcheck /tmp/aflcheck.c && \
/usr/local/bin/afl-showmap -q -o /tmp/aflmap -- /tmp/aflcheck && \
test -s /tmp/aflmap && \
echo "AFL++ instruments: OK" && rm -f /tmp/aflcheck.c /tmp/aflcheck /tmp/aflmap
# ============================================================
# 7b. Clam (formerly crab-llvm) — abstract-interpretation invariants
# ============================================================
# Clam rewrites the bitcode, inserting verifier.assume(inv) calls that
# NonDetPass rewrites to map2check_crab_assume and the runtime forwards to
# klee_assume. Branch dev16 targets LLVM 16, which is this image's LLVM.
#
# Built here rather than as a CMake ExternalProject: it is a subprocess tool,
# not a linked library, and building it per configure would add tens of minutes
# to every clean Map2Check build for a capability that is off by default
# (-DENABLE_CLAM=ON). See docs/reports/2026-08-16-crabllvm-review.md.
#
# libzstd-dev is required, not optional: LLVM 16 from apt.llvm.org exports
# zstd::libzstd_shared, so Clam's find_package(LLVM) fails outright without it.
# libflint-dev is NOT needed -- that belongs to the PPLite domain, and no
# optional domain is enabled here. Clam's default domain is zones (a DBM,
# built into Crab), the same default the crab-llvm of the SV-COMP builds had;
# what LDD, Apron, Elina and PPLite would add is boxes, oct and pk, which the
# old engine shipped (Apron) and --add-invariants never selected. Whether they
# are worth building is part of the pending --add-invariants study
# (docs/backlog.md).
RUN apt-get update && apt-get install -y \
libmpfr-dev \
libzstd-dev \
libcurl4-openssl-dev \
&& rm -rf /var/lib/apt/lists/*
# CLAM_INCLUDE_TESTS=OFF: Clam's own lit suite needs `lit` from pip and adds
# build time for tests of a dependency, not of Map2Check.
#
# The compilers are named explicitly rather than left to the ENV CC/CXX set in
# section 11: those are declared 88 lines BELOW this RUN, and a Docker ENV only
# applies to later instructions, so Clam would silently build with the default
# cc/c++ (GCC 11). That is not a cosmetic difference -- sea-dsa defines
# seadsa::mkTLIGetter with a redundant namespace qualification inside its own
# namespace, which clang accepts as -Wextra-qualification but GCC rejects
# outright, and the image build dies at 34%. Upstream's own docker/clam.Dockerfile
# passes these same two flags; clang is the toolchain Clam is built against.
#
# Every one of these four repositories is tracked upstream on a MOVING branch:
# clam, sea-dsa and llvm-seahorn on dev16, Crab on dev. Left unpinned, the
# contents of this image change without any change on our side -- crab@dev
# moved on 2026-08-21, while this section was being written. Pinning makes the
# image reproducible and turns an upstream break into a deliberate bump with a
# diff, instead of a red build nobody caused.
#
# To bump one: replace the SHA, and let the pull_request job in
# .github/workflows/docker-publish.yml prove the new combination still
# compiles and still injects invariants before it reaches develop.
ARG CLAM_SHA=302bf49a8847697f8f16e2c2548ccbc14c226640 # dev16 @ 2026-08-07
ARG SEADSA_SHA=661855a334c8fda45f45ae74d4e21bbd4e838835 # dev16 @ 2026-08-12
ARG LLVM_SEAHORN_SHA=8e7e6c62c9f23718973ef9f60d30a593d044287c # dev16 @ 2026-07-04
ARG CRAB_SHA=5c740fcc9afcc951844d35e20592af81d8d94604 # dev @ 2026-08-21
# The dependencies are placed by hand instead of via Clam's `crab` and `extra`
# targets. Those targets are plain `git clone -b dev<N>` custom commands
# (cmake/{crab,seadsa,llvm-seahorn}-git.cmake) with nowhere to pass a SHA, so
# pinning means not using them. Clam's CMakeLists already prefers a dependency
# that is present in-tree over cloning one, which is what makes this work --
# and because everything is in place before the first configure, the
# configure/clone/reconfigure dance the targets required collapses to a single
# `cmake ..`.
#
# `git init` + `fetch --depth 1 <sha>` rather than `clone -b <branch>`: it is
# the only shallow form that takes a commit, so pinning costs no extra history.
RUN set -eux; \
pin() { \
git init -q "$2" && \
git -C "$2" remote add origin "$1" && \
git -C "$2" fetch -q --depth 1 origin "$3" && \
git -C "$2" checkout -q FETCH_HEAD; \
}; \
pin https://github.com/seahorn/clam.git /tmp/clam "$CLAM_SHA"; \
pin https://github.com/seahorn/sea-dsa.git /tmp/clam/sea-dsa "$SEADSA_SHA"; \
pin https://github.com/seahorn/llvm-seahorn.git /tmp/clam/llvm-seahorn "$LLVM_SEAHORN_SHA"; \
pin https://github.com/seahorn/crab.git /tmp/clam/crab "$CRAB_SHA"; \
mkdir /tmp/clam/build && cd /tmp/clam/build && \
cmake .. -DCMAKE_BUILD_TYPE=Release -DCLAM_LLVM_VERSION=16 \
-DCLAM_INCLUDE_TESTS=OFF \
-DCMAKE_C_COMPILER=/usr/bin/clang-16 \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-16 \
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
-DCMAKE_INSTALL_PREFIX=/opt/clam && \
cmake --build . -j"$(nproc)" && \
cmake --build . --target install && \
rm -rf /tmp/clam
ENV CLAM_DIR=/opt/clam
# Fail the image build if Clam cannot inject invariants. The flag combination
# below is measured, not assumed: --llvm-pp-loops and --crab-promote-assume
# were both in the legacy crab-llvm invocation and both defeat injection (the
# first drops it to zero, the second rewrites verifier.assume into the
# llvm.assume intrinsic that NonDetPass does not match). A silent zero here is
# what kept --add-invariants dead for years.
RUN printf 'int main(){int i=0,s=0;while(i<10){s+=i;i++;}return s;}\n' > /tmp/clamcheck.c && \
/opt/clam/bin/clam.py -o /tmp/clamcheck.bc -m 64 -g --crab-inter \
--crab-track=num --crab-opt=add-invariants \
--crab-opt-invariants-loc=block-entry /tmp/clamcheck.c && \
test "$(llvm-dis-16 -o - /tmp/clamcheck.bc | grep -c 'verifier\.assume')" -gt 0 && \
echo "Clam injects invariants: OK" && rm -f /tmp/clamcheck.c /tmp/clamcheck.bc
# ============================================================
# 7c. DG + sbt-slicer — program slicing with respect to an error site
# ============================================================
# Phase 2 of docs/map2check_migration_plan.md, and the same pipeline Symbiotic
# uses: build a System Dependence Graph, keep only what the error site depends
# on, hand the smaller program to KLEE.
#
# What it is for, in numbers from this repository: finding K2 measured the cost
# of a nondeterministic read at 1 -> 21 -> 114 -> 861 partial paths for 2 -> 4
# reads. Most of that forking happens in code that cannot influence the target,
# and slicing removes it before KLEE ever sees it.
#
# Two limits worth knowing before relying on it. Slicing needs a criterion, so
# it serves Cover-Error and does nothing for Cover-Branches, where every branch
# matters and there is no error site to slice towards. And a slice taken with
# respect to one error can remove another -- fine for a tool answering one
# property, a hazard for a baseline that scores precision per CWE.
#
# Built with clang-16 for the reason section 7b spells out: the ENV CC below is
# declared later in this file and would not apply here, and these are LLVM
# projects that expect the LLVM toolchain.
#
# DG is taken from llvm-latest, NOT master, and the difference is the same one
# crab-llvm taught: the maintained version was somewhere else. master calls
# llvm::Function::getBasicBlockList(), which LLVM 16 made private, so it simply
# does not compile here. llvm-latest's newest commit is literally "Fix build
# for LLVM < 18".
#
# Pinned to SHAs. Neither project has had a versioned release since 2020, so
# without a pin the image changes when upstream does -- what crab@dev
# demonstrated by moving the day before it was needed.
ARG DG_SHA=b34da890694f5210e475f34018239fc9d126d1ee # llvm-latest @ 2023-11-29
ARG SBT_SLICER_SHA=e350116b39be215277803fe2f5e5ac4a161c16b8 # master @ 2025-03-27
RUN set -eux; \
pin() { \
git init -q "$2" && \
git -C "$2" remote add origin "$1" && \
git -C "$2" fetch -q --depth 1 origin "$3" && \
git -C "$2" checkout -q FETCH_HEAD; \
}; \
# Both projects pin C++14 with a plain set(), which overrides anything
# passed on the command line, and LLVM 16's headers use std::is_unsigned_v
# -- C++17. Patching the two lines is the smallest change that builds; the
# alternative is carrying a fork.
bump() { \
sed -i 's/set(CMAKE_CXX_STANDARD 14)/set(CMAKE_CXX_STANDARD 17)/; \
s/-std=c++14/-std=c++17/' "$1/CMakeLists.txt"; \
}; \
pin https://github.com/mchalupa/dg.git /tmp/dg "$DG_SHA"; \
bump /tmp/dg; \
# IN-SOURCE, deliberately. sbt-slicer's CMakeLists documents DG_PATH as
# "a path to an in-source build of dg" and derives both the include path
# and the library path from it; an out-of-tree build satisfies neither
# (the headers stay in the source tree, the libraries land in the build
# tree) and sbt-slicer fails to find dg/tools/llvm-slicer-opts.h.
cd /tmp/dg && \
cmake . -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=/usr/bin/clang-16 \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-16 \
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
-DCMAKE_INSTALL_PREFIX=/opt/dg && \
make -j"$(nproc)" && make install && \
pin https://github.com/staticafi/sbt-slicer.git /tmp/sbt-slicer \
"$SBT_SLICER_SHA"; \
bump /tmp/sbt-slicer; \
mkdir /tmp/sbt-slicer/build && cd /tmp/sbt-slicer/build && \
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=/usr/bin/clang-16 \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-16 \
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
-DDG_PATH=/tmp/dg \
-DCMAKE_INSTALL_PREFIX=/opt/sbt-slicer && \
make -j"$(nproc)" && make install && \
rm -rf /tmp/dg /tmp/sbt-slicer
ENV SBT_SLICER=/opt/sbt-slicer/bin/sbt-slicer
# dg installs shared libraries, and sbt-slicer links against them without an
# rpath: without this the binary exists, builds, and dies on every invocation
# with "libdganalysis.so: cannot open shared object file".
ENV LD_LIBRARY_PATH="/opt/dg/lib:${LD_LIBRARY_PATH}"
# Fail the image build if the slicer cannot actually slice. A binary that
# exists and refuses every input is the failure mode section 7b was written
# about: --add-invariants stayed dead for years behind exactly that.
RUN printf 'extern int __VERIFIER_nondet_int(void);\nvoid reach_error(void);\nint main(){int a=__VERIFIER_nondet_int();int junk=__VERIFIER_nondet_int();int s=0;for(int i=0;i<50;i++){s+=junk*i;}if(a==7){reach_error();}return s;}\n' > /tmp/slicecheck.c && \
clang-16 -c -emit-llvm -g -O0 -o /tmp/slicecheck.bc /tmp/slicecheck.c && \
/opt/sbt-slicer/bin/sbt-slicer -c reach_error -o /tmp/sliced.bc /tmp/slicecheck.bc && \
test -s /tmp/sliced.bc && \
echo "sbt-slicer slices: OK" && rm -f /tmp/slicecheck.c /tmp/slicecheck.bc /tmp/sliced.bc
# ============================================================
# 8. WABT (WebAssembly Binary Toolkit) — wasm2c, wasm2wat, wasm-ld
# ============================================================
# Using latest stable release (1.0.41) instead of apt (1.0.27)
# to support bulk memory operations and reference types
RUN apt-get update && apt-get install -y lld-16 libc6-dev linux-libc-dev && \
rm -rf /var/lib/apt/lists/*
# Download WABT 1.0.41 from GitHub releases
RUN wget -q "https://github.com/WebAssembly/wabt/releases/download/1.0.41/wabt-1.0.41-linux-x64.tar.gz" -O /tmp/wabt.tar.gz && \
tar xzf /tmp/wabt.tar.gz -C /opt && \
rm /tmp/wabt.tar.gz && \
ln -sf /opt/wabt-1.0.41/bin/wasm2c /usr/local/bin/wasm2c && \
ln -sf /opt/wabt-1.0.41/bin/wasm2wat /usr/local/bin/wasm2wat && \
ln -sf /opt/wabt-1.0.41/bin/wat2wasm /usr/local/bin/wat2wasm && \
ln -sf /opt/wabt-1.0.41/bin/wasm-objdump /usr/local/bin/wasm-objdump && \
ln -sf /opt/wabt-1.0.41/bin/wasm-interp /usr/local/bin/wasm-interp
# Symlink wasm-ld from lld-16
RUN update-alternatives --install /usr/bin/wasm-ld wasm-ld /usr/bin/wasm-ld-16 100
# Verify WABT installation
RUN wasm2c --version && wasm2wat --version && wasm-ld --version
# ============================================================
# 9. WASI SDK (C/C++ toolchain for WebAssembly)
# ============================================================
# Using latest stable release (33.0) for full WASM feature support
RUN wget -q "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-x86_64-linux.tar.gz" -O /tmp/wasi-sdk.tar.gz && \
tar xzf /tmp/wasi-sdk.tar.gz -C /opt && \
rm /tmp/wasi-sdk.tar.gz
# Add WASI SDK to PATH
# Note: wasi-sdk-33.0 extracts to wasi-sdk-33.0-x86_64-linux/
ENV WASI_SDK_PATH=/opt/wasi-sdk-33.0-x86_64-linux
ENV PATH="${WASI_SDK_PATH}/bin:${PATH}"
# Verify WASI SDK
RUN ${WASI_SDK_PATH}/bin/clang --version && \
${WASI_SDK_PATH}/bin/wasm-ld --version
# ============================================================
# 10. User setup
# ============================================================
RUN useradd -m map2check && \
echo "map2check:map2check" | chpasswd && \
echo "map2check ALL=(root) NOPASSWD: ALL" >> /etc/sudoers
USER map2check
WORKDIR /workspace
# Git config
RUN git config --global user.email "map2check.tool@gmail.com" && \
git config --global user.name "Map2Check" && \
git config --global --add safe.directory /workspace
# ============================================================
# 11. Environment variables for Map2Check build
# ============================================================
ENV LLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm
ENV CC=/usr/bin/clang-16
ENV CXX=/usr/bin/clang++-16
ENV KLEE_DIR=/opt/klee
ENV WASI_SDK_PATH=/opt/wasi-sdk-33.0-x86_64-linux
CMD ["/bin/bash"]