build: enable AddressSanitizer
[dpdk.git] / doc / guides / prog_guide / asan.rst
1 .. SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2021 Intel Corporation
3
4 Running AddressSanitizer
5 ========================
6
7 `AddressSanitizer
8 <https://github.com/google/sanitizers/wiki/AddressSanitizer>`_ (ASan)
9 is a widely-used debugging tool to detect memory access errors.
10 It helps to detect issues like use-after-free, various kinds of buffer
11 overruns in C/C++ programs, and other similar errors, as well as
12 printing out detailed debug information whenever an error is detected.
13
14 AddressSanitizer is a part of LLVM (3.1+) and GCC (4.8+).
15
16 Enabling ASan is done by passing the -Db_sanitize=address option to the meson build system,
17 see :ref:`linux_gsg_compiling_dpdk` for details.
18
19 The way ASan is integrated with clang requires to allow undefined symbols when linking code.
20 To do this, the -Db_lundef=false option must be added.
21
22 Additionally, passing -Dbuildtype=debug option might help getting more readable ASan reports.
23
24 Example::
25
26   - gcc: meson setup -Db_sanitize=address <build_dir>
27   - clang: meson setup -Db_sanitize=address -Db_lundef=false <build_dir>
28
29 .. Note::
30
31   - The libasan package must be installed when compiling with gcc in Centos/RHEL.
32   - If the program is tested using cmdline, you may need to execute the
33     "stty echo" command when an error occurs.