Explore Arm Memory Tagging Extension with an example C program
Introduction
Create and compile an example C application to explore Arm MTE
Run the example application to explore Arm MTE
Next Steps
Explore Arm Memory Tagging Extension with an example C program
Run the example
Use the compiled mte-example executable to run the example:
- Run the example on the Linux machine and confirm MTE is not supported:
./mte-example
The output is similar to:
MTE is not supported
The example reports that Memory Tagging Extension (MTE) isn’t supported because getauxval(), the function to query hardware features from applications, doesn’t report the HWCAP2_MTE field as set. This means MTE isn’t implemented in the processor. For more information about how to identify hardware features, see
ARM64 ELF hwcaps
.
- Run the application again using
qemu-aarch64, the userspace program which includes support for MTE:
qemu-aarch64 ./mte-example
The expected output is:
MTE is supported
pointer is 0x5501a14000
ptr[0] = 0x41 ptr[1] = 0x42
pointer is now 0x100005501a14000
ptr[0] = 0x43 ptr[1] = 0x44
Expecting SIGSEGV...
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)
The application detects that MTE is available and memory tagging can be enabled and used.
The tag value will be different from the example output (the tag value is 1). Each time you run the application, a random tag will be generated by the IRG instruction.
What you’ve accomplished
You’ve learned how to build and run a program with MTE on Linux.
You can continue learning about MTE using the further-reading resources provided in this Learning Path.