[PATCH] D152921: [lld] Synthesize metadata for MTE globals

Mitch Phillips via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 14 07:37:36 PDT 2023


hctim created this revision.
Herald added subscribers: mgrang, kbarton, kristof.beyls, arichardson, nemanjai, emaste.
Herald added a reviewer: MaskRay.
Herald added a project: All.
hctim requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As per the ABI at
https://github.com/ARM-software/abi-aa/blob/main/memtagabielf64/memtagabielf64.rst,
this patch interprets the SHT_AARCH64_MEMTAG_GLOBALS_STATIC section,
which contains R_NONE relocations to tagged globals, and emits a
SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC section, with the correct
DT_AARCH64_MEMTAG_GLOBALS and DT_AARCH64_MEMTAG_GLOBALSSZ dynamic
entries. This section describes, in a uleb-encoded stream, global memory
ranges that should be tagged with MTE.

We are also out of bits to spare in the LLD Symbol class. As a result,
I've reused the 'needsTocRestore' bit, which is a PPC64 only feature.
Now, it's also used for 'isTagged' on AArch64.

An entry in SHT_AARCH64_MEMTAG_GLOBALS_STATIC is practically a guarantee
from an objfile that all references to the linked symbol are through the
GOT, and meet correct alignment requirements. As a result, we go through
all symbols and make sure that, for all symbols $SYM, all object files
that reference $SYM also have a SHT_AARCH64_MEMTAG_GLOBALS_STATIC entry
for $SYM. If this isn't the case, we demote the symbol to being
untagged. Symbols that are imported from other DSOs should always be
fine, as they're GOT-referenced (and thus the GOT entry either has the
correct tag or not, depending on whether it's tagged in the defining DSO
or not).

Additionally hand-tested by building {libc, libm, libc++, libm, and libnetd}
on Android with some experimental MTE globals support in the
linker/libc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152921

Files:
  lld/ELF/Arch/AArch64.cpp
  lld/ELF/Arch/PPC64.cpp
  lld/ELF/Driver.cpp
  lld/ELF/Relocations.cpp
  lld/ELF/Symbols.h
  lld/ELF/SyntheticSections.cpp
  lld/ELF/SyntheticSections.h
  lld/ELF/Thunks.cpp
  lld/ELF/Writer.cpp
  lld/ELF/Writer.h
  lld/test/ELF/Inputs/aarch64-memtag-globals-1.s
  lld/test/ELF/Inputs/aarch64-memtag-globals-2.s
  lld/test/ELF/aarch64-memtag-android-abi.s
  lld/test/ELF/aarch64-memtag-globals.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152921.531326.patch
Type: text/x-patch
Size: 37011 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230614/a8608d5c/attachment.bin>


More information about the llvm-commits mailing list