[v1.2] Deprecate malloc_(sg)et state.
diff mbox

Message ID 20140428110349.GA23227@domone.podge
State New
Headers show

Commit Message

Ondřej Bílka April 28, 2014, 11:03 a.m. UTC
On Mon, Mar 24, 2014 at 03:15:50PM -0700, Roland McGrath wrote:
> > As I want to move forward with this patch I deleted this testcase and
> > when plumbing will be available I will restore it from git history. Is
> > that ok?
> 
> Nope.  We're not going to reduce our test coverage for some unknown period
> waiting for work that nobody has volunteered to do.  If deprecating this
> interface is a priority for you, then make the ability to test deprecated
> interfaces a priority for you or someone.

Here is new version. I simply used dlvsym to get these symbols.

	
	* malloc/malloc.c: Make malloc_get_state and malloc_set_state
	compatibility symbols.
	* malloc/hooks.c: Likewise.
	* malloc/tst-mallocstate.c (main): Use dynamic loader to get
	 malloc_get_state and malloc_set_state symbols.
	* malloc/Makefile: Link tst-mallocstate with libdl.

Comments

Joseph Myers April 28, 2014, 2:55 p.m. UTC | #1
On Mon, 28 Apr 2014, Ondrej Bilka wrote:

> +  malloc_get_state = dlvsym (RTLD_NEXT, "malloc_get_state", "GLIBC_2.2.5");
> +  malloc_set_state = dlvsym (RTLD_NEXT, "malloc_set_state", "GLIBC_2.2.5");

That's not correct.  GLIBC_2.2.5 is what GLIBC_2.0 maps to on x86_64, but 
on other architectures it maps to other versions; you need the correct 
version depending on the architecture.
Ondřej Bílka April 28, 2014, 3 p.m. UTC | #2
On Mon, Apr 28, 2014 at 02:55:18PM +0000, Joseph S. Myers wrote:
> On Mon, 28 Apr 2014, Ondrej Bilka wrote:
> 
> > +  malloc_get_state = dlvsym (RTLD_NEXT, "malloc_get_state", "GLIBC_2.2.5");
> > +  malloc_set_state = dlvsym (RTLD_NEXT, "malloc_set_state", "GLIBC_2.2.5");
> 
> That's not correct.  GLIBC_2.2.5 is what GLIBC_2.0 maps to on x86_64, but 
> on other architectures it maps to other versions; you need the correct 
> version depending on the architecture.
> 
Any macro for that?
Joseph Myers April 28, 2014, 3:07 p.m. UTC | #3
On Mon, 28 Apr 2014, Ondrej Bilka wrote:

> On Mon, Apr 28, 2014 at 02:55:18PM +0000, Joseph S. Myers wrote:
> > On Mon, 28 Apr 2014, Ondrej Bilka wrote:
> > 
> > > +  malloc_get_state = dlvsym (RTLD_NEXT, "malloc_get_state", "GLIBC_2.2.5");
> > > +  malloc_set_state = dlvsym (RTLD_NEXT, "malloc_set_state", "GLIBC_2.2.5");
> > 
> > That's not correct.  GLIBC_2.2.5 is what GLIBC_2.0 maps to on x86_64, but 
> > on other architectures it maps to other versions; you need the correct 
> > version depending on the architecture.
> > 
> Any macro for that?

Try stringizing the expansion of VERSION_libc_GLIBC_2_0 from 
abi-versions.h.

Patch
diff mbox

diff --git a/malloc/Makefile b/malloc/Makefile
index 2871726..00d0e2c 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -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
diff --git a/malloc/hooks.c b/malloc/hooks.c
index 00ee6be..442983e 100644
--- a/malloc/hooks.c
+++ b/malloc/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:
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 1120d4d..575a241 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -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:
diff --git a/malloc/tst-mallocstate.c b/malloc/tst-mallocstate.c
index 69c4500..247bd22 100644
--- a/malloc/tst-mallocstate.c
+++ b/malloc/tst-mallocstate.c
@@ -16,6 +16,8 @@ 
    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"
@@ -36,6 +38,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", "GLIBC_2.2.5");
+  malloc_set_state = dlvsym (RTLD_NEXT, "malloc_set_state", "GLIBC_2.2.5");
+
   errno = 0;
 
   p1 = malloc (10);