diff options
author | Indu Bhagat <indu.bhagat@oracle.com> | 2025-07-09 23:13:58 +0200 |
---|---|---|
committer | Jose E. Marchesi <jose.marchesi@oracle.com> | 2025-07-12 11:33:25 +0200 |
commit | b9b7bbb466efc2955c80204250eedeecfacbecd7 (patch) | |
tree | 2d743a811b3058b28d916b7622b00540310be464 /ld | |
parent | 97d71f2366fdbe506bcfad0c0abd3914ba334ada (diff) | |
download | gdb-master.zip gdb-master.tar.gz gdb-master.tar.bz2 |
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
... ... ...
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.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/emultempl/aarch64elf.em | 5 | ||||
-rw-r--r-- | ld/ld.texi | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/aarch64-elf.exp | 1 | ||||
-rw-r--r-- | ld/testsuite/ld-aarch64/dt-memtag-stack.d | 7 |
4 files changed, 18 insertions, 0 deletions
diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em index d7e4eb7..66eaf1c 100644 --- a/ld/emultempl/aarch64elf.em +++ b/ld/emultempl/aarch64elf.em @@ -44,6 +44,7 @@ static aarch64_protection_opts sw_protections = { static aarch64_memtag_opts memtag_opts = { .memtag_mode = AARCH64_MEMTAG_MODE_NONE, + .memtag_stack = 0, }; #define COMPILE_TIME_STRLEN(s) \ @@ -557,6 +558,8 @@ PARSE_AND_LIST_OPTIONS=' sync: Enable precise exceptions when mismatched address and\n\ allocation tags detected on load/store operations.\n\ async: Enable imprecise exceptions.\n")); + fprintf (file, _("\ + -z memtag-stack Mark program stack with MTE protection.\n")); ' PARSE_AND_LIST_ARGS_CASE_Z_AARCH64=' @@ -574,6 +577,8 @@ PARSE_AND_LIST_ARGS_CASE_Z_AARCH64=' {} else if (aarch64_parse_memtag_mode_option (optarg)) {} + else if (strcmp (optarg, "memtag-stack") == 0) + memtag_opts.memtag_stack = 1; ' PARSE_AND_LIST_ARGS_CASE_Z="$PARSE_AND_LIST_ARGS_CASE_Z $PARSE_AND_LIST_ARGS_CASE_Z_AARCH64" @@ -8384,6 +8384,11 @@ implies precise exceptions, with the runtime providing the exact instruction where the fault occurred, and the exact faulting address. The @samp{async} mode implies imprecise exceptions. +@kindex -z memtag-stack +@cindex Mark program stack for MTE protection +The @samp{-z memtag-stack} specifies that output object uses MTE +instructions for stack memory usage. + @ifclear GENERIC @lowersections @end ifclear diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index 56e68c5..8d56beb 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -378,6 +378,7 @@ run_dump_test_lp64 "variant_pcs-now" run_dump_test_lp64 "mte-tagged-frame" run_dump_test_lp64 "dt-memtag-mode" +run_dump_test_lp64 "dt-memtag-stack" set aarch64elflinktests { {"ld-aarch64/so with global symbol" "-shared" "" "" {copy-reloc-so.s} diff --git a/ld/testsuite/ld-aarch64/dt-memtag-stack.d b/ld/testsuite/ld-aarch64/dt-memtag-stack.d new file mode 100644 index 0000000..242f61f --- /dev/null +++ b/ld/testsuite/ld-aarch64/dt-memtag-stack.d @@ -0,0 +1,7 @@ +#source: dt-memtag.s +#ld: -shared -z memtag-stack +#readelf: -d + +#... + 0x000000007000000c \(AARCH64_MEMTAG_STACK\) 0x1 +#... |