Skip to content

Commit

Permalink
PS-8103: Do not unload dynamic libraries in an ASAN build
Browse files Browse the repository at this point in the history
Issue: address sanitizer and valgrind can't resolve stack traces inside
plugins and components. The reason behind this is that MySQL unloads
dynamic libraries loaded dynamically during shutdown, making the code
inaccessible to the sanitizers.

This also means that suppressions do not work inside components and
plugins, if the suppression involves a step in the stacktrace which is
inside the plugin/component.

Fix: add a conditional around dlunload to remove it from asan/valgrind
builds.
  • Loading branch information
dutow committed Mar 7, 2022
1 parent d191e63 commit 5ae4d27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/libminchassis/dynamic_loader_scheme_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <mysql/components/services/mysql_rwlock.h>
#include <mysqld_error.h>

#include "my_config.h"
#ifndef _WIN32
#include <dlfcn.h>
#endif
Expand Down Expand Up @@ -215,7 +216,12 @@ DEFINE_BOOL_METHOD(mysql_dynamic_loader_scheme_file_imp::unload,
mysql_unload_plugin(it->first.c_str());

/* Close library and delete entry from libraries list. */
#if !defined(HAVE_VALGRIND) && !defined(HAVE_ASAN)
/*
* Avoid closing components under ASAN / Valgrind in order to get
* meaningfull leak report */
dlclose(it->second);
#endif
object_files_list.erase(it);
return false;
} catch (...) {
Expand Down
5 changes: 5 additions & 0 deletions sql/sql_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,12 @@ static inline void free_plugin_mem(st_plugin_dl *p) {
PSI_SYSTEM_CALL(unload_plugin)
(std::string(p->dl.str, p->dl.length).c_str());
#endif
#if !defined(HAVE_VALGRIND) && !defined(HAVE_ASAN)
/*
* Avoid closing components under ASAN / Valgrind in order to get
* meaningfull leak report */
dlclose(p->handle);
#endif
}
my_free(p->dl.str);
if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION) my_free(p->plugins);
Expand Down

0 comments on commit 5ae4d27

Please sign in to comment.