malloc: Use global flag instead of function pointer dispatch for mtag
commit42bac88a211a7fac9dd1bfe7d1e45e59ac50c24f
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 27 Jan 2021 15:45:43 +0000 (27 15:45 +0000)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 26 Mar 2021 11:03:06 +0000 (26 11:03 +0000)
tree7ada38d2ac5b38b658b46d5b6038890fa2c83db0
parent0c719cf42c982ce627179cde4fd583bcca6417bd
malloc: Use global flag instead of function pointer dispatch for mtag

A flag check can be faster than function pointers because of how
branch prediction and speculation works and it can also remove a layer
of indirection when there is a mismatch between the malloc internal
tag_* api and __libc_mtag_* target hooks.

Memory tagging wrapper functions are moved to malloc.c from arena.c and
the logic now checks mmap_enabled.  The definition of tag_new_usable is
moved after chunk related definitions.

This refactoring also allows using mtag_enabled checks instead of
USE_MTAG ifdefs when memory tagging support only changes code logic
when memory tagging is enabled at runtime. Note: an "if (false)" code
block is optimized away even at -O0 by gcc.

Reviewed-by: DJ Delorie <dj@redhat.com>
malloc/arena.c
malloc/malloc.c