Skip to content

Commit 5ac4f08

Browse files
authored
build: add support for Clang with Address Sanitizer. (#265)
Signed-off-by: Piotr Sikora <[email protected]>
1 parent 4f7306a commit 5ac4f08

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

.bazelrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ build:clang --action_env=BAZEL_COMPILER=clang
88
build:clang --action_env=CC=clang
99
build:clang --action_env=CXX=clang++
1010

11+
# Use Clang compiler with Address and Undefined Behavior Sanitizers.
12+
build:clang-asan --config=clang
13+
build:clang-asan --copt -DADDRESS_SANITIZER=1
14+
build:clang-asan --copt -DUNDEFINED_SANITIZER=1
15+
build:clang-asan --copt -O1
16+
build:clang-asan --copt -fno-omit-frame-pointer
17+
build:clang-asan --copt -fno-optimize-sibling-calls
18+
build:clang-asan --copt -fsanitize=address,undefined
19+
build:clang-asan --copt -fsanitize-address-use-after-scope
20+
build:clang-asan --linkopt -fsanitize=address,undefined
21+
build:clang-asan --linkopt -fsanitize-address-use-after-scope
22+
build:clang-asan --linkopt -fsanitize-link-c++-runtime
23+
build:clang-asan --linkopt -fuse-ld=lld
24+
build:clang-asan --test_env=ASAN_OPTIONS=check_initialization_order=1:detect_stack_use_after_return=1:strict_init_order=1:strict_string_checks=1
25+
build:clang-asan --test_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1
26+
build:clang-asan --test_env=ASAN_SYMBOLIZER_PATH
27+
28+
# Use Clang compiler with Address and Undefined Behavior Sanitizers (strict version).
29+
build:clang-asan-strict --config=clang-asan
30+
build:clang-asan-strict --copt -fsanitize=integer
31+
build:clang-asan-strict --linkopt -fsanitize=integer
32+
1133
# Use GCC compiler.
1234
build:gcc --action_env=BAZEL_COMPILER=gcc
1335
build:gcc --action_env=CC=gcc

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ jobs:
9696
arch: x86_64
9797
action: test
9898
flags: --config=gcc
99+
- name: 'NullVM on Linux/x86_64 with ASan'
100+
engine: 'null'
101+
os: ubuntu-20.04
102+
arch: x86_64
103+
action: test
104+
flags: --config=clang-asan-strict --define=crypto=system
99105
- name: 'NullVM on Windows/x86_64'
100106
engine: 'null'
101107
os: windows-2019
@@ -109,6 +115,14 @@ jobs:
109115
action: test
110116
flags: --config=clang --define=crypto=system
111117
cache: true
118+
- name: 'V8 on Linux/x86_64 with ASan'
119+
engine: 'v8'
120+
repo: 'v8'
121+
os: ubuntu-20.04
122+
arch: x86_64
123+
action: test
124+
flags: --config=clang-asan
125+
cache: true
112126
- name: 'V8 on Linux/aarch64'
113127
engine: 'v8'
114128
repo: 'v8'
@@ -145,6 +159,13 @@ jobs:
145159
arch: x86_64
146160
action: test
147161
flags: --config=clang
162+
- name: 'Wasmtime on Linux/x86_64 with ASan'
163+
engine: 'wasmtime'
164+
repo: 'com_github_bytecodealliance_wasmtime'
165+
os: ubuntu-20.04
166+
arch: x86_64
167+
action: test
168+
flags: --config=clang-asan-strict --define=crypto=system
148169
- name: 'Wasmtime on Linux/aarch64'
149170
engine: 'wasmtime'
150171
repo: 'com_github_bytecodealliance_wasmtime'

test/runtime_test.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ TEST_P(TestVM, CloneUntilOutOfMemory) {
107107
ASSERT_TRUE(vm_->load(source, {}, {}));
108108
ASSERT_TRUE(vm_->link(""));
109109

110+
size_t max_clones = 100000;
111+
#if defined(__has_feature)
112+
#if __has_feature(address_sanitizer)
113+
max_clones = 1000;
114+
#endif
115+
#endif
116+
110117
std::vector<std::unique_ptr<WasmVm>> clones;
111-
for (;;) {
118+
for (size_t i = 0; i < max_clones; i++) {
112119
auto clone = vm_->clone();
113120
if (clone == nullptr) {
114121
break;

0 commit comments

Comments
 (0)