`-fsanitize=memtag-globals` for self-relocating executables
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Currently, the `-fsanitize=memtag-globals` option in `clang` is supported only on AArch64 Android:
https://github.com/llvm/llvm-project/blob/302ff8fd005620731b82dd2a6342a9613363a9aa/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp#L790-L793
This prevents its use in AArch64 self-relocating executables (`aarch64-none-elf`) which, being responsible for their own relocations, should not be prevented from using this functionality.
A similar assumption is also present in `lld`, which prevents fully static executables from using memtag globals under the assumption that a dynamic loader is needed:
https://github.com/llvm/llvm-project/blob/302ff8fd005620731b82dd2a6342a9613363a9aa/lld/ELF/SyntheticSections.cpp#L4513-L4514
A self-relocating executable is commonly compiled as a static executable and performs its own relocations, so this assumption is incorrect in this specific case.
I propose to modify these checks to improve the support for self-relocating executables.
Contributor guide
Research direction
Start by reading the memtag-globals checks in llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp and lld/ELF/SyntheticSections.cpp, focusing on their assumptions about Android, dynamic loaders, and static executables. Trace how an aarch64-none-elf self-relocating executable reaches these checks. Done means the checks no longer block this supported case while retaining the existing behavior for other executables.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100