summaryrefslogtreecommitdiff
path: root/libgcompat/malloc.c
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-14 18:40:59 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-14 18:57:52 -0600
commitdfafb0735f09d65a392d03a2d1ad3d0b934981da (patch)
treef5a1c49f22df2e72494cd114785763b111d6924a /libgcompat/malloc.c
parentd40369b0e09e4e2228ebff305067ec2d99220848 (diff)
downloadgcompat-dfafb0735f09d65a392d03a2d1ad3d0b934981da.tar.gz
gcompat-dfafb0735f09d65a392d03a2d1ad3d0b934981da.tar.bz2
gcompat-dfafb0735f09d65a392d03a2d1ad3d0b934981da.tar.xz
gcompat-dfafb0735f09d65a392d03a2d1ad3d0b934981da.zip
libgcompat: Add and use a macro for defining symbol aliases
* Prefer providing the underscore-prefixed symbol as the strong definition. * Do not use a weak alias if the alias is also underscore-prefixed. * Make libgcompat objects depend on the new header. [NOTE: I originally took the weak_alias macro from musl's libc.h, but it's trivial and the same pattern already in use. If desired, I can add the musl copyright notice.] Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'libgcompat/malloc.c')
-rw-r--r--libgcompat/malloc.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/libgcompat/malloc.c b/libgcompat/malloc.c
index db85d8d..dc9d25e 100644
--- a/libgcompat/malloc.c
+++ b/libgcompat/malloc.c
@@ -27,6 +27,8 @@
#include <stdlib.h> /* {m,c,re}alloc, free */
#include <string.h> /* memset */
+#include "alias.h" /* alias */
+
struct mallinfo {
int arena; /* Non-mmapped space allocated (bytes) */
int ordblks; /* Number of free chunks */
@@ -51,31 +53,27 @@ void *__libc_malloc(size_t size)
{
return malloc(size);
}
+alias(__libc_malloc, __malloc);
void __libc_free(void *ptr)
{
return free(ptr);
}
+alias(__libc_free, __free);
void *__libc_calloc(size_t nmemb, size_t size)
{
return calloc(nmemb, size);
}
+alias(__libc_calloc, __calloc);
void *__libc_realloc(void *ptr, size_t size)
{
return realloc(ptr, size);
}
+alias(__libc_realloc, __realloc);
void *__libc_memalign(size_t align, size_t len)
{
return memalign(align, len);
}
-
-extern __typeof(__libc_malloc) __malloc
- __attribute__((weak, alias("__libc_malloc")));
-extern __typeof(__libc_calloc) __calloc
- __attribute__((weak, alias("__libc_calloc")));
-extern __typeof(__libc_realloc) __realloc
- __attribute__((weak, alias("__libc_realloc")));
-extern __typeof(__libc_free) __free __attribute__((weak, alias("__libc_free")));