summaryrefslogtreecommitdiffstats
path: root/configure.ac
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2022-10-13 08:04:14 +0300
committerGitHub <noreply@github.com>2022-10-13 08:04:14 +0300
commit2974f525ec703329ef6ad079d8f6c685cfab11ad (patch)
treeb0e289a5fee787d764ee37cb8b5c2ac7bcd1bd20 /configure.ac
parentc805a9afad71ac96e703d599cbd6f54c29142ca7 (diff)
overload libc memory allocators with custom ones to trace all allocations (#13810)
* overload libc memory allocators with custom ones to trace all allocations * grab libc pointers for external c plugins * use -ldl when necessary; fallback to work without dlsym when it is not available * initialize global variable * add optional dl libs * dynamically link every library function when needed for the first time * prevent crashes on musl libc * another attempt * dont dereference function * attempt no 3 * attempt no 4 * cleanup - all attempts failed * dont enable tracing of allocations * missing parenthesis
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac26
1 files changed, 26 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 327cbb6c7a..68f1c8c742 100644
--- a/configure.ac
+++ b/configure.ac
@@ -269,6 +269,8 @@ if test "${enable_accept4}" != "no"; then
AC_CHECK_FUNCS_ONCE(accept4)
fi
+AC_CHECK_FUNCS_ONCE(malloc_usable_size)
+
# -----------------------------------------------------------------------------
# operating system detection
@@ -1529,6 +1531,30 @@ AC_SUBST([OPTIONAL_ATOMIC_LIBS])
AC_LANG_POP([C++])
+# -----------------------------------------------------------------------------
+
+AC_MSG_CHECKING(whether we can use dlsym)
+OLD_LIBS="${LIBS}"
+LIBS="-ldl"
+AC_LINK_IFELSE([AC_LANG_SOURCE([[
+ #include <dlfcn.h>
+ static void *(*libc_malloc)(size_t);
+ int main() {
+ libc_malloc = dlsym(RTLD_NEXT, "malloc");
+ }
+]])], CAN_USE_DLSYM=yes, CAN_USE_DLSYM=no)
+LIBS="${OLD_LIBS}"
+AC_MSG_RESULT($CAN_USE_DLSYM)
+
+if test "x$CAN_USE_DLSYM" = xyes; then
+ AC_DEFINE([HAVE_DLSYM], [1], [dlsym usability])
+ OPTIONAL_DL_LIBS="-ldl"
+fi
+AC_SUBST([OPTIONAL_DL_LIBS])
+
+# -----------------------------------------------------------------------------
+
+
AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged])
varlibdir="${localstatedir}/lib/netdata"