Skip to content

Commit 7dd51a3

Browse files
authored
Merge pull request diffblue#203 from diffblue/feature/cmake
SEC-62 : Introducing CMAKE build system for security-analyser and removal of Makefile system.
2 parents 06fcd4f + 8123fc9 commit 7dd51a3

39 files changed

+374
-338
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ src/goto-analyzer/taint_driver_scripts/.idea/*
1111
/*.creator.user
1212
/*.files
1313
/*.includes
14-
security-scanner/.idea
15-
security-scanner/*.pyc
14+
driver/.idea
15+
driver/*.pyc
16+
build
17+
dist
1618

1719
# Ignoring boost
1820
boost/*

.travis.yml

+38-51
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ jobs:
3939
- libubsan0
4040
before_install:
4141
- mkdir bin ; ln -s /usr/bin/gcc-5 bin/gcc
42-
# env: COMPILER=g++-5 SAN_FLAGS="-fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer"
43-
env: COMPILER="ccache g++-5"
42+
env:
43+
- COMPILER="g++-5"
44+
- BUILD_TYPE="Release"
45+
- RUN_CBMC_TESTS="true"
46+
- RUN_SECURITY_TESTS="true"
4447

4548
# LOCAL CHANGES: Added 'ant' to the OSX package list (needed by security-scanner regression tests)
4649

@@ -55,7 +58,11 @@ jobs:
5558
- mkdir bin ; ln -s /usr/bin/gcc bin/gcc
5659
- HOMEBREW_NO_AUTO_UPDATE=1 brew install ccache ant
5760
- export PATH=/usr/local/opt/ccache/libexec:$PATH
58-
env: COMPILER="ccache g++"
61+
env:
62+
- COMPILER="g++"
63+
- BUILD_TYPE="Release"
64+
- RUN_CBMC_TESTS="true"
65+
- RUN_SECURITY_TESTS="true"
5966

6067
# OS X using clang++
6168
- stage: Test different OS/CXX/Flags
@@ -67,12 +74,16 @@ jobs:
6774
- HOMEBREW_NO_AUTO_UPDATE=1 brew install ccache ant
6875
- export PATH=/usr/local/opt/ccache/libexec:$PATH
6976
env:
70-
- COMPILER="ccache clang++ -Qunused-arguments -fcolor-diagnostics"
77+
- COMPILER="clang++"
78+
- BUILD_TYPE="Release"
79+
- RUN_CBMC_TESTS="true"
80+
- RUN_SECURITY_TESTS="true"
7181
- CCACHE_CPP2=yes
7282

7383
# Ubuntu Linux with glibc using g++-5, debug mode
7484
- stage: Test different OS/CXX/Flags
7585
os: linux
86+
dist: trusty
7687
sudo: false
7788
compiler: gcc
7889
cache: ccache
@@ -82,19 +93,24 @@ jobs:
8293
- ubuntu-toolchain-r-test
8394
packages:
8495
- libwww-perl
96+
- libthread-pool-simple-perl
8597
- g++-5
8698
- libubsan0
99+
- parallel
87100
before_install:
88101
- mkdir bin ; ln -s /usr/bin/gcc-5 bin/gcc
89-
# env: COMPILER=g++-5 SAN_FLAGS="-fsanitize=undefined -fno-sanitize-recover -fno-omit-frame-pointer"
90102
env:
91-
- COMPILER="ccache g++-5"
92-
- EXTRA_CXXFLAGS="-DDEBUG"
93-
script: echo "Not running any tests for a debug build."
103+
- COMPILER="g++-5"
104+
- BUILD_TYPE="Debug"
105+
- RUN_CBMC_TESTS="false"
106+
- RUN_SECURITY_TESTS="true"
107+
- OS="ubuntu"
108+
- TEST_MODELS_LIB="false"
94109

95110
# Ubuntu Linux with glibc using clang++-3.7
96111
- stage: Test different OS/CXX/Flags
97112
os: linux
113+
dist: trusty
98114
sudo: false
99115
compiler: clang
100116
cache: ccache
@@ -105,16 +121,21 @@ jobs:
105121
- llvm-toolchain-precise-3.7
106122
packages:
107123
- libwww-perl
124+
- libthread-pool-simple-perl
108125
- clang-3.7
109126
- libstdc++-5-dev
110127
- libubsan0
128+
- parallel
111129
before_install:
112130
- mkdir bin ; ln -s /usr/bin/clang-3.7 bin/gcc
113131
- export CCACHE_CPP2=yes
114-
# env: COMPILER=clang++-3.7 SAN_FLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined,integer -fno-omit-frame-pointer"
115132
env:
116-
- COMPILER="ccache clang++-3.7 -Qunused-arguments -fcolor-diagnostics"
133+
- COMPILER="clang++-3.7"
134+
- BUILD_TYPE="Release"
135+
- RUN_CBMC_TESTS="true"
136+
- RUN_SECURITY_TESTS="true"
117137
- CCACHE_CPP2=yes
138+
- OS="ubuntu"
118139

119140
# Ubuntu Linux with glibc using clang++-3.7, debug mode
120141
- stage: Test different OS/CXX/Flags
@@ -135,39 +156,12 @@ jobs:
135156
before_install:
136157
- mkdir bin ; ln -s /usr/bin/clang-3.7 bin/gcc
137158
- export CCACHE_CPP2=yes
138-
# env: COMPILER=clang++-3.7 SAN_FLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined,integer -fno-omit-frame-pointer"
139159
env:
140-
- COMPILER="ccache clang++-3.7 -Qunused-arguments -fcolor-diagnostics"
160+
- COMPILER="clang++-3.7"
161+
- BUILD_TYPE="Debug"
162+
- RUN_CBMC_TESTS="false"
163+
- RUN_SECURITY_TESTS="true"
141164
- CCACHE_CPP2=yes
142-
- EXTRA_CXXFLAGS="-DDEBUG"
143-
script: echo "Not running any tests for a debug build."
144-
145-
- stage: Test different OS/CXX/Flags
146-
os: linux
147-
cache: ccache
148-
env:
149-
- BUILD_SYSTEM=cmake
150-
addons:
151-
apt:
152-
sources:
153-
- ubuntu-toolchain-r-test
154-
packages:
155-
- g++-5
156-
install:
157-
- cmake -Hcbmc -Bcbmc/build '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=g++-5'
158-
- cmake --build cbmc/build -- -j4
159-
script: (cd cbmc/build; ctest -V -L CORE)
160-
161-
- stage: Test different OS/CXX/Flags
162-
os: osx
163-
cache: ccache
164-
env:
165-
- BUILD_SYSTEM=cmake
166-
- CCACHE_CPP2=yes
167-
install:
168-
- cmake -Hcbmc -Bcbmc/build '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_OSX_ARCHITECTURES=x86_64'
169-
- cmake --build cbmc/build -- -j4
170-
script: (cd cbmc/build; ctest -V -L CORE)
171165

172166

173167
allow_failures:
@@ -178,20 +172,13 @@ jobs:
178172

179173
install:
180174
- ccache --max-size=1G
181-
- make -C cbmc/src minisat2-download
182-
- make -C cbmc/src boost-download
183-
- make -C cbmc/src/ansi-c library_check
184-
- make -C src "CXX=${COMPILER}" "CXXFLAGS=-Wall -Werror -pedantic -O2 -g -DUSE_BOOST ${EXTRA_CXXFLAGS}" -j2
185-
- make -C cbmc/src "CXX=${COMPILER}" "CXXFLAGS=-Wall -Werror -pedantic -O2 -g ${EXTRA_CXXFLAGS}" -j2 goto-analyzer.dir goto-cc.dir goto-diff.dir clobber.dir memory-models.dir
175+
- cmake . -Bbuild "-DCMAKE_CXX_COMPILER=${COMPILER}" "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" "-Denable_security_tests=${RUN_SECURITY_TESTS}" "-Denable_cbmc_tests=${RUN_CBMC_TESTS}"
176+
- ( cd build; make install )
186177

187178
# LOCAL CHANGES: Added cbmc/ prefix, and added unit and regression tests to the end of the list.
188179

189180
script:
190-
- if [ -e bin/gcc ] ; then export PATH=$PWD/bin:$PATH ; fi ;
191-
- env UBSAN_OPTIONS=print_stacktrace=1 make -C cbmc/regression test "CXX=${COMPILER}" "CXXFLAGS=-Wall -Werror -pedantic -O2 -g ${EXTRA_CXXFLAGS}"
192-
- make -C cbmc/unit "CXX=${COMPILER}" "CXXFLAGS=-Wall -Werror -pedantic -O2 -g ${EXTRA_CXXFLAGS}" -j2
193-
- make -C cbmc/unit test
194-
- make -C unit test "CXX=${COMPILER}" "CXXFLAGS=-Wall -Werror -pedantic -O2 -g -DUSE_BOOST ${EXTRA_CXXFLAGS}"
181+
- ( cd build; ctest -V -L CORE )
195182
- scripts/travis_run_regression_tests.sh
196183

197184
before_cache:

CMakeLists.txt

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
cmake_minimum_required(VERSION 3.2)
2+
3+
project(security-scanner)
4+
5+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
6+
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/dist" CACHE PATH "Specify the installation directory for the security-scanner." FORCE)
7+
endif()
8+
9+
if(NOT CMAKE_BUILD_TYPE)
10+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug, Release, RelWithDebInfo, MinSizeRel." FORCE)
11+
endif()
12+
13+
find_program(CCACHE_PROGRAM ccache)
14+
if(CCACHE_PROGRAM)
15+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
16+
message(STATUS "Rule launch compile: ${CCACHE_PROGRAM}")
17+
endif()
18+
19+
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
20+
21+
include(GNUInstallDirs)
22+
23+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
24+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
25+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
26+
27+
set(custom_cxx_flags "" CACHE STRING "Extra flags used to build CXX files")
28+
29+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
30+
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
31+
)
32+
# Ensure NDEBUG is not set for release builds
33+
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
34+
# Enable lots of warnings
35+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror")
36+
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
37+
# This would be the place to enable warnings for Windows builds, although
38+
# config.inc doesn't seem to do that currently
39+
endif()
40+
41+
set(CMAKE_CXX_STANDARD 11)
42+
set(CMAKE_CXX_STANDARD_REQUIRED true)
43+
44+
set(CMAKE_EXPORT_COMPILE_COMMANDS true)
45+
46+
set(enable_security_tests on CACHE BOOL "Whether tests of the security analyser should be enabled.")
47+
set(enable_cbmc_tests off CACHE BOOL "Whether CBMC tests should be enabled (the default is to enable just test-gen tests)")
48+
49+
################################################################################
50+
# BOOST
51+
52+
set(boost_include_root_dir "${CMAKE_CURRENT_SOURCE_DIR}/cbmc/boost-include" )
53+
set(boost_include_package_download_dir "${boost_include_root_dir}/download" )
54+
set(boost_include_package_name "boost_1.63_headers.tar.bz2" )
55+
set(boost_include_package_URL "http://storage.googleapis.com/diffblue-mirror/boost/boost_1.63_headers.tar.bz2?GoogleAccessId=diffbluemaster@diffblue-cr.iam.gserviceaccount.com&Expires=1542631994&Signature=X2GwPSm1dR8IPGP0D5JoyDmOnL%2Br4F7AI7NUA7SbmOAowMC0JS7Q5A6%2BkQziUzQa88zpddr5gSRbDOLqdoGzwLrYgPNtURS5dJ7l1q6xfJWSS%2FYf8be%2FSbdfLVN8qcXKCsfDe05Hqf%2Bz2cksqjQ1H6L0syj43rftbW4%2F7tp355%2BkinCeE466ulJeyru3CK%2F3RGX2Ul6ZQV6lNxkit1m6QM5BRtLbUQ1GOW0GCK9fWH2fry2n7kRVBCM3oz8fX62kLdKYlaXCf%2BvvXs9hOOmcQurL%2Fa4DCJYoClX%2BpznqXVmjUY%2FI3pD4HlRKbCeiPnoC6de2i1uxFNSVTBpG3w%2BtfA%3D%3D" )
56+
set(boost_include_include_dir "${boost_include_root_dir}")
57+
if (NOT EXISTS "${boost_include_package_download_dir}/${boost_include_package_name}")
58+
file(DOWNLOAD "${boost_include_package_URL}" "${boost_include_package_download_dir}/${boost_include_package_name}")
59+
endif()
60+
61+
include(ExternalProject)
62+
ExternalProject_Add(boost-include
63+
PREFIX "${boost_include_root_dir}"
64+
SOURCE_DIR "${boost_include_include_dir}/boost"
65+
URL "${boost_include_package_download_dir}/${boost_include_package_name}"
66+
CONFIGURE_COMMAND ""
67+
BUILD_COMMAND ""
68+
INSTALL_COMMAND ""
69+
)
70+
71+
################################################################################
72+
73+
add_subdirectory(cbmc)
74+
add_subdirectory(benchmarks/LIBRARIES/models)
75+
76+
add_subdirectory(src)
77+
78+
if(${enable_security_tests})
79+
enable_testing()
80+
endif()
81+
add_subdirectory(unit)
82+
add_subdirectory(regression)
83+
84+
install(FILES "./security-analyser.md" DESTINATION doc)
85+
install(FILES "./security-analyser-driver.py" DESTINATION bin)
86+
install(DIRECTORY "./driver" DESTINATION lib FILES_MATCHING PATTERN "*.py")

benchmarks/evaluator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __evaluate_benchmark(record):
135135

136136
# Now we can run the security-scanner on the installed benchmark
137137
command = (
138-
"python \"" + os.path.join(__get_my_dir(), "..", "security-scanner", "run.py") + "\" " +
138+
"python \"" + os.path.join(__get_my_dir(), "..", "dist", "lib", "driver", "run.py") + "\" " +
139139
"-C \"" + os.path.join(__get_my_dir(), record["rules-file"]) + "\" " +
140140
"-I \"" + os.path.join(__get_my_dir(), record["install-dir"]) + "\" " +
141141
"-R \"" + os.path.join(__get_my_dir(), record["results-dir"]) + "\" " +

cbmc/src/goto-instrument/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ add_if_library(goto-instrument-lib glpk)
3434
# Executable
3535
add_executable(goto-instrument goto_instrument_main.cpp)
3636
target_link_libraries(goto-instrument goto-instrument-lib)
37+
38+
install(TARGETS goto-instrument DESTINATION bin)

cbmc/src/symex/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ add_if_library(symex-lib php)
3333
add_executable(symex symex_main.cpp)
3434

3535
target_link_libraries(symex symex-lib)
36+
37+
install(TARGETS symex DESTINATION bin)
File renamed without changes.

security-scanner/analyser.py renamed to driver/analyser.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ def __get_my_dir(): return os.path.dirname(os.path.realpath(__file__))
88

99

1010
def get_security_analyser_pathname():
11-
return os.path.abspath(os.path.join(__get_my_dir(), "../src/driver/security-analyzer"))
11+
return os.path.abspath(os.path.join(__get_my_dir(), "../../bin/security-analyzer"))
1212

1313
def get_goto_instrument_pathname():
14-
return os.path.abspath(os.path.join(__get_my_dir(), "../cbmc/src/goto-instrument/goto-instrument"))
14+
return os.path.abspath(os.path.join(__get_my_dir(), "../../bin/goto-instrument"))
1515

1616
def get_cbmc_pathname():
17-
return os.path.abspath(os.path.join(__get_my_dir(), "../cbmc/src/cbmc/cbmc"))
17+
return os.path.abspath(os.path.join(__get_my_dir(), "../../bin/cbmc"))
1818

1919
def get_symex_pathname():
20-
return os.path.abspath(os.path.join(__get_my_dir(), "../cbmc/src/symex/symex"))
20+
return os.path.abspath(os.path.join(__get_my_dir(), "../../bin/symex"))
2121

2222

2323
def run_security_analyser(
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

regression/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# We do not have any regression test so far.
2+

scripts/travis_run_regression_tests.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ if [[ "$CBMC_ALPINE_BUILD" == "yes" ]]; then
77
exit 0
88
fi
99

10-
make -C $THISDIR/.. regression
10+
python $THISDIR/../benchmarks/evaluator.py
11+

security-analyser-driver.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# TODO: this script should only forwrad its input to the driver script.
2+
# Implement it! Until then, this script is bypassed by the evaluator.

security-analyser.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: add guide how to use the security-analyser product!

src/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project(SECURITY_ANALYSER)
2+
3+
# Set the public include locations for a target.
4+
macro(generic_includes name)
5+
target_include_directories(${name}
6+
PUBLIC
7+
${SECURITY_ANALYSER_BINARY_DIR}
8+
${SECURITY_ANALYSER_SOURCE_DIR}
9+
${CMAKE_CURRENT_BINARY_DIR}
10+
${CMAKE_CURRENT_SOURCE_DIR}
11+
${CBMC_SOURCE_DIR}
12+
${boost_include_include_dir}
13+
)
14+
endmacro(generic_includes)
15+
16+
17+
add_subdirectory(driver)
18+
add_subdirectory(pointer-analysis)
19+
add_subdirectory(summaries)
20+
add_subdirectory(taint-analysis)
21+
add_subdirectory(taint-slicer)
22+
add_subdirectory(util)
23+

src/Makefile

-37
This file was deleted.

0 commit comments

Comments
 (0)