@@ -149,6 +149,7 @@ $(objpfx)memusage: memusage.sh
# The implementation uses `dlsym'
$(objpfx)libmemusage.so: $(common-objpfx)dlfcn/libdl.so
+$(objpfx)tst-mallocstate: $(common-objpfx)dlfcn/libdl.so
# Extra dependencies
$(foreach o,$(all-object-suffixes),$(objpfx)malloc$(o)): arena.c hooks.c
@@ -474,6 +474,8 @@ struct malloc_save_state
unsigned long narenas;
};
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_20)
+
void *
__malloc_get_state (void)
{
@@ -644,6 +646,7 @@ __malloc_set_state (void *msptr)
(void) mutex_unlock (&main_arena.mutex);
return 0;
}
+#endif
/*
* Local variables:
@@ -5181,9 +5181,16 @@ strong_alias (__libc_mallopt, __mallopt) weak_alias (__libc_mallopt, mallopt)
weak_alias (__malloc_stats, malloc_stats)
weak_alias (__malloc_usable_size, malloc_usable_size)
weak_alias (__malloc_trim, malloc_trim)
+
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_20)
+
weak_alias (__malloc_get_state, malloc_get_state)
weak_alias (__malloc_set_state, malloc_set_state)
+compat_symbol (libc, malloc_get_state, malloc_get_state, GLIBC_2_0);
+compat_symbol (libc, malloc_set_state, malloc_set_state, GLIBC_2_0);
+
+#endif
/* ------------------------------------------------------------
History:
@@ -16,9 +16,16 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#define _GNU_SOURCE
+#include <dlfcn.h>
#include <errno.h>
#include <stdio.h>
#include "malloc.h"
+#include <abi-versions.h>
+
+#define STRINGIFY(x) #x
+#define STR_GLIBC_2_0 STRINGIFY (VERSION_libc_GLIBC_2_0)
+
static int errors = 0;
@@ -36,6 +43,12 @@ main (void)
void *save_state;
long i;
+ void *(*malloc_get_state)();
+ void *(*malloc_set_state)(void ());
+
+ malloc_get_state = dlvsym (RTLD_NEXT, "malloc_get_state", STR_GLIBC_2_0);
+ malloc_set_state = dlvsym (RTLD_NEXT, "malloc_set_state", STR_GLIBC_2_0);
+
errno = 0;
p1 = malloc (10);