Add --enable-asan configure option
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 14 May 2021 14:23:19 +0000 (10:23 -0400)
committerMichael Jeanson <mjeanson@efficios.com>
Fri, 12 Nov 2021 18:40:01 +0000 (13:40 -0500)
commit0b0893d4a069f17d1326ebc3bfc9f9f987f411f3
tree274a88e27754cc0faaad9334bacf4655caacb24c
parent82338bfd24b995ca7b5224f54f1a245d906d517e
Add --enable-asan configure option

It's possible to build babeltrace with AddressSanitizer by adding
-fsanitize=address to CFLAGS/LDFLAGS, but it causes some issues.  These
issues are related to the fact that if libasan.so is to be loaded, it
must be the first library to be loaded.  When a Python interpreter loads
the bt2 module, that pulls in libbabeltrace2.so, which pulls libasan.so.
libasan.so then complains about not being the first loaded libraries.
The only way I know to fix this is to LD_PRELOAD libasan.so in the
Python interpreter.

The first case where this happens is when building the Python bindings.
This is because the Sphinx tool (so, the Python interpreter) loads the
bt2 Python module in order to obtain the documentation.

The other case is when running the Python bindings tests, the test
runner is in Python, and the .py tests imports the bt2 module.

In both cases, libasan unfortunately finds some leaks in the Python
interpreter.  We must therefore disable leak reporting with
ASAN_OPTIONS=detect_leaks=0.  This is particularly unfortunate for the
Python bindings tests, because it would be nice to know about leaks that
are libbabeltrace2's or the tests' fault.  But I don't see any way
around it.  For running Sphinx, we don't care about leaks.

Since we need to set some special environment variables when building
and checking if AddressSanitizer is used, it's much easier if the build
system knows that we want to use AddressSanitizer.  This patch therefore
adds a new `--enable-asan` option that developers should use in order to
use AddressSanitizer, instead of manually adding -fsanitize=address in
CFLAGS/LDFLAGS.

If `--enable-asan` is used, the following command will be invoked :

  $(CC) -print-file-name=libasan.so

... to find the path of the libasan.so library associated to the
compiler being used (it's important that we pre-load the right version
of libasan.so).

For the Python bindings documentation generation, the command is used in
the Makefile where Sphinx is invoked.

For tests, a boolean is written in a generated tests/utils/env.sh file,
which is sourced by tests/utils/utils.sh and the command is then used
when running the tests.

Change-Id: I5e0ca10532605cfdfda08b3ee4fcc39922480797
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/5860
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
15 files changed:
configure.ac
doc/bindings/python/Makefile.am
src/bindings/python/bt2/Makefile.am
src/cli/Makefile.am
src/compat/Makefile.am
src/ctf-writer/Makefile.am
src/lib/Makefile.am
src/plugins/ctf/Makefile.am
src/plugins/lttng-utils/Makefile.am
src/plugins/text/Makefile.am
src/plugins/utils/Makefile.am
src/python-plugin-provider/Makefile.am
tests/lib/test-plugin-plugins/Makefile.am
tests/utils/env.sh.in
tests/utils/utils.sh
This page took 0.026255 seconds and 4 git commands to generate.