[PATCH] aarch64: tests: Fix MTE tests compilation failure with -mcpu=native

Yury Khrustalev yury.khrustalev@arm.com
Tue Nov 3 14:45:38 GMT 2026


When configured with CFLAGS="... -mcpu=native ..." MTE malloc tests
would try to use '-march=armv8-a+memtag' which would result in an
error if host's CPU does not have MTE.

Fix it by using target attribute on the test functions that require
memory tagging instructions.

No functional change to the tests.

Reported-by: Wilco Dijkstra <wilco.dijkstra@arm.com>
---
 sysdeps/unix/sysv/linux/aarch64/Makefile         | 7 +------
 sysdeps/unix/sysv/linux/aarch64/tst-mte-helper.h | 6 ++++--
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 761b53f6b2..2507452577 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -411,16 +411,10 @@ tests-static += \
   tst-mte-realloc-static \
   # tests-static
 
-CFLAGS-tst-mte-malloc.o += -march=armv9-a+memtag
-CFLAGS-tst-mte-malloc-static.o += -march=armv9-a+memtag
-CFLAGS-tst-mte-realloc.o += -march=armv9-a+memtag
-CFLAGS-tst-mte-realloc-static.o += -march=armv9-a+memtag
-
 tests-exclude-malloc-check += $(tests-for-mte)
 tests-exclude-mcheck += $(tests-for-mte)
 tests-exclude-hugetlb1 += $(tests-for-mte)
 tests-exclude-hugetlb2 += $(tests-for-mte)
-endif # ifneq ($(multi-arch),no)
 
 # Add MTE tunable to all malloc tests except malloc-check and mcheck variants
 tests-malloc-mte = \
@@ -435,6 +429,7 @@ $(1)-TUNABLES += glibc.cpu.mtemode=sync
 endef
 
 $(foreach t,$(tests-malloc-mte),$(eval $(call tests-malloc-mte-ENVS,$(t))))
+endif # ifneq ($(multi-arch),no)
 endif # ifeq ($(subdir),malloc)
 
 abi-variants := lp64
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-mte-helper.h b/sysdeps/unix/sysv/linux/aarch64/tst-mte-helper.h
index 8952dda036..8ad1e91538 100644
--- a/sysdeps/unix/sysv/linux/aarch64/tst-mte-helper.h
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-mte-helper.h
@@ -31,6 +31,8 @@
 
 #define GRANULE_SIZE 16
 
+#define __memtag __attribute__ ((target("arch=armv9-a+memtag")))
+
 /* Extract logical tag from pointer PTR.  */
 static __always_inline uint64_t
 get_logical_tag (const void *ptr)
@@ -40,7 +42,7 @@ get_logical_tag (const void *ptr)
 }
 
 /* Load allocation tag from memory pointed-to by the PTR pointer.  */
-static __always_inline uint64_t
+static __memtag uint64_t
 get_allocation_tag (const void *ptr)
 {
   uint64_t t;
@@ -49,7 +51,7 @@ get_allocation_tag (const void *ptr)
 }
 
 /* Read the Tag Check Override bit.  */
-static __always_inline uint64_t
+static __memtag uint64_t
 get_pstate_tco (void)
 {
   uint64_t t;
-- 
2.47.3



More information about the Libc-alpha mailing list