]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
ld/aarch64elf: add support for DT_AARCH64_MEMTAG_STACK dynamic tag users/ibhagat/try-mte-rfc-v2
authorIndu Bhagat <indu.bhagat@oracle.com>
Wed, 4 Dec 2024 21:45:25 +0000 (13:45 -0800)
committerIndu Bhagat <indu.bhagat@oracle.com>
Fri, 11 Apr 2025 03:54:24 +0000 (20:54 -0700)
commit6442427b49a643d1f56acaf5af55a187343fbf0c
treee77d42b91df493b56d82bb36e7dccf355e60eb8a
parent6e0b15951187e3bee75d8e2ec8ebc67b3dc0ca4c
ld/aarch64elf: add support for DT_AARCH64_MEMTAG_STACK dynamic tag

Add new command line option -z memtag-stack for aarch64 elf.  This
option instructs the linker to generate the necessary dynamic tag
DT_AARCH64_MEMTAG_STACK,  which the dynamic loader can then use to
protect the stack memory with PROT_MTE.  Linker issues an 'unrecognized
option' error when -z memtag-stack is specified for non-aarch64 based
emulations.

readelf displays the dynamic tag when present:

$ readelf -d <exectutable>
Dynamic section at offset 0xfdd8 contains XX entries:
Tag        Type                         Name/Value
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
0x000000000000000c (INIT)               0x400520
0x000000000000000d (FINI)               0x400b64
0x0000000000000019 (INIT_ARRAY)         0x41fdc8
...                 ...                 ...
0x000000007000000c (AARCH64_MEMTAG_STACK) 0x1
...                 ...                 ...

TBD:
1. Error/Warn if user says -z memtag-stack but does not select a
   mode ?
2. Should ld check that all input ELF components were compiled with
   -fsanitize=memtag-stack ? If yes, we likely need something like
   GNU_PROPERTY_AARCH64_FEATURE_1_MEMTAG_STACK specified in the ABI.
   Should we then allow the user to select the desirable action like we
   do in other cases, via say memtag-report[=none|warning|error] ?

ChangeLog:

        * bfd/elfnn-aarch64.c (elfNN_aarch64_late_size_sections): Emit
DT_AARCH64_MEMTAG_STACK dynamic tag.
        * bfd/elfxx-aarch64.h (struct aarch64_memtag_opts): Add new
member for tracking whether stack access uses MTE insns.
        * binutils/readelf.c (get_aarch64_dynamic_type): Handle
DT_AARCH64_MEMTAG_STACK.
        * ld/emultempl/aarch64elf.em: Add new command line option.
        * ld/ld.texi: Add documentation for -z memtag-stack.
        * ld/testsuite/ld-aarch64/aarch64-elf.exp: Add new test.
        * ld/testsuite/ld-aarch64/dt-memtag-stack.d: New test.

include/ChangeLog:

        * elf/aarch64.h (DT_AARCH64_MEMTAG_STACK): New definition.
bfd/elfnn-aarch64.c
bfd/elfxx-aarch64.h
binutils/readelf.c
include/elf/aarch64.h
ld/emultempl/aarch64elf.em
ld/ld.texi
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/dt-memtag-stack.d [new file with mode: 0644]