Skip to content

Commit 9fa277e

Browse files
committed
bazel: address PR feedback on sanitizers and debug docs
1 parent 9204232 commit 9fa277e

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

.bazelrc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ common:dbg-symbols \
165165
common:asan \
166166
--copt=-fsanitize=address \
167167
--copt=-fno-omit-frame-pointer \
168-
--linkopt=-fsanitize=address
168+
--linkopt=-fsanitize=address \
169+
--config=dbg-symbols
169170

170171
# Configuration: 'asan-static'
171172
# AddressSanitizer with static libasan linkage.
@@ -174,7 +175,8 @@ common:asan-static \
174175
--copt=-fsanitize=address \
175176
--copt=-fno-omit-frame-pointer \
176177
--linkopt=-fsanitize=address \
177-
--linkopt=-static-libasan
178+
--linkopt=-static-libasan \
179+
--config=dbg-symbols
178180

179181

180182
# Configuration: 'tsan'
@@ -184,7 +186,8 @@ common:asan-static \
184186
common:tsan \
185187
--copt=-fsanitize=thread \
186188
--copt=-fno-omit-frame-pointer \
187-
--linkopt=-fsanitize=thread
189+
--linkopt=-fsanitize=thread \
190+
--config=dbg-symbols
188191

189192

190193
# Configuration: 'ubsan'
@@ -194,7 +197,8 @@ common:tsan \
194197
common:ubsan \
195198
--copt=-fsanitize=undefined \
196199
--copt=-fno-omit-frame-pointer \
197-
--linkopt=-fsanitize=undefined
200+
--linkopt=-fsanitize=undefined \
201+
--config=dbg-symbols
198202

199203

200204
# =============================================================================
@@ -206,3 +210,21 @@ common:ubsan \
206210
# Or persist in user-local ~/.bazelrc:
207211
# build --copt=-your-flag
208212
# =============================================================================
213+
214+
# Configuration: 'msan'
215+
# MemorySanitizer build.
216+
# Note: Requires Clang or ICPX. GCC does not support MSan.
217+
# bazel test //cpp/oneapi/dal:tests --config=msan
218+
common:msan \
219+
--copt=-fsanitize=memory \
220+
--copt=-fno-omit-frame-pointer \
221+
--linkopt=-fsanitize=memory \
222+
--config=dbg-symbols
223+
224+
# Configuration: 'type'
225+
# Type sanitizer build.
226+
common:type \
227+
--copt=-fsanitize=type \
228+
--copt=-fno-omit-frame-pointer \
229+
--linkopt=-fsanitize=type \
230+
--config=dbg-symbols

dev/bazel/README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ bazel build //:release --config=dbg-symbols
400400

401401
### AddressSanitizer (ASan)
402402

403-
Equivalent to Make `REQSAN=address`. Recommended to combine with `--config=dbg`:
403+
Equivalent to Make `REQSAN=address`. Sanitizers do not automatically enable assertions or unoptimized debug builds. It is highly recommended to combine them with `--config=dbg` (for full debug + assertions) or `--enable_assert=True`:
404404

405405
```sh
406406
bazel test //cpp/oneapi/dal:tests --config=asan --config=dbg
@@ -428,13 +428,20 @@ Equivalent to Make `REQSAN=undefined`:
428428
bazel test //cpp/oneapi/dal:tests --config=ubsan
429429
```
430430

431-
> Note: Not all compilers support all sanitizers. There is currently no
432-
> `--config=msan` preset. To use MemorySanitizer, use a compiler that supports
433-
> it (icpx or clang) and pass flags manually:
434-
> ```sh
435-
> bazel test //cpp/oneapi/dal:tests --copt=-fsanitize=memory --linkopt=-fsanitize=memory
436-
> ```
437-
> GCC does not support MemorySanitizer and will fail by design.
431+
### MemorySanitizer (MSan)
432+
433+
Requires Clang or ICPX. GCC does not support MSan.
434+
435+
```sh
436+
bazel test //cpp/oneapi/dal:tests --config=msan
437+
```
438+
439+
### Type Sanitizer
440+
441+
```sh
442+
bazel test //cpp/oneapi/dal:tests --config=type
443+
```
444+
438445

439446
---
440447

@@ -463,6 +470,16 @@ bazel build //:release --config=release-dpc
463470

464471
---
465472

473+
### Standard Library Assertions
474+
475+
To enable C++ standard library assertions (e.g., `std::vector` bounds checking), inject the preprocessor macro via `--copt`:
476+
477+
```sh
478+
bazel test //cpp/oneapi/dal:tests --config=dbg --copt=-D_GLIBCXX_DEBUG
479+
```
480+
481+
---
482+
466483
## Custom Compiler and Linker Flags
467484

468485
Equivalent to Make `COPT` / `CXXFLAGS`. Pass via `--copt` and `--linkopt`:
@@ -498,6 +515,8 @@ build --linkopt=-your-link-flag
498515
| `REQSAN=static` | `--config=asan-static` | ASan with static libasan |
499516
| `REQSAN=thread` | `--config=tsan` | ThreadSanitizer |
500517
| `REQSAN=undefined` | `--config=ubsan` | UBSan |
518+
| | `--config=msan` | MemorySanitizer (Clang/ICPX only) |
519+
| | `--config=type` | Type Sanitizer |
501520
| `COMPILER=gnu` | `CC=gcc bazel build ...` | Override compiler via `CC` env |
502521
| `OPTFLAG=O2` | `--copt=-O2` | Override optimization level |
503522
| `COPT=-flag` | `--copt=-flag` | Arbitrary compiler flag |

0 commit comments

Comments
 (0)