llvm / llvm/llvm-project

`-fsanitize=memtag-globals` for self-relocating executables

Open
#180,712 3 comments 0 reactions 0 assignees View on GitHub
lld:ELF llvm:codegen
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.