mirror of
git://sourceware.org/git/glibc.git
synced 2026-09-08 23:58:31 +08:00
malloc: aarch64: Add ifuncs for malloc functions
Introduce ifuncs and resolvers for functions pertinent to the malloc interface on the AArch64 target: malloc, calloc, free, realloc, memalign, valloc, pvalloc, posix_memalign, aligned_alloc, free_sized, free_aligned_sized, malloc_usable_size. A target can define the USE_MULTIARCH_MALLOC macro. In this case it must provide alternative aliases for the malloc functions that point to the ifuncs. This implementation respects the --disable-multi-arch configure flag. If multi-arch support is disabled, the generic aliases are used on aarch64. This patch contains aarch64-specific resolvers. At this point they return core implementations but in the future they can be changed to support for features, e.g. to handle memory tagging. Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <hugepages.h>
|
||||
#include <calloc-clear-memory.h>
|
||||
#include <malloc-api.h>
|
||||
#include <malloc-ifuncs.h>
|
||||
|
||||
/* Called in the parent process before a fork. */
|
||||
void __malloc_fork_lock_parent (void) attribute_hidden;
|
||||
|
||||
+9
-2
@@ -5168,6 +5168,9 @@ __malloc_info (int options, FILE *fp)
|
||||
}
|
||||
|
||||
#if IS_IN (libc)
|
||||
|
||||
/* See sysdeps/generic/malloc-ifuncs.h for details. */
|
||||
# if !USE_MULTIARCH_MALLOC
|
||||
strong_alias (__libc_malloc, malloc)
|
||||
strong_alias (__libc_realloc, realloc)
|
||||
strong_alias (__libc_free, free)
|
||||
@@ -5180,6 +5183,7 @@ weak_alias (__malloc_usable_size, malloc_usable_size)
|
||||
weak_alias (__aligned_alloc, aligned_alloc)
|
||||
weak_alias (__free_sized, free_sized)
|
||||
weak_alias (__free_aligned_sized, free_aligned_sized)
|
||||
#endif /* !USE_MULTIARCH_MALLOC */
|
||||
|
||||
weak_alias (__malloc_info, malloc_info)
|
||||
weak_alias (__libc_mallinfo, mallinfo)
|
||||
@@ -5187,11 +5191,14 @@ weak_alias (__libc_mallinfo2, mallinfo2)
|
||||
weak_alias (__libc_mallopt, mallopt)
|
||||
weak_alias (__malloc_stats, malloc_stats)
|
||||
weak_alias (__malloc_trim, malloc_trim)
|
||||
|
||||
#endif /* IS_IN (libc) */
|
||||
|
||||
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_26)
|
||||
#if !USE_MULTIARCH_MALLOC
|
||||
# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_26)
|
||||
compat_symbol (libc, __libc_free, cfree, GLIBC_2_0);
|
||||
#endif
|
||||
# endif
|
||||
#endif /* !USE_MULTIARCH_MALLOC */
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
History:
|
||||
|
||||
@@ -20,3 +20,9 @@ sysdep_routines += \
|
||||
strlen_generic \
|
||||
# sysdep_routines
|
||||
endif # ifeq ($(subdir),string)
|
||||
|
||||
ifeq ($(subdir),malloc)
|
||||
sysdep_routines += \
|
||||
malloc-ifuncs \
|
||||
# sysdep_routines
|
||||
endif # ifeq ($(subdir),malloc)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/* Code for ifunc resolvers for malloc: aarch64 version.
|
||||
Copyright (C) 2026 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "malloc-ifuncs.h"
|
||||
|
||||
#if USE_MULTIARCH_MALLOC
|
||||
# if IS_IN (libc)
|
||||
|
||||
#include <init-arch.h>
|
||||
#include <malloc-api.h>
|
||||
#include <shlib-compat.h>
|
||||
|
||||
libc_ifunc_hidden (__libc_malloc, __libc_malloc_redirect,
|
||||
__libc_malloc)
|
||||
strong_alias (__libc_malloc_redirect, malloc)
|
||||
|
||||
libc_ifunc_hidden (__libc_calloc, __libc_calloc_redirect,
|
||||
__libc_calloc)
|
||||
weak_alias (__libc_calloc_redirect, calloc)
|
||||
|
||||
libc_ifunc_hidden (__libc_memalign, __libc_memalign_redirect,
|
||||
__libc_memalign)
|
||||
weak_alias (__libc_memalign_redirect, memalign)
|
||||
|
||||
libc_ifunc_hidden (__libc_valloc, __libc_valloc_redirect,
|
||||
__libc_valloc)
|
||||
weak_alias (__libc_valloc_redirect, valloc)
|
||||
|
||||
libc_ifunc_hidden (__libc_pvalloc, __libc_pvalloc_redirect,
|
||||
__libc_pvalloc)
|
||||
weak_alias (__libc_pvalloc_redirect, pvalloc)
|
||||
|
||||
libc_ifunc_hidden (__libc_realloc, __libc_realloc_redirect,
|
||||
__libc_realloc)
|
||||
strong_alias (__libc_realloc_redirect, realloc)
|
||||
|
||||
libc_ifunc_hidden (__libc_free, __libc_free_redirect,
|
||||
__libc_free)
|
||||
strong_alias (__libc_free_redirect, free)
|
||||
|
||||
libc_ifunc_hidden (__malloc_usable_size, __malloc_usable_size_redirect,
|
||||
__malloc_usable_size)
|
||||
weak_alias (__malloc_usable_size_redirect, malloc_usable_size)
|
||||
|
||||
libc_ifunc_hidden (__posix_memalign, __posix_memalign_redirect,
|
||||
__posix_memalign)
|
||||
weak_alias (__posix_memalign_redirect, posix_memalign)
|
||||
|
||||
libc_ifunc_hidden (__aligned_alloc, __aligned_alloc_redirect,
|
||||
__aligned_alloc)
|
||||
weak_alias (__aligned_alloc_redirect, aligned_alloc)
|
||||
|
||||
libc_ifunc_hidden (__free_sized, __free_sized_redirect,
|
||||
__free_sized)
|
||||
weak_alias (__free_sized_redirect, free_sized)
|
||||
|
||||
libc_ifunc_hidden (__free_aligned_sized, __free_aligned_sized_redirect,
|
||||
__free_aligned_sized)
|
||||
weak_alias (__free_aligned_sized_redirect, free_aligned_sized)
|
||||
|
||||
# endif /* IS_IN (libc) */
|
||||
|
||||
# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_26)
|
||||
compat_symbol (libc, __libc_free_redirect, cfree, GLIBC_2_0);
|
||||
# endif
|
||||
|
||||
#endif /* #if USE_MULTIARCH_MALLOC */
|
||||
@@ -0,0 +1,25 @@
|
||||
/* Definitions for ifunc resolvers for malloc: aarch64 version.
|
||||
Copyright (C) 2026 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _AARCH64_MALLOC_IFUNCS_H
|
||||
#define _AARCH64_MALLOC_IFUNCS_H
|
||||
|
||||
/* AArch64 target provides ifuncs for malloc functions. */
|
||||
#define USE_MULTIARCH_MALLOC 1
|
||||
|
||||
#endif /* _AARCH64_MALLOC_IFUNCS_H */
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Definitions for ifunc resolvers for malloc: generic version.
|
||||
Copyright (C) 2026 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _GENERIC_MALLOC_IFUNCS_H
|
||||
#define _GENERIC_MALLOC_IFUNCS_H
|
||||
|
||||
/* Targets that support GNU ifuncs should define this macro
|
||||
if they provide ifuncs for malloc functions.
|
||||
|
||||
When USE_MULTIARCH_MALLOC is defined as 1, the following
|
||||
functions should be implemented via ifuncs:
|
||||
|
||||
malloc, calloc, free, realloc
|
||||
memalign, valloc, pvalloc
|
||||
posix_memalign
|
||||
malloc_usable_size
|
||||
aligned_alloc, free_sized, free_aligned_sized
|
||||
*/
|
||||
#define USE_MULTIARCH_MALLOC 0
|
||||
|
||||
#endif /* _GENERIC_MALLOC_IFUNCS_H */
|
||||
Reference in New Issue
Block a user