This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] malloc: create aliases for malloc, free,...


Our version explicitly uses the dl prefix, so dlmalloc, dlfree, etc.
But if you want to DL_PRELOAD our version to replace libc malloc, you
need actual malloc, free, etc. to be defined.

And while at it, remove the old broken aliasing under !PURE_HACK.

JIRA: PURE-42344
https://codereviews.purestorage.com/r/23673/
---
 tpc/malloc2.13/malloc.c | 52 +++++++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 30 deletions(-)

diff --git a/tpc/malloc2.13/malloc.c b/tpc/malloc2.13/malloc.c
index 439c1247fe99..2e3067344ad2 100644
--- a/tpc/malloc2.13/malloc.c
+++ b/tpc/malloc2.13/malloc.c
@@ -1102,14 +1102,12 @@ Void_t*  public_gET_STATe(void);
 */
 int      public_sET_STATe(Void_t*);
 
-#if defined(PURE_HACK)
 /*
   posix_memalign(void **memptr, size_t alignment, size_t size);
 
   POSIX wrapper like memalign(), checking for validity of size.
 */
 int      dlposix_memalign(void **, size_t, size_t);
-#endif
 
 /* mallopt tuning options */
 
@@ -5393,8 +5391,7 @@ malloc_printerr(int action, const char *str, void *ptr)
 }
 #endif
 
-#if defined(PURE_HACK)
-# include <sys/param.h>
+#include <sys/param.h>
 
 /* We need a wrapper function for one of the additions of POSIX.  */
 int
@@ -5427,10 +5424,6 @@ dlposix_memalign (void **memptr, size_t alignment, size_t size)
   return ENOMEM;
 }
 
-#ifndef PURE_HACK
-weak_alias (__posix_memalign, posix_memalign)
-#endif
-
 int
 dlmalloc_info (int options, FILE *fp)
 {
@@ -5614,28 +5607,27 @@ dlmalloc_info (int options, FILE *fp)
   return 0;
 }
 
-#ifndef PURE_HACK
-strong_alias (__libc_calloc, __calloc) weak_alias (__libc_calloc, calloc)
-strong_alias (__libc_free, __cfree) weak_alias (__libc_free, cfree)
-strong_alias (__libc_free, __free) strong_alias (__libc_free, free)
-strong_alias (__libc_malloc, __malloc) strong_alias (__libc_malloc, malloc)
-strong_alias (__libc_memalign, __memalign)
-weak_alias (__libc_memalign, memalign)
-strong_alias (__libc_realloc, __realloc) strong_alias (__libc_realloc, realloc)
-strong_alias (__libc_valloc, __valloc) weak_alias (__libc_valloc, valloc)
-strong_alias (__libc_pvalloc, __pvalloc) weak_alias (__libc_pvalloc, pvalloc)
-strong_alias (__libc_mallinfo, __mallinfo)
-weak_alias (__libc_mallinfo, mallinfo)
-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)
-weak_alias (__malloc_get_state, malloc_get_state)
-weak_alias (__malloc_set_state, malloc_set_state)
-#endif
-
-#endif /* _LIBC */
+# define strong_alias(name, aliasname) \
+	extern __typeof(name) aliasname __attribute__((alias(#name)))
+
+strong_alias(dlcalloc, calloc);
+strong_alias(dlfree, free);
+strong_alias(dlcfree, cfree);
+strong_alias(dlmalloc, malloc);
+strong_alias(dlmemalign, memalign);
+strong_alias(dlrealloc, realloc);
+strong_alias(dlvalloc, valloc);
+strong_alias(dlpvalloc, pvalloc);
+strong_alias(dlmallinfo, mallinfo);
+strong_alias(dlmallopt, mallopt);
+strong_alias(dlmalloc_trim, malloc_trim);
+strong_alias(dlmalloc_stats, malloc_stats);
+strong_alias(dlmalloc_usable_size, malloc_usable_size);
+strong_alias(dlindependent_calloc, independent_calloc);
+strong_alias(dlindependent_comalloc, independent_comalloc);
+strong_alias(dlget_state, get_state);
+strong_alias(dlset_state, set_state);
+strong_alias(dlposix_memalign, posix_memalign);
 
 /* ------------------------------------------------------------
 History:
-- 
2.7.0.rc3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]