[PATCH v6 0/1] aarch64: Add ifuncs for malloc functions

Yury Khrustalev yury.khrustalev@arm.com
Wed Jun 10 12:45:16 GMT 2026


See commit message for details. In a nutshell, we want to add ifuncs
for the functions related to the malloc API (on targets that support
ifuncs). This will allow to add alternative (e.g. target-specific)
implementations or wrappers for these functions.

This patch introduces ifuncs for malloc functions for aarch64 in
multiarch mode.

I've checked it with gdb and lldb as well as with valgrind memcheck and
massif tools, address, hwadderess, thread and leak sanitizers and also
using the heaptrack heap profiler. The output before and after looks the
same except for 2 things I describe below. The heap usage, memory leaks,
and out of buffer accesses are reported in the same way before and after
the change.

One difference in the valgrind output is that it detects that the malloc
functions are ifuncs now and you see

  REDIR: 0x4958810 (libc.so.6:aligned_alloc) redirected to 0x48507cc (_vgnU_ifunc_wrapper)
  REDIR: 0x4956c84 (libc.so.6:__aligned_alloc) redirected to 0x488d708 (aligned_alloc)

instead of

  REDIR: 0x4956c84 (libc.so.6:aligned_alloc) redirected to 0x488d708 (aligned_alloc)

This is expected I guess, and it doesn't affect valgrind's operation.

The second thing in the debuggers and in thread stacks in sanitizers the
malloc functions appear as "__lib_malloc" instead of "malloc" (for example)
which is also expected as a tool would show the symbol that the corresponding
ifunc resolves to. When we have "__libc_malloc" and "__libc_malloc_mte", it
would show the appropriate symbol which is how it should be, I think.

So, I think that this patch should not introduce any issues for sanitizers,
profiling and debugging tools.

Passes regression on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu and
build-tested for several targets with build-many-glibcs.py, OK for trunk?

Changes in v6:
 - base-commit: 9cf4dd03bd
 - Moved declarations for malloc API functions into new header located at
   sysdeps/generic/malloc-api.h (most code including comments copied from
   malloc/malloc.c as is).
 - Changed USE_MULTIARCH_MALLOC to be defined to 1 when malloc ifuncs are
   provided and 0 otherwise. The latter includes targets that don't support
   ifuncs and therefore have undefined USE_MULTIARCH, so the malloc-ifuncs.h
   header should always be included so that these targets would get the
   USE_MULTIARCH_MALLOC defined to 0.
 - v5: https://inbox.sourceware.org/libc-alpha/20260604142337.1547596-2-yury.khrustalev@arm.com/

Changes in v5:
 - Addressed upstream feedback.
 - Check some debuggers, sanitizers and profilers, that they work as before.
 - v4: https://inbox.sourceware.org/libc-alpha/20260601103034.217749-1-yury.khrustalev@arm.com/

Changes in v4:
 - Replaced custom ifunc macros with the one from libc-symbols.h.
 - v3: https://inbox.sourceware.org/libc-alpha/20260531161322.2610706-1-yury.khrustalev@arm.com

Changes in v3:
 - Moved all ifunc code into multiarch folder under aarch64, so this
   change is now aarch64-only not affecting other targets.
 - v2: https://inbox.sourceware.org/libc-alpha/20260420141459.531612-1-yury.khrustalev@arm.com

Changes in v2:
 - Fixed ifunc resolvers arguments: use no arguments for generic resolvers
   and use 'uint64_t arg0, uint64_t arg1[]' for aarch64 resolvers.
 - Added grep test to check that code in malloc.c doesn't use non-_core
   functions.
 - Cleaned-up makefile patch.

---

Yury Khrustalev (1):
  malloc: aarch64: Add ifuncs for malloc functions

 malloc/malloc-internal.h                  |   2 +
 malloc/malloc.c                           | 155 +++------------------
 sysdeps/aarch64/multiarch/Makefile        |  10 +-
 sysdeps/aarch64/multiarch/malloc-ifuncs.c |  77 +++++++++++
 sysdeps/aarch64/multiarch/malloc-ifuncs.h |  24 ++++
 sysdeps/generic/malloc-api.h              | 161 ++++++++++++++++++++++
 sysdeps/generic/malloc-ifuncs.h           |  36 +++++
 7 files changed, 330 insertions(+), 135 deletions(-)
 create mode 100644 sysdeps/aarch64/multiarch/malloc-ifuncs.c
 create mode 100644 sysdeps/aarch64/multiarch/malloc-ifuncs.h
 create mode 100644 sysdeps/generic/malloc-api.h
 create mode 100644 sysdeps/generic/malloc-ifuncs.h

-- 
2.47.3



More information about the Libc-alpha mailing list