Skip to content

Commit 0b9fc21

Browse files
committed
Add UBSan build + test CI.
1 parent 7df33f0 commit 0b9fc21

File tree

2 files changed

+104
-59
lines changed

2 files changed

+104
-59
lines changed

.circleci/config.yml

Lines changed: 69 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,7 @@ defaults:
121121
no_output_timeout: 30m
122122
command: ./.circleci/soltest_all.sh
123123

124-
- run_cmdline_tests: &run_cmdline_tests
125-
name: command line tests
126-
no_output_timeout: 30m
127-
command: ./test/cmdlineTests.sh
128-
129-
- run_docs_pragma_min_version: &run_docs_pragma_min_version
130-
name: docs pragma version check
131-
command: ./scripts/docs_version_pragma_check.sh
132-
133-
- test_ubuntu1604_clang: &test_ubuntu1604_clang
134-
docker:
135-
- image: << pipeline.parameters.ubuntu-1604-clang-ossfuzz-docker-image >>
124+
- run_soltest_steps: &run_soltest_steps
136125
steps:
137126
- checkout
138127
- attach_workspace:
@@ -141,50 +130,57 @@ defaults:
141130
- store_test_results: *store_test_results
142131
- store_artifacts: *artifacts_test_results
143132

144-
- test_ubuntu2004_clang: &test_ubuntu2004_clang
145-
docker:
146-
- image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
133+
- run_soltest_all_steps: &run_soltest_all_steps
147134
steps:
148135
- checkout
149136
- attach_workspace:
150137
at: build
151-
- run: *run_soltest
138+
- run: *run_soltest_all
152139
- store_test_results: *store_test_results
153140
- store_artifacts: *artifacts_test_results
154141

155-
- test_ubuntu2004: &test_ubuntu2004
156-
docker:
157-
- image: << pipeline.parameters.ubuntu-2004-docker-image >>
158-
parallelism: 6
142+
- run_cmdline_tests: &run_cmdline_tests
143+
name: command line tests
144+
no_output_timeout: 30m
145+
command: ./test/cmdlineTests.sh
146+
147+
- run_cmdline_tests_steps: &run_cmdline_tests_steps
159148
steps:
160149
- checkout
161150
- attach_workspace:
162151
at: build
163-
- run: *run_soltest_all
152+
- run: *run_cmdline_tests
164153
- store_test_results: *store_test_results
165154
- store_artifacts: *artifacts_test_results
166155

156+
- run_docs_pragma_min_version: &run_docs_pragma_min_version
157+
name: docs pragma version check
158+
command: ./scripts/docs_version_pragma_check.sh
159+
160+
- test_ubuntu1604_clang: &test_ubuntu1604_clang
161+
docker:
162+
- image: << pipeline.parameters.ubuntu-1604-clang-ossfuzz-docker-image >>
163+
<<: *run_soltest_steps
164+
165+
- test_ubuntu2004_clang: &test_ubuntu2004_clang
166+
docker:
167+
- image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
168+
<<: *run_soltest_steps
169+
170+
- test_ubuntu2004: &test_ubuntu2004
171+
docker:
172+
- image: << pipeline.parameters.ubuntu-2004-docker-image >>
173+
parallelism: 6
174+
<<: *run_soltest_all_steps
175+
167176
- test_asan: &test_asan
168177
<<: *test_ubuntu2004
169-
steps:
170-
- checkout
171-
- attach_workspace:
172-
at: build
173-
- run:
174-
<<: *run_soltest
175-
- store_test_results: *store_test_results
176-
- store_artifacts: *artifacts_test_results
178+
<<: *run_soltest_steps
177179

178-
- test_asan_clang: &test_asan_clang
179-
<<: *test_ubuntu2004_clang
180-
steps:
181-
- checkout
182-
- attach_workspace:
183-
at: build
184-
- run:
185-
<<: *run_soltest
186-
- store_test_results: *store_test_results
187-
- store_artifacts: *artifacts_test_results
180+
- test_ubuntu2004_clang_cli: &test_ubuntu2004_clang_cli
181+
docker:
182+
- image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
183+
<<: *run_cmdline_tests_steps
188184

189185
# --------------------------------------------------------------------------
190186
# Workflow Templates
@@ -239,6 +235,11 @@ defaults:
239235
requires:
240236
- b_ubu_asan_clang
241237

238+
- workflow_ubuntu2004_ubsan_clang: &workflow_ubuntu2004_ubsan_clang
239+
<<: *workflow_trigger_on_tags
240+
requires:
241+
- b_ubu_ubsan_clang
242+
242243
- workflow_emscripten: &workflow_emscripten
243244
<<: *workflow_trigger_on_tags
244245
requires:
@@ -447,8 +448,7 @@ jobs:
447448
- store_artifacts: *artifacts_solc
448449
- persist_to_workspace: *artifacts_executables
449450

450-
451-
b_ubu_asan_clang: &build_ubuntu2004_clang
451+
b_ubu_asan_clang: &b_ubu_asan_clang
452452
docker:
453453
- image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
454454
environment:
@@ -462,6 +462,20 @@ jobs:
462462
- store_artifacts: *artifacts_solc
463463
- persist_to_workspace: *artifacts_executables
464464

465+
b_ubu_ubsan_clang: &b_ubu_ubsan_clang
466+
docker:
467+
- image: << pipeline.parameters.ubuntu-2004-clang-docker-image >>
468+
environment:
469+
CC: clang
470+
CXX: clang++
471+
CMAKE_OPTIONS: -DSANITIZE=undefined
472+
MAKEFLAGS: -j 3
473+
steps:
474+
- checkout
475+
- run: *run_build
476+
- store_artifacts: *artifacts_solc
477+
- persist_to_workspace: *artifacts_executables
478+
465479
b_ubu: &build_ubuntu2004
466480
resource_class: xlarge
467481
docker:
@@ -768,13 +782,7 @@ jobs:
768782
- image: << pipeline.parameters.ubuntu-2004-docker-image >>
769783
environment:
770784
TERM: xterm
771-
steps:
772-
- checkout
773-
- attach_workspace:
774-
at: build
775-
- run: *run_cmdline_tests
776-
- store_test_results: *store_test_results
777-
- store_artifacts: *artifacts_test_results
785+
<<: *run_cmdline_tests_steps
778786

779787
t_ubu_release_cli: &t_ubu_release_cli
780788
<<: *t_ubu_cli
@@ -784,14 +792,7 @@ jobs:
784792
environment:
785793
TERM: xterm
786794
ASAN_OPTIONS: check_initialization_order=true:detect_stack_use_after_return=true:strict_init_order=true:strict_string_checks=true:detect_invalid_pointer_pairs=2
787-
steps:
788-
- checkout
789-
- attach_workspace:
790-
at: build
791-
- run:
792-
<<: *run_cmdline_tests
793-
- store_test_results: *store_test_results
794-
- store_artifacts: *artifacts_test_results
795+
<<: *run_cmdline_tests_steps
795796

796797
t_ubu_asan_constantinople:
797798
<<: *test_asan
@@ -802,13 +803,19 @@ jobs:
802803
ASAN_OPTIONS: check_initialization_order=true:detect_stack_use_after_return=true:strict_init_order=true:strict_string_checks=true:detect_invalid_pointer_pairs=2
803804

804805
t_ubu_asan_constantinople_clang:
805-
<<: *test_asan_clang
806+
<<: *test_ubuntu2004_clang
806807
environment:
807808
EVM: constantinople
808809
OPTIMIZE: 0
809810
SOLTEST_FLAGS: --no-smt
810811
ASAN_OPTIONS: check_initialization_order=true:detect_stack_use_after_return=true:strict_init_order=true:strict_string_checks=true:detect_invalid_pointer_pairs=2
811812

813+
t_ubu_ubsan_clang:
814+
<<: *test_ubuntu2004_clang
815+
816+
t_ubu_ubsan_clang_cli:
817+
<<: *test_ubuntu2004_clang_cli
818+
812819
t_ems_solcjs:
813820
docker:
814821
- image: << pipeline.parameters.ubuntu-2004-docker-image >>
@@ -1208,6 +1215,11 @@ workflows:
12081215
- t_ubu_asan_constantinople_clang: *workflow_ubuntu2004_asan_clang
12091216
- t_ubu_asan_cli: *workflow_ubuntu2004_asan
12101217

1218+
# UBSan build and tests
1219+
- b_ubu_ubsan_clang: *workflow_trigger_on_tags
1220+
- t_ubu_ubsan_clang: *workflow_ubuntu2004_ubsan_clang
1221+
- t_ubu_ubsan_clang_cli: *workflow_ubuntu2004_ubsan_clang
1222+
12111223
# Emscripten build and tests that take more than 15 minutes to execute
12121224
- b_ems: *workflow_trigger_on_tags
12131225
- t_ems_ext:

cmake/EthCompilerSettings.cmake

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,44 @@ endif ()
192192

193193
if (SANITIZE)
194194
# Perform case-insensitive string compare
195-
string(TOLOWER "${SANITIZE}" san)
195+
string(TOLOWER "${SANITIZE}" sanitizer)
196196
# -fno-omit-frame-pointer gives more informative stack trace in case of an error
197197
# -fsanitize-address-use-after-scope throws an error when a variable is used beyond its scope
198-
if (san STREQUAL "address")
198+
if (sanitizer STREQUAL "address")
199199
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope")
200+
elseif (sanitizer STREQUAL "undefined")
201+
# The following flags not used by fuzzer but used by us may create problems, so consider
202+
# disabling them: alignment, pointer-overflow, unsigned-shift-base.
203+
# Flags are alphabetically sorted
204+
list(APPEND undefinedSanitizerChecks
205+
alignment
206+
array-bounds
207+
bool
208+
builtin
209+
enum
210+
float-divide-by-zero
211+
function
212+
integer-divide-by-zero
213+
null
214+
object-size
215+
pointer-overflow
216+
return
217+
returns-nonnull-attribute
218+
shift
219+
signed-integer-overflow
220+
unsigned-integer-overflow
221+
unsigned-shift-base
222+
unreachable
223+
vla-bound
224+
vptr
225+
)
226+
list(JOIN undefinedSanitizerChecks "," sanitizerChecks)
227+
list(REMOVE_ITEM undefinedSanitizerChecks unsigned-integer-overflow)
228+
# The fuzzer excludes reports of unsigned-integer-overflow. Hence, we remove it
229+
# from the -fno-sanitize-recover checks. Consider reducing this list if we do not
230+
# want to be notified about other failed checks.
231+
list(JOIN undefinedSanitizerChecks "," dontRecoverFromChecks)
232+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${sanitizerChecks} -fno-sanitize-recover=${dontRecoverFromChecks}")
200233
endif()
201234
endif()
202235

0 commit comments

Comments
 (0)