@@ -204,6 +204,57 @@ make cov
204
204
# A coverage report will now be accessible at `./test_bitcoin.coverage/index.html`.
205
205
```
206
206
207
+ ** Sanitizers**
208
+
209
+ Bitcoin can be compiled with various "sanitizers" enabled, which add
210
+ instrumentation for issues regarding things like memory safety, thread race
211
+ conditions, or undefined behavior. This is controlled with the
212
+ ` --with-sanitizers ` configure flag, which should be a comma separated list of
213
+ sanitizers to enable. The sanitizer list should correspond to supported
214
+ ` -fsanitize= ` options in your compiler. These sanitizers have runtime overhead,
215
+ so they are most useful when testing changes or producing debugging builds.
216
+
217
+ Some examples:
218
+
219
+ ``` bash
220
+ # Enable both the address sanitizer and the undefined behavior sanitizer
221
+ ./configure --with-sanitizers=address,undefined
222
+
223
+ # Enable the thread sanitizer
224
+ ./configure --with-sanitizers=thread
225
+ ```
226
+
227
+ If you are compiling with GCC you will typically need to install corresponding
228
+ "san" libraries to actually compile with these flags, e.g. libasan for the
229
+ address sanitizer, libtsan for the thread sanitizer, and libubsan for the
230
+ undefined sanitizer. If you are missing required libraries, the configure script
231
+ will fail with a linker error when testing the sanitizer flags.
232
+
233
+ The test suite should pass cleanly with the ` thread ` and ` undefined ` sanitizers,
234
+ but there are a number of known problems when using the ` address ` sanitizer. The
235
+ address sanitizer is known to fail in
236
+ [ sha256_sse4::Transform] ( /src/crypto/sha256_sse4.cpp ) which makes it unusable
237
+ unless you also use ` --disable-asm ` when running configure. We would like to fix
238
+ sanitizer issues, so please send pull requests if you can fix any errors found
239
+ by the address sanitizer (or any other sanitizer).
240
+
241
+ Not all sanitizer options can be enabled at the same time, e.g. trying to build
242
+ with ` --with-sanitizers=address,thread ` will fail in the configure script as
243
+ these sanitizers are mutually incompatible. Refer to your compiler manual to
244
+ learn more about these options and which sanitizers are supported by your
245
+ compiler.
246
+
247
+ Additional resources:
248
+
249
+ * [ AddressSanitizer] ( https://clang.llvm.org/docs/AddressSanitizer.html )
250
+ * [ LeakSanitizer] ( https://clang.llvm.org/docs/LeakSanitizer.html )
251
+ * [ MemorySanitizer] ( https://clang.llvm.org/docs/MemorySanitizer.html )
252
+ * [ ThreadSanitizer] ( https://clang.llvm.org/docs/ThreadSanitizer.html )
253
+ * [ UndefinedBehaviorSanitizer] ( https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html )
254
+ * [ GCC Instrumentation Options] ( https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html )
255
+ * [ Google Sanitizers Wiki] ( https://github.com/google/sanitizers/wiki )
256
+ * [ Issue #12691 : Enable -fsanitize flags in Travis] ( https://github.com/bitcoin/bitcoin/issues/12691 )
257
+
207
258
Locking/mutex usage notes
208
259
-------------------------
209
260
0 commit comments