Skip to content

Commit 9415861

Browse files
authored
Add ASAN and UBSAN stages to CI, fix various errors [AP-1386] (#1403)
# Description @swift-nav/devinfra Add bazel config to build with ASAN, UBSAN, TSAN, or MSAN Add CI stages to run tests with ASAN and UBSAN. The other sanitizers aren't important to run regularly given the nature of code in this repository, but they exist for consistency with other projects and to enable manually running those sanitizer if required A couple of fixes to problems in code which were discovered by the sanitizer. No breaking changes though # API compatibility No ## API compatibility plan No # JIRA Reference https://swift-nav.atlassian.net/browse/AP-1386
1 parent 9e8203e commit 9415861

File tree

470 files changed

+34985
-9955
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

470 files changed

+34985
-9955
lines changed

.bazelrc

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,97 @@
1+
# Causes the build to default to the custom toolchain
2+
build --incompatible_enable_cc_toolchain_resolution
3+
14
build --action_env=BAZEL_CXXOPTS='-std=c++14'
25

36
build:clang-tidy --aspects @rules_swiftnav//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
47
build:clang-tidy --output_groups=report
8+
9+
# Shared sanitizer configuration
10+
common:sanitize -c dbg
11+
common:sanitize --cxxopt=-g3
12+
common:sanitize --copt=-g3
13+
common:sanitize --linkopt=-g3
14+
#common:sanitize --cxxopt=-O1
15+
#common:sanitize --copt=-O1
16+
#common:sanitize --linkopt=-O1
17+
common:sanitize --cxxopt=-fno-omit-frame-pointer
18+
common:sanitize --copt=-fno-omit-frame-pointer
19+
common:sanitize --linkopt=-fno-omit-frame-pointer
20+
common:sanitize --@rules_swiftnav//cc:enable_symbolizer=true
21+
22+
# Sanitizer overhead can cause some functions to become so large that
23+
# the compiler falls back to a linear register allocator. This
24+
# shouldn't cause a sanitizer build to fail.
25+
common:sanitize --cxxopt=-Wno-error=disabled-optimization
26+
common:sanitize --copt=-Wno-error=disabled-optimization
27+
common:sanitize --linkopt=-Wno-error=disabled-optimization
28+
# https://github.com/bazelbuild/bazel/issues/12797#issuecomment-980641064
29+
common:sanitize --linkopt='-fsanitize-link-c++-runtime'
30+
common:sanitize --cxxopt=-fPIC
31+
common:sanitize --copt=-fPIC
32+
common:sanitize --linkopt=-fPIC
33+
34+
# Address sanitizer
35+
common:asan --config=sanitize
36+
common:asan --cxxopt=-fsanitize=address
37+
common:asan --copt=-fsanitize=address
38+
common:asan --linkopt=-fsanitize=address
39+
common:asan --cxxopt=-fno-optimize-sibling-calls
40+
common:asan --copt=-fno-optimize-sibling-calls
41+
common:asan --linkopt=-fno-optimize-sibling-calls
42+
common:asan --platform_suffix=asan
43+
44+
# Undefined behavior sanitizer
45+
common:ubsan --config=sanitize
46+
common:ubsan --cxxopt=-fsanitize=undefined
47+
common:ubsan --copt=-fsanitize=undefined
48+
common:ubsan --linkopt=-fsanitize=undefined
49+
common:ubsan --cxxopt=-fno-sanitize-recover=all
50+
common:ubsan --copt=-fno-sanitize-recover=all
51+
common:ubsan --linkopt=-fno-sanitize-recover=all
52+
common:ubsan --cxxopt=-fsanitize=local-bounds
53+
common:ubsan --copt=-fsanitize=local-bounds
54+
common:ubsan --linkopt=-fsanitize=local-bounds
55+
common:ubsan --@rules_swiftnav//cc:enable_rtti=true
56+
# Unfortunately the current build setup doesn't seem to provide stack
57+
# frame names using clang++ and llvm-symbolizer. (This was also the
58+
# case in cmake, but the default of g++ there _did_ provide frame
59+
# names in backtraces.)
60+
test:ubsan --action_env="UBSAN_OPTIONS=print_stacktrace=1"
61+
run:ubsan --action_env="UBSAN_OPTIONS=print_stacktrace=1"
62+
# vptr sanitizer is horribly broken to the point of throwing false positives at a
63+
# rate that suppressions or an ignore list are impractical.
64+
common:ubsan --cxxopt=-fno-sanitize=vptr
65+
common:ubsan --linkopt=-fno-sanitize=vptr
66+
common:ubsan --platform_suffix=ubsan
67+
68+
# Dynamic memory sanitizer
69+
#
70+
# Warning: takes an incredible amount of space! Try testing only one
71+
# target at a time.
72+
common:msan --config=sanitize
73+
common:msan --cxxopt=-fsanitize=memory
74+
common:msan --copt=-fsanitize=memory
75+
common:msan --linkopt=-fsanitize=memory
76+
common:msan --cxxopt=-fsanitize-memory-track-origins=2
77+
common:msan --copt=-fsanitize-memory-track-origins=2
78+
common:msan --linkopt=-fsanitize-memory-track-origins=2
79+
common:msan --cxxopt=-fsanitize-memory-use-after-dtor
80+
common:msan --copt=-fsanitize-memory-use-after-dtor
81+
common:msan --linkopt=-fsanitize-memory-use-after-dtor
82+
common:msan --platform_suffix=msan
83+
84+
# > Currently, ThreadSanitizer symbolizes its output using an external
85+
# > addr2line process (this will be fixed in future).
86+
#
87+
# https://clang.llvm.org/docs/ThreadSanitizer.html#usage
88+
common:tsan --config=sanitize
89+
common:tsan --cxxopt=-fsanitize=thread
90+
common:tsan --copt=-fsanitize=thread
91+
common:tsan --linkopt=-fsanitize=thread
92+
common:tsan --platform_suffix=tsan
93+
94+
# Helpful aliases
95+
common:asan_ubsan --config=asan
96+
common:asan_ubsan --config=ubsan
97+
common:ubsan_asan --config=asan_ubsan

.github/workflows/c.yaml

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,60 @@ jobs:
140140
- uses: actions/checkout@v2
141141
with:
142142
submodules: recursive
143-
- name: Install Bazel
143+
144+
- uses: bazelbuild/setup-bazelisk@v2
145+
146+
- name: Mount bazel cache
147+
uses: actions/cache@v1
148+
with:
149+
path: "~/.cache/bazel"
150+
key: bazel
151+
152+
- name: Bazel Build & Test
144153
run: |
145-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.15.0/bazelisk-linux-amd64"
146-
mkdir -p "${GITHUB_WORKSPACE}/bin/"
147-
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
148-
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
154+
bazel test //...
155+
156+
157+
asan:
158+
name: ASAN
159+
runs-on: ubuntu-20.04
160+
steps:
161+
- uses: actions/checkout@v2
162+
with:
163+
submodules: recursive
164+
165+
- uses: bazelbuild/setup-bazelisk@v2
166+
167+
- name: Mount bazel cache
168+
uses: actions/cache@v1
169+
with:
170+
path: "~/.cache/bazel"
171+
key: bazel
172+
173+
- name: Bazel Build & Test
174+
run: |
175+
bazel test --config=asan //...
176+
177+
178+
ubsan:
179+
name: UBSAN
180+
runs-on: ubuntu-20.04
181+
steps:
182+
- uses: actions/checkout@v2
183+
with:
184+
submodules: recursive
185+
186+
- uses: bazelbuild/setup-bazelisk@v2
187+
188+
- name: Mount bazel cache
189+
uses: actions/cache@v1
190+
with:
191+
path: "~/.cache/bazel"
192+
key: bazel
193+
149194
- name: Bazel Build & Test
150195
run: |
151-
${GITHUB_WORKSPACE}/bin/bazel test //...
196+
bazel test --config=ubsan //...
152197
153198
154199
windows-2019:

WORKSPACE.bazel

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44

55
http_archive(
66
name = "rules_swiftnav",
7-
strip_prefix = "rules_swiftnav-82e89313fc0c2046a2b19d4a4da5167a88f5da3f",
8-
url = "https://github.com/swift-nav/rules_swiftnav/archive/82e89313fc0c2046a2b19d4a4da5167a88f5da3f.tar.gz",
7+
strip_prefix = "rules_swiftnav-cb82c790d50dd87f301df67b710161906dafb0c2",
8+
url = "https://github.com/swift-nav/rules_swiftnav/archive/cb82c790d50dd87f301df67b710161906dafb0c2.tar.gz",
99
)
1010

11+
load(
12+
"@rules_swiftnav//cc:repositories.bzl",
13+
"register_swift_cc_toolchains",
14+
"swift_cc_toolchain",
15+
)
16+
17+
swift_cc_toolchain()
18+
19+
register_swift_cc_toolchains()
20+
1121
http_archive(
1222
name = "rules_foreign_cc",
1323
strip_prefix = "rules_foreign_cc-c65e8cfbaa002bcd1ce9c26e9fec63b0b866c94b",

c/test/cpp/auto_check_sbp_acquisition_MsgAcqResult.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResult0 : public ::testing::Test {
340340
template <typename T,
341341
std::enable_if_t<std::is_integral<T>::value, bool> = true>
342342
void make_lesser_greater(T &lesser, T &greater) {
343-
if (greater == std::numeric_limits<T>::max()) {
343+
if (lesser > std::numeric_limits<T>::min()) {
344344
lesser--;
345345
} else {
346346
greater++;

c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepA.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepA0
346346
template <typename T,
347347
std::enable_if_t<std::is_integral<T>::value, bool> = true>
348348
void make_lesser_greater(T &lesser, T &greater) {
349-
if (greater == std::numeric_limits<T>::max()) {
349+
if (lesser > std::numeric_limits<T>::min()) {
350350
lesser--;
351351
} else {
352352
greater++;
@@ -1126,7 +1126,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepA1
11261126
template <typename T,
11271127
std::enable_if_t<std::is_integral<T>::value, bool> = true>
11281128
void make_lesser_greater(T &lesser, T &greater) {
1129-
if (greater == std::numeric_limits<T>::max()) {
1129+
if (lesser > std::numeric_limits<T>::min()) {
11301130
lesser--;
11311131
} else {
11321132
greater++;
@@ -1906,7 +1906,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepA2
19061906
template <typename T,
19071907
std::enable_if_t<std::is_integral<T>::value, bool> = true>
19081908
void make_lesser_greater(T &lesser, T &greater) {
1909-
if (greater == std::numeric_limits<T>::max()) {
1909+
if (lesser > std::numeric_limits<T>::min()) {
19101910
lesser--;
19111911
} else {
19121912
greater++;
@@ -2686,7 +2686,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepA3
26862686
template <typename T,
26872687
std::enable_if_t<std::is_integral<T>::value, bool> = true>
26882688
void make_lesser_greater(T &lesser, T &greater) {
2689-
if (greater == std::numeric_limits<T>::max()) {
2689+
if (lesser > std::numeric_limits<T>::min()) {
26902690
lesser--;
26912691
} else {
26922692
greater++;
@@ -3466,7 +3466,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepA4
34663466
template <typename T,
34673467
std::enable_if_t<std::is_integral<T>::value, bool> = true>
34683468
void make_lesser_greater(T &lesser, T &greater) {
3469-
if (greater == std::numeric_limits<T>::max()) {
3469+
if (lesser > std::numeric_limits<T>::min()) {
34703470
lesser--;
34713471
} else {
34723472
greater++;
@@ -4246,7 +4246,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepA5
42464246
template <typename T,
42474247
std::enable_if_t<std::is_integral<T>::value, bool> = true>
42484248
void make_lesser_greater(T &lesser, T &greater) {
4249-
if (greater == std::numeric_limits<T>::max()) {
4249+
if (lesser > std::numeric_limits<T>::min()) {
42504250
lesser--;
42514251
} else {
42524252
greater++;

c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepB.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepB0
348348
template <typename T,
349349
std::enable_if_t<std::is_integral<T>::value, bool> = true>
350350
void make_lesser_greater(T &lesser, T &greater) {
351-
if (greater == std::numeric_limits<T>::max()) {
351+
if (lesser > std::numeric_limits<T>::min()) {
352352
lesser--;
353353
} else {
354354
greater++;
@@ -1142,7 +1142,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepB1
11421142
template <typename T,
11431143
std::enable_if_t<std::is_integral<T>::value, bool> = true>
11441144
void make_lesser_greater(T &lesser, T &greater) {
1145-
if (greater == std::numeric_limits<T>::max()) {
1145+
if (lesser > std::numeric_limits<T>::min()) {
11461146
lesser--;
11471147
} else {
11481148
greater++;
@@ -1936,7 +1936,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepB2
19361936
template <typename T,
19371937
std::enable_if_t<std::is_integral<T>::value, bool> = true>
19381938
void make_lesser_greater(T &lesser, T &greater) {
1939-
if (greater == std::numeric_limits<T>::max()) {
1939+
if (lesser > std::numeric_limits<T>::min()) {
19401940
lesser--;
19411941
} else {
19421942
greater++;
@@ -2730,7 +2730,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepB3
27302730
template <typename T,
27312731
std::enable_if_t<std::is_integral<T>::value, bool> = true>
27322732
void make_lesser_greater(T &lesser, T &greater) {
2733-
if (greater == std::numeric_limits<T>::max()) {
2733+
if (lesser > std::numeric_limits<T>::min()) {
27342734
lesser--;
27352735
} else {
27362736
greater++;
@@ -3524,7 +3524,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepB4
35243524
template <typename T,
35253525
std::enable_if_t<std::is_integral<T>::value, bool> = true>
35263526
void make_lesser_greater(T &lesser, T &greater) {
3527-
if (greater == std::numeric_limits<T>::max()) {
3527+
if (lesser > std::numeric_limits<T>::min()) {
35283528
lesser--;
35293529
} else {
35303530
greater++;

c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepC.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepC0
348348
template <typename T,
349349
std::enable_if_t<std::is_integral<T>::value, bool> = true>
350350
void make_lesser_greater(T &lesser, T &greater) {
351-
if (greater == std::numeric_limits<T>::max()) {
351+
if (lesser > std::numeric_limits<T>::min()) {
352352
lesser--;
353353
} else {
354354
greater++;
@@ -1142,7 +1142,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepC1
11421142
template <typename T,
11431143
std::enable_if_t<std::is_integral<T>::value, bool> = true>
11441144
void make_lesser_greater(T &lesser, T &greater) {
1145-
if (greater == std::numeric_limits<T>::max()) {
1145+
if (lesser > std::numeric_limits<T>::min()) {
11461146
lesser--;
11471147
} else {
11481148
greater++;
@@ -1936,7 +1936,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepC2
19361936
template <typename T,
19371937
std::enable_if_t<std::is_integral<T>::value, bool> = true>
19381938
void make_lesser_greater(T &lesser, T &greater) {
1939-
if (greater == std::numeric_limits<T>::max()) {
1939+
if (lesser > std::numeric_limits<T>::min()) {
19401940
lesser--;
19411941
} else {
19421942
greater++;
@@ -2730,7 +2730,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepC3
27302730
template <typename T,
27312731
std::enable_if_t<std::is_integral<T>::value, bool> = true>
27322732
void make_lesser_greater(T &lesser, T &greater) {
2733-
if (greater == std::numeric_limits<T>::max()) {
2733+
if (lesser > std::numeric_limits<T>::min()) {
27342734
lesser--;
27352735
} else {
27362736
greater++;
@@ -3524,7 +3524,7 @@ class Testauto_check_sbp_acquisition_MsgAcqResultDepC4
35243524
template <typename T,
35253525
std::enable_if_t<std::is_integral<T>::value, bool> = true>
35263526
void make_lesser_greater(T &lesser, T &greater) {
3527-
if (greater == std::numeric_limits<T>::max()) {
3527+
if (lesser > std::numeric_limits<T>::min()) {
35283528
lesser--;
35293529
} else {
35303530
greater++;

c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfile.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class Testauto_check_sbp_acquisition_MsgAcqSvProfile0 : public ::testing::Test {
383383
template <typename T,
384384
std::enable_if_t<std::is_integral<T>::value, bool> = true>
385385
void make_lesser_greater(T &lesser, T &greater) {
386-
if (greater == std::numeric_limits<T>::max()) {
386+
if (lesser > std::numeric_limits<T>::min()) {
387387
lesser--;
388388
} else {
389389
greater++;

c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfileDep.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0
387387
template <typename T,
388388
std::enable_if_t<std::is_integral<T>::value, bool> = true>
389389
void make_lesser_greater(T &lesser, T &greater) {
390-
if (greater == std::numeric_limits<T>::max()) {
390+
if (lesser > std::numeric_limits<T>::min()) {
391391
lesser--;
392392
} else {
393393
greater++;

c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0
345345
template <typename T,
346346
std::enable_if_t<std::is_integral<T>::value, bool> = true>
347347
void make_lesser_greater(T &lesser, T &greater) {
348-
if (greater == std::numeric_limits<T>::max()) {
348+
if (lesser > std::numeric_limits<T>::min()) {
349349
lesser--;
350350
} else {
351351
greater++;

0 commit comments

Comments
 (0)