From 661b29283425c568d1fa403be703775e02c50d08 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 17 Nov 2020 16:50:36 -0800 Subject: [PATCH] egl: Skip closing drivers when building with AddressSanitizer. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If you dlclose your driver, the leak reports look like: #0 0xffff9c7e5e7c in malloc (/lib/aarch64-linux-gnu/libasan.so.6+0x9ee7c) #1 0xffff94aaaa48 () #2 0xffff94aa5ff4 () #3 0xffff94d1867c () #4 0xffff94d184f0 () #5 0xffff94c9a990 () #6 0xffff94c92e30 () #7 0xffff94c91d48 () #8 0xffff946eb800 (/home/anholt/src/mesa/build-aarch64-asan/src/egl/libEGL.so.1.0.0+0xfe800) #9 0xffff94c72874 () #10 0xffff946ede68 (/home/anholt/src/mesa/build-aarch64-asan/src/egl/libEGL.so.1.0.0+0x100e68) #11 0xffff94bf7134 () #12 0xffff9c686450 in dri2_create_screen ../src/egl/drivers/dri2/egl_dri2.c:1079 which is not terribly useful. Probe if we're building with asan and just skip closing the driver in the happy path (which seems to be the standard practice for loadable modules with this tool). Acked-by: Michel Dänzer Part-of: --- meson.build | 9 +++++++++ src/egl/drivers/dri2/egl_dri2.c | 7 +++++++ src/egl/meson.build | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index f828eb8..d866e73 100644 --- a/meson.build +++ b/meson.build @@ -1648,6 +1648,15 @@ else dep_valgrind = null_dep endif +# AddressSanitizer's leak reports need all the symbols to be present at exit to +# decode well, which runs afoul of our dlopen()/dlclose()ing of the DRI drivers. +# Set a flag so we can skip the dlclose for asan builds. +if ['address', 'address,undefined'].contains(get_option('b_sanitize')) + asan_c_args = ['-DBUILT_WITH_ASAN=1'] +else + asan_c_args = ['-DBUILT_WITH_ASAN=0'] +endif + # pthread stubs. Lets not and say we didn't if host_machine.system() == 'windows' diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 89fc1c8..d2febce 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -1237,8 +1237,15 @@ dri2_display_destroy(_EGLDisplay *disp) } if (dri2_dpy->fd >= 0) close(dri2_dpy->fd); + + /* Don't dlclose the driver when building with the address sanitizer, so you + * get good symbols from the leak reports. + */ +#if !BUILT_WITH_ASAN || defined(NDEBUG) if (dri2_dpy->driver) dlclose(dri2_dpy->driver); +#endif + free(dri2_dpy->driver_name); #ifdef HAVE_WAYLAND_PLATFORM diff --git a/src/egl/meson.build b/src/egl/meson.build index 69f9484..7a3fcdc 100644 --- a/src/egl/meson.build +++ b/src/egl/meson.build @@ -21,7 +21,7 @@ inc_egl = include_directories('.', 'main') inc_egl_dri2 = include_directories('drivers/dri2') -c_args_for_egl = [] +c_args_for_egl = [asan_c_args] link_for_egl = [] deps_for_egl = [] incs_for_egl = [inc_include, inc_src, inc_egl] -- 2.7.4