| 1 |
# -*- mode: makefile -*- |
| 2 |
# The first line sets the emacs major mode to Makefile |
| 3 |
|
| 4 |
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 |
# SPDX-License-Identifier: MIT-0 |
| 6 |
|
| 7 |
CBMC_STARTER_KIT_VERSION = CBMC starter kit 2.11 |
| 8 |
|
| 9 |
################################################################ |
| 10 |
# The CBMC Starter Kit depends on the files Makefile.common and |
| 11 |
# run-cbmc-proofs.py. They are installed by the setup script |
| 12 |
# cbmc-starter-kit-setup and updated to the latest version by the |
| 13 |
# update script cbmc-starter-kit-update. For more information about |
| 14 |
# the starter kit and these files and these scripts, see |
| 15 |
# https://model-checking.github.io/cbmc-starter-kit |
| 16 |
# |
| 17 |
# Makefile.common implements what we consider to be some best |
| 18 |
# practices for using cbmc for software verification. |
| 19 |
# |
| 20 |
# Section I gives default values for a large number of Makefile |
| 21 |
# variables that control |
| 22 |
# * how your code is built (include paths, etc), |
| 23 |
# * what program transformations are applied to your code (loop |
| 24 |
# unwinding, etc), and |
| 25 |
# * what properties cbmc checks for in your code (memory safety, etc). |
| 26 |
# |
| 27 |
# These variables are defined below with definitions of the form |
| 28 |
# VARIABLE ?= DEFAULT_VALUE |
| 29 |
# meaning VARIABLE is set to DEFAULT_VALUE if VARIABLE has not already |
| 30 |
# been given a value. |
| 31 |
# |
| 32 |
# For your project, you can override these default values with |
| 33 |
# project-specific definitions in Makefile-project-defines. |
| 34 |
# |
| 35 |
# For any individual proof, you can override these default values and |
| 36 |
# project-specific values with proof-specific definitions in the |
| 37 |
# Makefile for your proof. |
| 38 |
# |
| 39 |
# The definitions in the proof Makefile override definitions in the |
| 40 |
# project Makefile-project-defines which override definitions in this |
| 41 |
# Makefile.common. |
| 42 |
# |
| 43 |
# Section II uses the values defined in Section I to build your code, run |
| 44 |
# your proof, and build a report of your results. You should not need |
| 45 |
# to modify or override anything in Section II, but you may want to |
| 46 |
# read it to understand how the values defined in Section I control |
| 47 |
# things. |
| 48 |
# |
| 49 |
# To use Makefile.common, set variables as described above as needed, |
| 50 |
# and then for each proof, |
| 51 |
# |
| 52 |
# * Create a subdirectory <DIR>. |
| 53 |
# * Write a proof harness (a function) with the name <HARNESS_ENTRY> |
| 54 |
# in a file with the name <DIR>/<HARNESS_FILE>.c |
| 55 |
# * Write a makefile with the name <DIR>/Makefile that looks |
| 56 |
# something like |
| 57 |
# |
| 58 |
# HARNESS_FILE=<HARNESS_FILE> |
| 59 |
# HARNESS_ENTRY=<HARNESS_ENTRY> |
| 60 |
# PROOF_UID=<PROOF_UID> |
| 61 |
# |
| 62 |
# PROJECT_SOURCES += $(SRCDIR)/libraries/api_1.c |
| 63 |
# PROJECT_SOURCES += $(SRCDIR)/libraries/api_2.c |
| 64 |
# |
| 65 |
# PROOF_SOURCES += $(PROOFDIR)/harness.c |
| 66 |
# PROOF_SOURCES += $(SRCDIR)/cbmc/proofs/stub_a.c |
| 67 |
# PROOF_SOURCES += $(SRCDIR)/cbmc/proofs/stub_b.c |
| 68 |
# |
| 69 |
# UNWINDSET += foo.0:3 |
| 70 |
# UNWINDSET += bar.1:6 |
| 71 |
# |
| 72 |
# REMOVE_FUNCTION_BODY += api_stub_a |
| 73 |
# REMOVE_FUNCTION_BODY += api_stub_b |
| 74 |
# |
| 75 |
# DEFINES = -DDEBUG=0 |
| 76 |
# |
| 77 |
# include ../Makefile.common |
| 78 |
# |
| 79 |
# * Change directory to <DIR> and run make |
| 80 |
# |
| 81 |
# The proof setup script cbmc-starter-kit-setup-proof from the CBMC |
| 82 |
# Starter Kit will do most of this for, creating a directory and |
| 83 |
# writing a basic Makefile and proof harness into it that you can edit |
| 84 |
# as described above. |
| 85 |
# |
| 86 |
# Warning: If you get results that are hard to explain, consider |
| 87 |
# running "make clean" or "make veryclean" before "make" if you get |
| 88 |
# results that are hard to explain. Dependency handling in this |
| 89 |
# Makefile.common may not be perfect. |
| 90 |
|
| 91 |
SHELL=/bin/bash |
| 92 |
|
| 93 |
default: report |
| 94 |
|
| 95 |
################################################################ |
| 96 |
################################################################ |
| 97 |
## Section I: This section gives common variable definitions. |
| 98 |
## |
| 99 |
## Override these definitions in Makefile-project-defines or |
| 100 |
## your proof Makefile. |
| 101 |
## |
| 102 |
## Remember that Makefile.common and Makefile-project-defines are |
| 103 |
## included into the proof Makefile in your proof directory, so all |
| 104 |
## relative pathnames defined there should be relative to your proof |
| 105 |
## directory. |
| 106 |
|
| 107 |
################################################################ |
| 108 |
# Define the layout of the source tree and the proof subtree |
| 109 |
# |
| 110 |
# Generally speaking, |
| 111 |
# |
| 112 |
# SRCDIR = the root of the repository |
| 113 |
# CBMC_ROOT = /srcdir/cbmc |
| 114 |
# PROOF_ROOT = /srcdir/cbmc/proofs |
| 115 |
# PROOF_SOURCE = /srcdir/cbmc/sources |
| 116 |
# PROOF_INCLUDE = /srcdir/cbmc/include |
| 117 |
# PROOF_STUB = /srcdir/cbmc/stubs |
| 118 |
# PROOFDIR = the directory containing the Makefile for your proof |
| 119 |
# |
| 120 |
# The path /srcdir/cbmc used in the example above is determined by the |
| 121 |
# setup script cbmc-starter-kit-setup. Projects usually create a cbmc |
| 122 |
# directory somewhere in the source tree, and run the setup script in |
| 123 |
# that directory. The value of CBMC_ROOT becomes the absolute path to |
| 124 |
# that directory. |
| 125 |
# |
| 126 |
# The location of that cbmc directory in the source tree affects the |
| 127 |
# definition of SRCDIR, which is defined in terms of the relative path |
| 128 |
# from a proof directory to the repository root. The definition is |
| 129 |
# usually determined by the setup script cbmc-starter-kit-setup and |
| 130 |
# written to Makefile-template-defines, but you can override it for a |
| 131 |
# project in Makefile-project-defines and for a specific proof in the |
| 132 |
# Makefile for the proof. |
| 133 |
|
| 134 |
# Absolute path to the directory containing this Makefile.common |
| 135 |
# See https://ftp.gnu.org/old-gnu/Manuals/make-3.80/html_node/make_17.html |
| 136 |
# |
| 137 |
# Note: We compute the absolute paths to the makefiles in MAKEFILE_LIST |
| 138 |
# before we filter the list of makefiles for %/Makefile.common. |
| 139 |
# Otherwise an invocation of the form "make -f Makefile.common" will set |
| 140 |
# MAKEFILE_LIST to "Makefile.common" which will fail to match the |
| 141 |
# pattern %/Makefile.common. |
| 142 |
# |
| 143 |
MAKEFILE_PATHS = $(foreach makefile,$(MAKEFILE_LIST),$(abspath $(makefile))) |
| 144 |
PROOF_ROOT = $(dir $(filter %/Makefile.common,$(MAKEFILE_PATHS))) |
| 145 |
|
| 146 |
CBMC_ROOT = $(shell dirname $(PROOF_ROOT)) |
| 147 |
PROOF_SOURCE = $(CBMC_ROOT)/sources |
| 148 |
PROOF_INCLUDE = $(CBMC_ROOT)/include |
| 149 |
PROOF_STUB = $(CBMC_ROOT)/stubs |
| 150 |
|
| 151 |
# Project-specific definitions to override default definitions below |
| 152 |
# * Makefile-project-defines will never be overwritten |
| 153 |
# * Makefile-template-defines may be overwritten when the starter |
| 154 |
# kit is updated |
| 155 |
sinclude $(PROOF_ROOT)/Makefile-project-defines |
| 156 |
sinclude $(PROOF_ROOT)/Makefile-template-defines |
| 157 |
|
| 158 |
# SRCDIR is the path to the root of the source tree |
| 159 |
# This is a default definition that is frequently overridden in |
| 160 |
# another Makefile, see the discussion of SRCDIR above. |
| 161 |
SRCDIR ?= $(abspath ../..) |
| 162 |
|
| 163 |
# PROOFDIR is the path to the directory containing the proof harness |
| 164 |
PROOFDIR ?= $(abspath .) |
| 165 |
|
| 166 |
################################################################ |
| 167 |
# Define how to run CBMC |
| 168 |
|
| 169 |
# Do property checking with the external SAT solver given by |
| 170 |
# EXTERNAL_SAT_SOLVER. Do coverage checking with the default solver, |
| 171 |
# since coverage checking requires the use of an incremental solver. |
| 172 |
# The EXTERNAL_SAT_SOLVER variable is typically set (if it is at all) |
| 173 |
# as an environment variable or as a makefile variable in |
| 174 |
# Makefile-project-defines. |
| 175 |
# |
| 176 |
# For a particular proof, if the default solver is faster, do property |
| 177 |
# checking with the default solver by including this definition in the |
| 178 |
# proof Makefile: |
| 179 |
# USE_EXTERNAL_SAT_SOLVER = |
| 180 |
# |
| 181 |
ifneq ($(strip $(EXTERNAL_SAT_SOLVER)),) |
| 182 |
USE_EXTERNAL_SAT_SOLVER ?= --external-sat-solver $(EXTERNAL_SAT_SOLVER) |
| 183 |
endif |
| 184 |
CHECKFLAGS += $(USE_EXTERNAL_SAT_SOLVER) |
| 185 |
|
| 186 |
# Job pools |
| 187 |
# For version of Litani that are new enough (where `litani print-capabilities` |
| 188 |
# prints "pools"), proofs for which `EXPENSIVE = true` is set can be added to a |
| 189 |
# "job pool" that restricts how many expensive proofs are run at a time. All |
| 190 |
# other proofs will be built in parallel as usual. |
| 191 |
# |
| 192 |
# In more detail: all compilation, instrumentation, and report jobs are run with |
| 193 |
# full parallelism as usual, even for expensive proofs. The CBMC jobs for |
| 194 |
# non-expensive proofs are also run in parallel. The only difference is that the |
| 195 |
# CBMC safety checks and coverage checks for expensive proofs are run with a |
| 196 |
# restricted parallelism level. At any one time, only N of these jobs are run at |
| 197 |
# once, amongst all the proofs. |
| 198 |
# |
| 199 |
# To configure N, Litani needs to be initialized with a pool called "expensive". |
| 200 |
# For example, to only run two CBMC safety/coverage jobs at a time from amongst |
| 201 |
# all the proofs, you would initialize litani like |
| 202 |
# litani init --pools expensive:2 |
| 203 |
# The run-cbmc-proofs.py script takes care of this initialization through the |
| 204 |
# --expensive-jobs-parallelism flag. |
| 205 |
# |
| 206 |
# To enable this feature, set |
| 207 |
# the ENABLE_POOLS variable when running Make, like |
| 208 |
# `make ENABLE_POOLS=true report` |
| 209 |
# The run-cbmc-proofs.py script takes care of this through the |
| 210 |
# --restrict-expensive-jobs flag. |
| 211 |
|
| 212 |
ifeq ($(strip $(ENABLE_POOLS)),) |
| 213 |
POOL = |
| 214 |
INIT_POOLS = |
| 215 |
else ifeq ($(strip $(EXPENSIVE)),) |
| 216 |
POOL = |
| 217 |
INIT_POOLS = |
| 218 |
else |
| 219 |
POOL = --pool expensive |
| 220 |
INIT_POOLS = --pools expensive:1 |
| 221 |
endif |
| 222 |
|
| 223 |
# Similar to the pool feature above. If Litani is new enough, enable |
| 224 |
# profiling CBMC's memory use. |
| 225 |
ifeq ($(strip $(ENABLE_MEMORY_PROFILING)),) |
| 226 |
MEMORY_PROFILING = |
| 227 |
else |
| 228 |
MEMORY_PROFILING = --profile-memory |
| 229 |
endif |
| 230 |
|
| 231 |
# Property checking flags |
| 232 |
# |
| 233 |
# Each variable below controls a specific property checking flag |
| 234 |
# within CBMC. If desired, a property flag can be disabled within |
| 235 |
# a particular proof by nulling the corresponding variable when CBMC's default |
| 236 |
# is not to perform such checks, or setting to --no-<CHECK>-check when CBMC's |
| 237 |
# default is to perform such checks. For instance, the following lines: |
| 238 |
# |
| 239 |
# CBMC_FLAG_POINTER_CHECK = --no-pointer-check |
| 240 |
# CBMC_FLAG_UNSIGNED_OVERFLOW_CHECK = |
| 241 |
# |
| 242 |
# would disable pointer checks and unsigned overflow checks with CBMC flag |
| 243 |
# within: |
| 244 |
# * an entire project when added to Makefile-project-defines |
| 245 |
# * a specific proof when added to the harness Makefile |
| 246 |
|
| 247 |
CBMC_FLAG_MALLOC_MAY_FAIL ?= # set to --no-malloc-may-fail to disable |
| 248 |
CBMC_FLAG_BOUNDS_CHECK ?= # set to --no-bounds-check to disable |
| 249 |
CBMC_FLAG_CONVERSION_CHECK ?= --conversion-check |
| 250 |
CBMC_FLAG_DIV_BY_ZERO_CHECK ?= # set to --no-div-by-zero-check to disable |
| 251 |
CBMC_FLAG_FLOAT_OVERFLOW_CHECK ?= --float-overflow-check |
| 252 |
CBMC_FLAG_NAN_CHECK ?= --nan-check |
| 253 |
CBMC_FLAG_POINTER_CHECK ?= #set to --no-pointer-check to disable |
| 254 |
CBMC_FLAG_POINTER_OVERFLOW_CHECK ?= --pointer-overflow-check |
| 255 |
CBMC_FLAG_POINTER_PRIMITIVE_CHECK ?= # set to --no-pointer-primitive-check to disable |
| 256 |
CBMC_FLAG_SIGNED_OVERFLOW_CHECK ?= # set to --no-signed-overflow-check to disable |
| 257 |
CBMC_FLAG_UNDEFINED_SHIFT_CHECK ?= # set to --no-undefined-shift-check to disable |
| 258 |
CBMC_FLAG_UNSIGNED_OVERFLOW_CHECK ?= --unsigned-overflow-check |
| 259 |
CBMC_FLAG_UNWINDING_ASSERTIONS ?= # set to --no-unwinding-assertions to disable |
| 260 |
CBMC_DEFAULT_UNWIND ?= --unwind 1 |
| 261 |
CBMC_FLAG_FLUSH ?= --flush |
| 262 |
|
| 263 |
# CBMC flags used for property checking and coverage checking |
| 264 |
|
| 265 |
CBMCFLAGS += $(CBMC_FLAG_FLUSH) |
| 266 |
|
| 267 |
# CBMC 6.0.0 enables all standard checks by default, which can make coverage analysis |
| 268 |
# very slow. See https://github.com/diffblue/cbmc/issues/8389 |
| 269 |
# For now, we disable these checks when generating coverage info. |
| 270 |
COVERFLAGS ?= --no-standard-checks --malloc-may-fail --malloc-fail-null |
| 271 |
|
| 272 |
# CBMC flags used for property checking |
| 273 |
|
| 274 |
CHECKFLAGS += $(CBMC_FLAG_BOUNDS_CHECK) |
| 275 |
CHECKFLAGS += $(CBMC_FLAG_CONVERSION_CHECK) |
| 276 |
CHECKFLAGS += $(CBMC_FLAG_DIV_BY_ZERO_CHECK) |
| 277 |
CHECKFLAGS += $(CBMC_FLAG_FLOAT_OVERFLOW_CHECK) |
| 278 |
CHECKFLAGS += $(CBMC_FLAG_NAN_CHECK) |
| 279 |
CHECKFLAGS += $(CBMC_FLAG_POINTER_CHECK) |
| 280 |
CHECKFLAGS += $(CBMC_FLAG_POINTER_OVERFLOW_CHECK) |
| 281 |
CHECKFLAGS += $(CBMC_FLAG_POINTER_PRIMITIVE_CHECK) |
| 282 |
CHECKFLAGS += $(CBMC_FLAG_SIGNED_OVERFLOW_CHECK) |
| 283 |
CHECKFLAGS += $(CBMC_FLAG_UNDEFINED_SHIFT_CHECK) |
| 284 |
CHECKFLAGS += $(CBMC_FLAG_UNSIGNED_OVERFLOW_CHECK) |
| 285 |
|
| 286 |
# Additional CBMC flag to CBMC control verbosity. |
| 287 |
# |
| 288 |
# Meaningful values are |
| 289 |
# 0 none |
| 290 |
# 1 only errors |
| 291 |
# 2 + warnings |
| 292 |
# 4 + results |
| 293 |
# 6 + status/phase information |
| 294 |
# 8 + statistical information |
| 295 |
# 9 + progress information |
| 296 |
# 10 + debug info |
| 297 |
# |
| 298 |
# Uncomment the following line or set in Makefile-project-defines |
| 299 |
# CBMC_VERBOSITY ?= --verbosity 4 |
| 300 |
|
| 301 |
# Additional CBMC flag to control how CBMC treats static variables. |
| 302 |
# |
| 303 |
# NONDET_STATIC is a list of flags of the form --nondet-static |
| 304 |
# and --nondet-static-exclude VAR. The --nondet-static flag causes |
| 305 |
# CBMC to initialize static variables with unconstrained value |
| 306 |
# (ignoring initializers and default zero-initialization). The |
| 307 |
# --nondet-static-exclude VAR excludes VAR for the variables |
| 308 |
# initialized with unconstrained values. |
| 309 |
NONDET_STATIC ?= |
| 310 |
|
| 311 |
# Flags to pass to goto-cc for compilation and linking |
| 312 |
COMPILE_FLAGS ?= -Wall -Werror |
| 313 |
LINK_FLAGS ?= -Wall -Werror |
| 314 |
EXPORT_FILE_LOCAL_SYMBOLS ?= --export-file-local-symbols |
| 315 |
|
| 316 |
# During instrumentation, it adds models of C library functions |
| 317 |
ADD_LIBRARY_FLAG := --add-library |
| 318 |
|
| 319 |
# Preprocessor include paths -I... |
| 320 |
INCLUDES ?= |
| 321 |
|
| 322 |
# Preprocessor definitions -D... |
| 323 |
DEFINES ?= |
| 324 |
|
| 325 |
# CBMC object model |
| 326 |
# |
| 327 |
# CBMC_OBJECT_BITS is the number of bits in a pointer CBMC uses for |
| 328 |
# the id of the object to which a pointer is pointing. CBMC uses 8 |
| 329 |
# bits for the object id by default. The remaining bits in the pointer |
| 330 |
# are used for offset into the object. This limits the size of the |
| 331 |
# objects that CBMC can model. This Makefile defines this bound on |
| 332 |
# object size to be CBMC_MAX_OBJECT_SIZE. You are likely to get |
| 333 |
# unexpected results if you try to malloc an object larger than this |
| 334 |
# bound. |
| 335 |
CBMC_OBJECT_BITS ?= 8 |
| 336 |
|
| 337 |
# CBMC loop unwinding (Normally set in the proof Makefile) |
| 338 |
# |
| 339 |
# UNWINDSET is a list of pairs of the form foo.1:4 meaning that |
| 340 |
# CBMC should unwind loop 1 in function foo no more than 4 times. |
| 341 |
# For historical reasons, the number 4 is one more than the number |
| 342 |
# of times CBMC actually unwinds the loop. |
| 343 |
UNWINDSET ?= |
| 344 |
|
| 345 |
# CBMC early loop unwinding (Normally set in the proof Makefile) |
| 346 |
# |
| 347 |
# Most users can ignore this variable. |
| 348 |
# |
| 349 |
# This variable exists to support the use of loop and function |
| 350 |
# contracts, two features under development for CBMC. Checking the |
| 351 |
# assigns clause for function contracts and loop invariants currently |
| 352 |
# assumes loop-free bodies for loops and functions with contracts |
| 353 |
# (possibly after replacing nested loops with their own loop |
| 354 |
# contracts). To satisfy this requirement, it may be necessary to |
| 355 |
# unwind some loops before the function contract and loop invariant |
| 356 |
# transformations are applied to the goto program. This variable |
| 357 |
# CPROVER_LIBRARY_UNWINDSET is identical to UNWINDSET, and we assume that the |
| 358 |
# loops mentioned in CPROVER_LIBRARY_UNWINDSET and UNWINDSET are disjoint. |
| 359 |
CPROVER_LIBRARY_UNWINDSET ?= |
| 360 |
|
| 361 |
# CBMC function removal (Normally set set in the proof Makefile) |
| 362 |
# |
| 363 |
# REMOVE_FUNCTION_BODY is a list of function names. CBMC will "undefine" |
| 364 |
# the function, and CBMC will treat the function as having no side effects |
| 365 |
# and returning an unconstrained value of the appropriate return type. |
| 366 |
# The list should include the names of functions being stubbed out. |
| 367 |
REMOVE_FUNCTION_BODY ?= |
| 368 |
|
| 369 |
# CBMC function pointer restriction (Normally set in the proof Makefile) |
| 370 |
# |
| 371 |
# RESTRICT_FUNCTION_POINTER is a list of function pointer restriction |
| 372 |
# instructions of the form: |
| 373 |
# |
| 374 |
# <fun_id>.function_pointer_call.<N>/<fun_id>[,<fun_id>]* |
| 375 |
# |
| 376 |
# The function pointer call number <N> in the specified function gets |
| 377 |
# rewritten to a case switch over a finite list of functions. |
| 378 |
# If some possible target functions are omitted from the list a counter |
| 379 |
# example trace will be found by CBMC, i.e. the transformation is sound. |
| 380 |
# If the target functions are file-local symbols, then mangled names must |
| 381 |
# be used. |
| 382 |
RESTRICT_FUNCTION_POINTER ?= |
| 383 |
|
| 384 |
# The project source files (Normally set set in the proof Makefile) |
| 385 |
# |
| 386 |
# PROJECT_SOURCES is the list of project source files to compile, |
| 387 |
# including the source file defining the function under test. |
| 388 |
PROJECT_SOURCES ?= |
| 389 |
|
| 390 |
# The proof source files (Normally set in the proof Makefile) |
| 391 |
# |
| 392 |
# PROOF_SOURCES is the list of proof source files to compile, including |
| 393 |
# the proof harness, and including any function stubs being used. |
| 394 |
PROOF_SOURCES ?= |
| 395 |
PROOF_SOURCES += $(PROOF_STUB)/s2n_calculate_stacktrace.c |
| 396 |
|
| 397 |
# The number of seconds that CBMC should be allowed to run for before |
| 398 |
# being forcefully terminated. Currently, this is set to be less than |
| 399 |
# the time limit for a CodeBuild job, which is eight hours. If a proof |
| 400 |
# run takes longer than the time limit of the CI environment, the |
| 401 |
# environment will halt the proof run without updating the Litani |
| 402 |
# report, making the proof run appear to "hang". |
| 403 |
CBMC_TIMEOUT ?= 21600 |
| 404 |
|
| 405 |
# CBMC string abstraction |
| 406 |
# |
| 407 |
# Replace all uses of char * by a struct that carries that string, |
| 408 |
# and also the underlying allocation and the C string length. |
| 409 |
STRING_ABSTRACTION ?= |
| 410 |
ifdef STRING_ABSTRACTION |
| 411 |
ifneq ($(strip $(STRING_ABSTRACTION)),) |
| 412 |
CBMC_STRING_ABSTRACTION := --string-abstraction |
| 413 |
endif |
| 414 |
endif |
| 415 |
|
| 416 |
# Optional configuration library flags |
| 417 |
OPT_CONFIG_LIBRARY ?= |
| 418 |
CBMC_OPT_CONFIG_LIBRARY := $(CBMC_FLAG_MALLOC_MAY_FAIL) $(CBMC_STRING_ABSTRACTION) |
| 419 |
|
| 420 |
# Proof writers could add function contracts in their source code. |
| 421 |
# These contracts are ignored by default, but may be enabled in two distinct |
| 422 |
# contexts using the following two variables: |
| 423 |
# 1. To check whether one or more function contracts are sound with respect to |
| 424 |
# the function implementation, CHECK_FUNCTION_CONTRACTS should be a list of |
| 425 |
# function names. Use CHECK_FUNCTION_CONTRACTS_REC to check contracts on |
| 426 |
# recursive functions. |
| 427 |
# 2. To replace calls to certain functions with their correspondent function |
| 428 |
# contracts, USE_FUNCTION_CONTRACTS should be a list of function names. |
| 429 |
# One must check separately whether a function contract is sound before |
| 430 |
# replacing it in calling contexts. |
| 431 |
CHECK_FUNCTION_CONTRACTS ?= |
| 432 |
CBMC_CHECK_FUNCTION_CONTRACTS := $(patsubst %,--enforce-contract %, $(CHECK_FUNCTION_CONTRACTS)) |
| 433 |
|
| 434 |
CHECK_FUNCTION_CONTRACTS_REC ?= |
| 435 |
CBMC_CHECK_FUNCTION_CONTRACTS_REC := $(patsubst %,--enforce-contract-rec %, $(CHECK_FUNCTION_CONTRACTS_REC)) |
| 436 |
|
| 437 |
USE_FUNCTION_CONTRACTS ?= |
| 438 |
CBMC_USE_FUNCTION_CONTRACTS := $(patsubst %,--replace-call-with-contract %, $(USE_FUNCTION_CONTRACTS)) |
| 439 |
|
| 440 |
CODE_CONTRACTS := $(CHECK_FUNCTION_CONTRACTS)$(USE_FUNCTION_CONTRACTS)$(APPLY_LOOP_CONTRACTS) |
| 441 |
|
| 442 |
# Proof writers may also apply function contracts using the Dynamic Frame |
| 443 |
# Condition Checking (DFCC) mode. For more information on DFCC, |
| 444 |
# please see https://diffblue.github.io/cbmc/contracts-dev-spec-dfcc.html. |
| 445 |
USE_DYNAMIC_FRAMES ?= |
| 446 |
ifdef USE_DYNAMIC_FRAMES |
| 447 |
ifneq ($(strip $(USE_DYNAMIC_FRAMES)),) |
| 448 |
CBMC_USE_DYNAMIC_FRAMES := $(CBMC_OPT_CONFIG_LIBRARY) --dfcc $(HARNESS_ENTRY) $(CBMC_CHECK_FUNCTION_CONTRACTS_REC) |
| 449 |
endif |
| 450 |
endif |
| 451 |
|
| 452 |
# Similarly, proof writers could also add loop contracts in their source code |
| 453 |
# to obtain unbounded correctness proofs. Unlike function contracts, loop |
| 454 |
# contracts are not reusable and thus are checked and used simultaneously. |
| 455 |
# These contracts are also ignored by default, but may be enabled by setting |
| 456 |
# the APPLY_LOOP_CONTRACTS variable. |
| 457 |
APPLY_LOOP_CONTRACTS ?= |
| 458 |
ifdef APPLY_LOOP_CONTRACTS |
| 459 |
ifneq ($(strip $(APPLY_LOOP_CONTRACTS)),) |
| 460 |
CBMC_APPLY_LOOP_CONTRACTS := --apply-loop-contracts |
| 461 |
endif |
| 462 |
endif |
| 463 |
|
| 464 |
# The default unwind should only be used in DFCC mode without loop contracts. |
| 465 |
# When loop contracts are applied, we only unwind specified loops. |
| 466 |
# If any loops remain after loop contracts have been applied, CBMC might try |
| 467 |
# to unwind the program indefinitely, because we do not pass default unwind |
| 468 |
# (i.e., --unwind 1) to CBMC when in DFCC mode. |
| 469 |
# We must not use a default unwind command in DFCC mode, because contract instrumentation |
| 470 |
# introduces loops encoding write set inclusion checks that must be dynamically unwound during |
| 471 |
# symex. |
| 472 |
ifneq ($(strip $(USE_DYNAMIC_FRAMES)),) |
| 473 |
ifneq ($(strip $(APPLY_LOOP_CONTRACTS)),) |
| 474 |
UNWIND_0500_FLAGS=$(CBMC_UNWINDSET) $(CBMC_CPROVER_LIBRARY_UNWINDSET) $(CBMC_FLAG_UNWINDING_ASSERTIONS) |
| 475 |
UNWIND_0500_DESC="$(PROOF_UID): unwinding specified subset of loops" |
| 476 |
else |
| 477 |
UNWIND_0500_FLAGS=$(CBMC_UNWINDSET) $(CBMC_CPROVER_LIBRARY_UNWINDSET) $(CBMC_DEFAULT_UNWIND) $(CBMC_FLAG_UNWINDING_ASSERTIONS) |
| 478 |
UNWIND_0500_DESC="$(PROOF_UID): unwinding all loops" |
| 479 |
endif |
| 480 |
endif |
| 481 |
|
| 482 |
# Silence makefile output (eg, long litani commands) unless VERBOSE is set. |
| 483 |
ifndef VERBOSE |
| 484 |
MAKEFLAGS := $(MAKEFLAGS) -s |
| 485 |
endif |
| 486 |
|
| 487 |
################################################################ |
| 488 |
################################################################ |
| 489 |
## Section II: This section defines the process of running a proof |
| 490 |
## |
| 491 |
## There should be no reason to edit anything below this line. |
| 492 |
|
| 493 |
################################################################ |
| 494 |
# Paths |
| 495 |
|
| 496 |
CBMC ?= cbmc |
| 497 |
GOTO_ANALYZER ?= goto-analyzer |
| 498 |
GOTO_CC ?= goto-cc |
| 499 |
GOTO_INSTRUMENT ?= goto-instrument |
| 500 |
CRANGLER ?= crangler |
| 501 |
VIEWER ?= cbmc-viewer |
| 502 |
VIEWER2 ?= cbmc-viewer |
| 503 |
CMAKE ?= cmake |
| 504 |
|
| 505 |
GOTODIR ?= $(PROOFDIR)/gotos |
| 506 |
LOGDIR ?= $(PROOFDIR)/logs |
| 507 |
|
| 508 |
PROJECT ?= project |
| 509 |
PROOF ?= proof |
| 510 |
|
| 511 |
HARNESS_GOTO ?= $(GOTODIR)/$(HARNESS_FILE) |
| 512 |
PROJECT_GOTO ?= $(GOTODIR)/$(PROJECT) |
| 513 |
PROOF_GOTO ?= $(GOTODIR)/$(PROOF) |
| 514 |
|
| 515 |
################################################################ |
| 516 |
# Useful macros for values that are hard to reference |
| 517 |
SPACE :=$() $() |
| 518 |
COMMA :=, |
| 519 |
|
| 520 |
################################################################ |
| 521 |
# Set C compiler defines |
| 522 |
|
| 523 |
CBMCFLAGS += --object-bits $(CBMC_OBJECT_BITS) |
| 524 |
|
| 525 |
DEFINES += -DCBMC=1 |
| 526 |
DEFINES += -DCBMC_OBJECT_BITS=$(CBMC_OBJECT_BITS) |
| 527 |
DEFINES += -DCBMC_MAX_OBJECT_SIZE="(SIZE_MAX>>(CBMC_OBJECT_BITS+1))" |
| 528 |
|
| 529 |
# CI currently assumes cbmc invocation has at most one --unwindset |
| 530 |
|
| 531 |
# UNWINDSET is designed for user code (i.e., proof and project code) |
| 532 |
ifdef UNWINDSET |
| 533 |
ifneq ($(strip $(UNWINDSET)),) |
| 534 |
CBMC_UNWINDSET := --unwindset $(subst $(SPACE),$(COMMA),$(strip $(UNWINDSET))) |
| 535 |
endif |
| 536 |
endif |
| 537 |
|
| 538 |
# CPROVER_LIBRARY_UNWINDSET is designed for CPROVER library functions |
| 539 |
ifdef CPROVER_LIBRARY_UNWINDSET |
| 540 |
ifneq ($(strip $(CPROVER_LIBRARY_UNWINDSET)),) |
| 541 |
CBMC_CPROVER_LIBRARY_UNWINDSET := --unwindset $(subst $(SPACE),$(COMMA),$(strip $(CPROVER_LIBRARY_UNWINDSET))) |
| 542 |
endif |
| 543 |
endif |
| 544 |
|
| 545 |
CBMC_REMOVE_FUNCTION_BODY := $(patsubst %,--remove-function-body %, $(REMOVE_FUNCTION_BODY)) |
| 546 |
|
| 547 |
ifdef RESTRICT_FUNCTION_POINTER |
| 548 |
ifneq ($(strip $(RESTRICT_FUNCTION_POINTER)),) |
| 549 |
CBMC_RESTRICT_FUNCTION_POINTER := $(patsubst %,--restrict-function-pointer %, $(RESTRICT_FUNCTION_POINTER)) |
| 550 |
endif |
| 551 |
endif |
| 552 |
|
| 553 |
################################################################ |
| 554 |
# Targets for rewriting source files with crangler |
| 555 |
|
| 556 |
# Construct crangler configuration files |
| 557 |
# |
| 558 |
# REWRITTEN_SOURCES is a list of crangler output files source.i. |
| 559 |
# This target assumes that for each source.i |
| 560 |
# * source.i_SOURCE is the path to a source file, |
| 561 |
# * source.i_FUNCTIONS is a list of functions (may be empty) |
| 562 |
# * source.i_OBJECTS is a list of variables (may be empty) |
| 563 |
# This target constructs the crangler configuration file source.i.json |
| 564 |
# of the form |
| 565 |
# { |
| 566 |
# "sources": [ "/proj/code.c" ], |
| 567 |
# "includes": [ "/proj/include" ], |
| 568 |
# "defines": [ "VAR=1" ], |
| 569 |
# "functions": [ {"function_name": ["remove static"]} ], |
| 570 |
# "objects": [ {"variable_name": ["remove static"]} ], |
| 571 |
# "output": "source.i" |
| 572 |
# } |
| 573 |
# to remove the static attribute from function_name and variable_name |
| 574 |
# in the source file source.c and write the result to source.i. |
| 575 |
# |
| 576 |
# This target assumes that filenames include no spaces and that |
| 577 |
# the INCLUDES and DEFINES variables include no spaces after -I |
| 578 |
# and -D. For example, use "-DVAR=1" and not "-D VAR=1". |
| 579 |
# |
| 580 |
# Define *_SOURCE, *_FUNCTIONS, and *_OBJECTS in the proof Makefile. |
| 581 |
# The string source.i is usually an absolute path $(PROOFDIR)/code.i |
| 582 |
# to a file in the proof directory that contains the proof Makefile. |
| 583 |
# The proof Makefile usually includes the definitions |
| 584 |
# $(PROOFDIR)/code.i_SOURCE = /proj/code.c |
| 585 |
# $(PROOFDIR)/code.i_FUNCTIONS = function_name |
| 586 |
# $(PROOFDIR)/code.i_OBJECTS = variable_name |
| 587 |
# Because these definitions refer to PROOFDIR that is defined in this |
| 588 |
# Makefile.common, these definitions must appear after the inclusion |
| 589 |
# of Makefile.common in the proof Makefile. |
| 590 |
# |
| 591 |
$(foreach rs,$(REWRITTEN_SOURCES),$(eval $(rs).json: $($(rs)_SOURCE))) |
| 592 |
$(foreach rs,$(REWRITTEN_SOURCES),$(rs).json): |
| 593 |
echo '{'\ |
| 594 |
'"sources": ['\ |
| 595 |
'"$($(@:.json=)_SOURCE)"'\ |
| 596 |
'],'\ |
| 597 |
'"includes": ['\ |
| 598 |
'$(subst $(SPACE),$(COMMA),$(patsubst -I%,"%",$(strip $(INCLUDES))))' \ |
| 599 |
'],'\ |
| 600 |
'"defines": ['\ |
| 601 |
'$(subst $(SPACE),$(COMMA),$(patsubst -D%,"%",$(subst ",\",$(strip $(DEFINES)))))' \ |
| 602 |
'],'\ |
| 603 |
'"functions": ['\ |
| 604 |
'{'\ |
| 605 |
'$(subst ~, ,$(subst $(SPACE),$(COMMA),$(patsubst %,"%":["remove~static"],$($(@:.json=)_FUNCTIONS))))' \ |
| 606 |
'}'\ |
| 607 |
'],'\ |
| 608 |
'"objects": ['\ |
| 609 |
'{'\ |
| 610 |
'$(subst ~, ,$(subst $(SPACE),$(COMMA),$(patsubst %,"%":["remove~static"],$($(@:.json=)_OBJECTS))))' \ |
| 611 |
'}'\ |
| 612 |
'],'\ |
| 613 |
'"output": "$(@:.json=)"'\ |
| 614 |
'}' > $@ |
| 615 |
|
| 616 |
# Rewrite source files with crangler |
| 617 |
# |
| 618 |
$(foreach rs,$(REWRITTEN_SOURCES),$(eval $(rs): $(rs).json)) |
| 619 |
$(REWRITTEN_SOURCES): |
| 620 |
$(LITANI) add-job \ |
| 621 |
--command \ |
| 622 |
'$(CRANGLER) [email protected]' \ |
| 623 |
--inputs $($@_SOURCE) \ |
| 624 |
--outputs $@ \ |
| 625 |
--stdout-file $(LOGDIR)/crangler-$(subst /,_,$(subst .,_,$@))-log.txt \ |
| 626 |
--interleave-stdout-stderr \ |
| 627 |
--pipeline-name "$(PROOF_UID)" \ |
| 628 |
--ci-stage build \ |
| 629 |
--description "$(PROOF_UID): removing static" |
| 630 |
|
| 631 |
################################################################ |
| 632 |
# Build targets that make the relevant .goto files |
| 633 |
|
| 634 |
# Compile project sources |
| 635 |
$(PROJECT_GOTO)0100.goto: $(PROJECT_SOURCES) $(REWRITTEN_SOURCES) |
| 636 |
$(LITANI) add-job \ |
| 637 |
--command \ |
| 638 |
'$(GOTO_CC) $(CBMC_VERBOSITY) $(COMPILE_FLAGS) $(EXPORT_FILE_LOCAL_SYMBOLS) $(INCLUDES) $(DEFINES) $^ -o $@' \ |
| 639 |
--inputs $^ \ |
| 640 |
--outputs $@ \ |
| 641 |
--stdout-file $(LOGDIR)/project_sources-log.txt \ |
| 642 |
--pipeline-name "$(PROOF_UID)" \ |
| 643 |
--ci-stage build \ |
| 644 |
--description "$(PROOF_UID): building project binary" |
| 645 |
|
| 646 |
# Compile proof sources |
| 647 |
$(PROOF_GOTO)0100.goto: $(PROOF_SOURCES) |
| 648 |
$(LITANI) add-job \ |
| 649 |
--command \ |
| 650 |
'$(GOTO_CC) $(CBMC_VERBOSITY) $(COMPILE_FLAGS) $(EXPORT_FILE_LOCAL_SYMBOLS) $(INCLUDES) $(DEFINES) $^ -o $@' \ |
| 651 |
--inputs $^ \ |
| 652 |
--outputs $@ \ |
| 653 |
--stdout-file $(LOGDIR)/proof_sources-log.txt \ |
| 654 |
--pipeline-name "$(PROOF_UID)" \ |
| 655 |
--ci-stage build \ |
| 656 |
--description "$(PROOF_UID): building proof binary" |
| 657 |
|
| 658 |
# Remove function bodies from project sources |
| 659 |
$(PROJECT_GOTO)0200.goto: $(PROJECT_GOTO)0100.goto |
| 660 |
$(LITANI) add-job \ |
| 661 |
--command \ |
| 662 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) $(CBMC_REMOVE_FUNCTION_BODY) $^ $@' \ |
| 663 |
--inputs $^ \ |
| 664 |
--outputs $@ \ |
| 665 |
--stdout-file $(LOGDIR)/remove_function_body-log.txt \ |
| 666 |
--pipeline-name "$(PROOF_UID)" \ |
| 667 |
--ci-stage build \ |
| 668 |
--description "$(PROOF_UID): removing function bodies from project sources" |
| 669 |
|
| 670 |
# Link project and proof sources into the proof harness |
| 671 |
$(HARNESS_GOTO)0100.goto: $(PROOF_GOTO)0100.goto $(PROJECT_GOTO)0200.goto |
| 672 |
$(LITANI) add-job \ |
| 673 |
--command '$(GOTO_CC) $(CBMC_VERBOSITY) --function $(HARNESS_ENTRY) $^ $(LINK_FLAGS) -o $@' \ |
| 674 |
--inputs $^ \ |
| 675 |
--outputs $@ \ |
| 676 |
--stdout-file $(LOGDIR)/link_proof_project-log.txt \ |
| 677 |
--pipeline-name "$(PROOF_UID)" \ |
| 678 |
--ci-stage build \ |
| 679 |
--description "$(PROOF_UID): linking project to proof" |
| 680 |
|
| 681 |
# Restrict function pointers |
| 682 |
$(HARNESS_GOTO)0200.goto: $(HARNESS_GOTO)0100.goto |
| 683 |
$(LITANI) add-job \ |
| 684 |
--command \ |
| 685 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) $(CBMC_RESTRICT_FUNCTION_POINTER) --remove-function-pointers $^ $@' \ |
| 686 |
--inputs $^ \ |
| 687 |
--outputs $@ \ |
| 688 |
--stdout-file $(LOGDIR)/restrict_function_pointer-log.txt \ |
| 689 |
--pipeline-name "$(PROOF_UID)" \ |
| 690 |
--ci-stage build \ |
| 691 |
--description "$(PROOF_UID): restricting function pointers in project sources" |
| 692 |
|
| 693 |
# Fill static variable with unconstrained values |
| 694 |
$(HARNESS_GOTO)0300.goto: $(HARNESS_GOTO)0200.goto |
| 695 |
ifneq ($(strip $(CODE_CONTRACTS)),) |
| 696 |
$(LITANI) add-job \ |
| 697 |
--command 'cp $^ $@' \ |
| 698 |
--inputs $^ \ |
| 699 |
--outputs $@ \ |
| 700 |
--stdout-file $(LOGDIR)/nondet_static-log.txt \ |
| 701 |
--pipeline-name "$(PROOF_UID)" \ |
| 702 |
--ci-stage build \ |
| 703 |
--description "$(PROOF_UID): not setting static variables to nondet (will do during contract instrumentation)" |
| 704 |
else |
| 705 |
$(LITANI) add-job \ |
| 706 |
--command \ |
| 707 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) $(NONDET_STATIC) $^ $@' \ |
| 708 |
--inputs $^ \ |
| 709 |
--outputs $@ \ |
| 710 |
--stdout-file $(LOGDIR)/nondet_static-log.txt \ |
| 711 |
--pipeline-name "$(PROOF_UID)" \ |
| 712 |
--ci-stage build \ |
| 713 |
--description "$(PROOF_UID): setting static variables to nondet" |
| 714 |
endif |
| 715 |
|
| 716 |
# Link CPROVER library if DFCC mode is on |
| 717 |
$(HARNESS_GOTO)0400.goto: $(HARNESS_GOTO)0300.goto |
| 718 |
ifneq ($(strip $(USE_DYNAMIC_FRAMES)),) |
| 719 |
$(LITANI) add-job \ |
| 720 |
--command \ |
| 721 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) $(ADD_LIBRARY_FLAG) $(CBMC_OPT_CONFIG_LIBRARY) $^ $@' \ |
| 722 |
--inputs $^ \ |
| 723 |
--outputs $@ \ |
| 724 |
--stdout-file $(LOGDIR)/linking-library-models-log.txt \ |
| 725 |
--pipeline-name "$(PROOF_UID)" \ |
| 726 |
--ci-stage build \ |
| 727 |
--description "$(PROOF_UID): linking CPROVER library" |
| 728 |
else |
| 729 |
$(LITANI) add-job \ |
| 730 |
--command 'cp $^ $@' \ |
| 731 |
--inputs $^ \ |
| 732 |
--outputs $@ \ |
| 733 |
--stdout-file $(LOGDIR)/linking-library-models-log.txt \ |
| 734 |
--pipeline-name "$(PROOF_UID)" \ |
| 735 |
--ci-stage build \ |
| 736 |
--description "$(PROOF_UID): not linking CPROVER library" |
| 737 |
endif |
| 738 |
|
| 739 |
# Early unwind all loops on DFCC mode; otherwise, only unwind loops in proof and project code |
| 740 |
$(HARNESS_GOTO)0500.goto: $(HARNESS_GOTO)0400.goto |
| 741 |
ifneq ($(strip $(USE_DYNAMIC_FRAMES)),) |
| 742 |
$(LITANI) add-job \ |
| 743 |
--command \ |
| 744 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) $(UNWIND_0500_FLAGS) $^ $@' \ |
| 745 |
--inputs $^ \ |
| 746 |
--outputs $@ \ |
| 747 |
--stdout-file $(LOGDIR)/unwind_loops-log.txt \ |
| 748 |
--pipeline-name "$(PROOF_UID)" \ |
| 749 |
--ci-stage build \ |
| 750 |
--description $(UNWIND_0500_DESC) |
| 751 |
else ifneq ($(strip $(CODE_CONTRACTS)),) |
| 752 |
$(LITANI) add-job \ |
| 753 |
--command \ |
| 754 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) $(CBMC_UNWINDSET) $(CBMC_FLAG_UNWINDING_ASSERTIONS) $^ $@' \ |
| 755 |
--inputs $^ \ |
| 756 |
--outputs $@ \ |
| 757 |
--stdout-file $(LOGDIR)/unwind_loops-log.txt \ |
| 758 |
--pipeline-name "$(PROOF_UID)" \ |
| 759 |
--ci-stage build \ |
| 760 |
--description "$(PROOF_UID): unwinding loops in proof and project code" |
| 761 |
else |
| 762 |
$(LITANI) add-job \ |
| 763 |
--command 'cp $^ $@' \ |
| 764 |
--inputs $^ \ |
| 765 |
--outputs $@ \ |
| 766 |
--stdout-file $(LOGDIR)/unwind_loops-log.txt \ |
| 767 |
--pipeline-name "$(PROOF_UID)" \ |
| 768 |
--ci-stage build \ |
| 769 |
--description "$(PROOF_UID): not unwinding loops" |
| 770 |
endif |
| 771 |
|
| 772 |
# Replace function contracts, check function contracts, instrument for loop contracts |
| 773 |
$(HARNESS_GOTO)0600.goto: $(HARNESS_GOTO)0500.goto |
| 774 |
$(LITANI) add-job \ |
| 775 |
--command \ |
| 776 |
'$(GOTO_INSTRUMENT) $(CBMC_USE_DYNAMIC_FRAMES) $(NONDET_STATIC) $(CBMC_VERBOSITY) $(CBMC_CHECK_FUNCTION_CONTRACTS) $(CBMC_USE_FUNCTION_CONTRACTS) $(CBMC_APPLY_LOOP_CONTRACTS) $^ $@' \ |
| 777 |
--inputs $^ \ |
| 778 |
--outputs $@ \ |
| 779 |
--stdout-file $(LOGDIR)/check_function_contracts-log.txt \ |
| 780 |
--pipeline-name "$(PROOF_UID)" \ |
| 781 |
--ci-stage build \ |
| 782 |
--description "$(PROOF_UID): checking function contracts" |
| 783 |
|
| 784 |
# Omit initialization of unused global variables (reduces problem size) |
| 785 |
$(HARNESS_GOTO)0700.goto: $(HARNESS_GOTO)0600.goto |
| 786 |
$(LITANI) add-job \ |
| 787 |
--command \ |
| 788 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) --slice-global-inits $^ $@' \ |
| 789 |
--inputs $^ \ |
| 790 |
--outputs $@ \ |
| 791 |
--stdout-file $(LOGDIR)/slice_global_inits-log.txt \ |
| 792 |
--pipeline-name "$(PROOF_UID)" \ |
| 793 |
--ci-stage build \ |
| 794 |
--description "$(PROOF_UID): slicing global initializations" |
| 795 |
|
| 796 |
# Omit unused functions (sharpens coverage calculations) |
| 797 |
$(HARNESS_GOTO)0800.goto: $(HARNESS_GOTO)0700.goto |
| 798 |
$(LITANI) add-job \ |
| 799 |
--command \ |
| 800 |
'$(GOTO_INSTRUMENT) $(CBMC_VERBOSITY) --drop-unused-functions $^ $@' \ |
| 801 |
--inputs $^ \ |
| 802 |
--outputs $@ \ |
| 803 |
--stdout-file $(LOGDIR)/drop_unused_functions-log.txt \ |
| 804 |
--pipeline-name "$(PROOF_UID)" \ |
| 805 |
--ci-stage build \ |
| 806 |
--description "$(PROOF_UID): dropping unused functions" |
| 807 |
|
| 808 |
# Final name for proof harness |
| 809 |
$(HARNESS_GOTO).goto: $(HARNESS_GOTO)0800.goto |
| 810 |
$(LITANI) add-job \ |
| 811 |
--command 'cp $< $@' \ |
| 812 |
--inputs $^ \ |
| 813 |
--outputs $@ \ |
| 814 |
--pipeline-name "$(PROOF_UID)" \ |
| 815 |
--ci-stage build \ |
| 816 |
--description "$(PROOF_UID): copying final goto-binary" |
| 817 |
|
| 818 |
################################################################ |
| 819 |
# Targets to run the analysis commands |
| 820 |
|
| 821 |
ifdef CBMCFLAGS |
| 822 |
ifeq ($(strip $(CODE_CONTRACTS)),) |
| 823 |
CBMCFLAGS += $(CBMC_UNWINDSET) $(CBMC_CPROVER_LIBRARY_UNWINDSET) $(CBMC_DEFAULT_UNWIND) $(CBMC_OPT_CONFIG_LIBRARY) |
| 824 |
else ifeq ($(strip $(USE_DYNAMIC_FRAMES)),) |
| 825 |
CBMCFLAGS += $(CBMC_CPROVER_LIBRARY_UNWINDSET) $(CBMC_OPT_CONFIG_LIBRARY) |
| 826 |
endif |
| 827 |
endif |
| 828 |
|
| 829 |
$(LOGDIR)/result.xml: $(HARNESS_GOTO).goto |
| 830 |
$(LITANI) add-job \ |
| 831 |
$(POOL) \ |
| 832 |
--command \ |
| 833 |
'$(CBMC) $(CBMC_VERBOSITY) $(CBMCFLAGS) $(CBMC_FLAG_UNWINDING_ASSERTIONS) $(CHECKFLAGS) --trace --xml-ui $<' \ |
| 834 |
--inputs $^ \ |
| 835 |
--outputs $@ \ |
| 836 |
--ci-stage test \ |
| 837 |
--stdout-file $@ \ |
| 838 |
$(MEMORY_PROFILING) \ |
| 839 |
--ignore-returns 10 \ |
| 840 |
--timeout $(CBMC_TIMEOUT) \ |
| 841 |
--pipeline-name "$(PROOF_UID)" \ |
| 842 |
--tags "stats-group:safety checks" \ |
| 843 |
--stderr-file $(LOGDIR)/result-err-log.txt \ |
| 844 |
--description "$(PROOF_UID): checking safety properties" |
| 845 |
|
| 846 |
$(LOGDIR)/result.txt: $(HARNESS_GOTO).goto |
| 847 |
$(LITANI) add-job \ |
| 848 |
$(POOL) \ |
| 849 |
--command \ |
| 850 |
'$(CBMC) $(CBMC_VERBOSITY) $(CBMCFLAGS) $(CBMC_FLAG_UNWINDING_ASSERTIONS) $(CHECKFLAGS) --trace $<' \ |
| 851 |
--inputs $^ \ |
| 852 |
--outputs $@ \ |
| 853 |
--ci-stage test \ |
| 854 |
--stdout-file $@ \ |
| 855 |
$(MEMORY_PROFILING) \ |
| 856 |
--ignore-returns 10 \ |
| 857 |
--timeout $(CBMC_TIMEOUT) \ |
| 858 |
--pipeline-name "$(PROOF_UID)" \ |
| 859 |
--tags "stats-group:safety checks" \ |
| 860 |
--stderr-file $(LOGDIR)/result-err-log.txt \ |
| 861 |
--description "$(PROOF_UID): checking safety properties" |
| 862 |
|
| 863 |
$(LOGDIR)/property.xml: $(HARNESS_GOTO).goto |
| 864 |
$(LITANI) add-job \ |
| 865 |
--command \ |
| 866 |
'$(CBMC) $(CBMC_VERBOSITY) $(CBMCFLAGS) $(CBMC_FLAG_UNWINDING_ASSERTIONS) $(CHECKFLAGS) --show-properties --xml-ui $<' \ |
| 867 |
--inputs $^ \ |
| 868 |
--outputs $@ \ |
| 869 |
--ci-stage test \ |
| 870 |
--stdout-file $@ \ |
| 871 |
--ignore-returns 10 \ |
| 872 |
--pipeline-name "$(PROOF_UID)" \ |
| 873 |
--stderr-file $(LOGDIR)/property-err-log.txt \ |
| 874 |
--description "$(PROOF_UID): printing safety properties" |
| 875 |
|
| 876 |
$(LOGDIR)/coverage.xml: $(HARNESS_GOTO).goto |
| 877 |
$(LITANI) add-job \ |
| 878 |
$(POOL) \ |
| 879 |
--command \ |
| 880 |
'$(CBMC) $(CBMC_VERBOSITY) $(CBMCFLAGS) $(COVERFLAGS) --cover location --xml-ui $<' \ |
| 881 |
--inputs $^ \ |
| 882 |
--outputs $@ \ |
| 883 |
--ci-stage test \ |
| 884 |
--stdout-file $@ \ |
| 885 |
$(MEMORY_PROFILING) \ |
| 886 |
--ignore-returns 10 \ |
| 887 |
--timeout $(CBMC_TIMEOUT) \ |
| 888 |
--pipeline-name "$(PROOF_UID)" \ |
| 889 |
--tags "stats-group:coverage computation" \ |
| 890 |
--stderr-file $(LOGDIR)/coverage-err-log.txt \ |
| 891 |
--description "$(PROOF_UID): calculating coverage" |
| 892 |
|
| 893 |
COVERAGE ?= $(LOGDIR)/coverage.xml |
| 894 |
VIEWER_COVERAGE_FLAG ?= --coverage $(COVERAGE) |
| 895 |
|
| 896 |
$(PROOFDIR)/report: $(LOGDIR)/result.xml $(LOGDIR)/property.xml $(COVERAGE) |
| 897 |
$(LITANI) add-job \ |
| 898 |
--command " $(VIEWER) \ |
| 899 |
--result $(LOGDIR)/result.xml \ |
| 900 |
$(VIEWER_COVERAGE_FLAG) \ |
| 901 |
--property $(LOGDIR)/property.xml \ |
| 902 |
--srcdir $(SRCDIR) \ |
| 903 |
--goto $(HARNESS_GOTO).goto \ |
| 904 |
--reportdir $(PROOFDIR)/report \ |
| 905 |
--config $(PROOFDIR)/cbmc-viewer.json" \ |
| 906 |
--inputs $^ \ |
| 907 |
--outputs $(PROOFDIR)/report \ |
| 908 |
--pipeline-name "$(PROOF_UID)" \ |
| 909 |
--stdout-file $(LOGDIR)/viewer-log.txt \ |
| 910 |
--ci-stage report \ |
| 911 |
--description "$(PROOF_UID): generating report" |
| 912 |
|
| 913 |
litani-path: |
| 914 |
@echo $(LITANI) |
| 915 |
|
| 916 |
# ############################################################## |
| 917 |
# Phony Rules |
| 918 |
# |
| 919 |
# These rules provide a convenient way to run a single proof up to a |
| 920 |
# certain stage. Users can browse into a proof directory and run |
| 921 |
# "make -Bj 3 report" to generate a report for just that proof, or |
| 922 |
# "make goto" to build the goto binary. Under the hood, this runs litani |
| 923 |
# for just that proof. |
| 924 |
|
| 925 |
_goto: $(HARNESS_GOTO).goto |
| 926 |
goto: |
| 927 |
@ echo Running 'litani init' |
| 928 |
$(LITANI) init $(INIT_POOLS) --project $(PROJECT_NAME) |
| 929 |
@ echo Running 'litani add-job' |
| 930 |
$(MAKE) -B _goto |
| 931 |
@ echo Running 'litani build' |
| 932 |
$(LITANI) run-build |
| 933 |
|
| 934 |
_result: $(LOGDIR)/result.txt |
| 935 |
result: |
| 936 |
@ echo Running 'litani init' |
| 937 |
$(LITANI) init $(INIT_POOLS) --project $(PROJECT_NAME) |
| 938 |
@ echo Running 'litani add-job' |
| 939 |
$(MAKE) -B _result |
| 940 |
@ echo Running 'litani build' |
| 941 |
$(LITANI) run-build |
| 942 |
|
| 943 |
_property: $(LOGDIR)/property.xml |
| 944 |
property: |
| 945 |
@ echo Running 'litani init' |
| 946 |
$(LITANI) init $(INIT_POOLS) --project $(PROJECT_NAME) |
| 947 |
@ echo Running 'litani add-job' |
| 948 |
$(MAKE) -B _property |
| 949 |
@ echo Running 'litani build' |
| 950 |
$(LITANI) run-build |
| 951 |
|
| 952 |
_coverage: $(LOGDIR)/coverage.xml |
| 953 |
coverage: |
| 954 |
@ echo Running 'litani init' |
| 955 |
$(LITANI) init $(INIT_POOLS) --project $(PROJECT_NAME) |
| 956 |
@ echo Running 'litani add-job' |
| 957 |
$(MAKE) -B _coverage |
| 958 |
@ echo Running 'litani build' |
| 959 |
$(LITANI) run-build |
| 960 |
|
| 961 |
_report: $(PROOFDIR)/report |
| 962 |
report: |
| 963 |
@ echo Running 'litani init' |
| 964 |
$(LITANI) init $(INIT_POOLS) --project $(PROJECT_NAME) |
| 965 |
@ echo Running 'litani add-job' |
| 966 |
$(MAKE) -B _report |
| 967 |
@ echo Running 'litani build' |
| 968 |
$(LITANI) run-build |
| 969 |
|
| 970 |
_report_no_coverage: |
| 971 |
$(MAKE) COVERAGE="" VIEWER_COVERAGE_FLAG="" _report |
| 972 |
report-no-coverage: |
| 973 |
$(MAKE) COVERAGE="" VIEWER_COVERAGE_FLAG=" " report |
| 974 |
|
| 975 |
################################################################ |
| 976 |
# Targets to clean up after ourselves |
| 977 |
clean: |
| 978 |
-$(RM) $(DEPENDENT_GOTOS) |
| 979 |
-$(RM) TAGS* |
| 980 |
-$(RM) *~ \#* |
| 981 |
-$(RM) $(REWRITTEN_SOURCES) $(foreach rs,$(REWRITTEN_SOURCES),$(rs).json) |
| 982 |
|
| 983 |
veryclean: clean |
| 984 |
-$(RM) -r report |
| 985 |
-$(RM) -r $(LOGDIR) $(GOTODIR) |
| 986 |
|
| 987 |
.PHONY: \ |
| 988 |
_coverage \ |
| 989 |
_goto \ |
| 990 |
_property \ |
| 991 |
_report \ |
| 992 |
_report_no_coverage \ |
| 993 |
clean \ |
| 994 |
coverage \ |
| 995 |
goto \ |
| 996 |
litani-path \ |
| 997 |
property \ |
| 998 |
report \ |
| 999 |
report-no-coverage \ |
| 1000 |
result \ |
| 1001 |
setup_dependencies \ |
| 1002 |
testdeps \ |
| 1003 |
veryclean \ |
| 1004 |
# |
| 1005 |
|
| 1006 |
################################################################ |
| 1007 |
|
| 1008 |
# Run "make echo-proof-uid" to print the proof ID of a proof. This can be |
| 1009 |
# used by scripts to ensure that every proof has an ID, that there are |
| 1010 |
# no duplicates, etc. |
| 1011 |
|
| 1012 |
.PHONY: echo-proof-uid |
| 1013 |
echo-proof-uid: |
| 1014 |
@echo $(PROOF_UID) |
| 1015 |
|
| 1016 |
.PHONY: echo-project-name |
| 1017 |
echo-project-name: |
| 1018 |
@echo $(PROJECT_NAME) |
| 1019 |
|
| 1020 |
################################################################ |
| 1021 |
|
| 1022 |
# Project-specific targets requiring values defined above |
| 1023 |
sinclude $(PROOF_ROOT)/Makefile-project-targets |
| 1024 |
|
| 1025 |
# CI-specific targets to drive cbmc in CI |
| 1026 |
sinclude $(PROOF_ROOT)/Makefile-project-testing |
| 1027 |
|
| 1028 |
################################################################ |