diff options
author | Mitch Phillips <31459023+hctim@users.noreply.github.com> | 2023-01-31 12:28:28 -0800 |
---|---|---|
committer | Mitch Phillips <31459023+hctim@users.noreply.github.com> | 2023-01-31 13:03:37 -0800 |
commit | 486729ce06c1efeb3315be1b810afcddf715dacb (patch) | |
tree | 65082edbc0ae1bfe28c739ddcbf8b0c0b5d9d762 /llvm/lib/CodeGen/GlobalMerge.cpp | |
parent | 8a16a069540a6c9662e53b64679b1f5ce8e51956 (diff) | |
download | llvm-486729ce06c1efeb3315be1b810afcddf715dacb.zip llvm-486729ce06c1efeb3315be1b810afcddf715dacb.tar.gz llvm-486729ce06c1efeb3315be1b810afcddf715dacb.tar.bz2 |
Re-land: [MTE] Add AArch64GlobalsTagging Pass
Adds an IR pass for -fsanitize=memtag-globals. This pass goes over the
tag-capable global variables, and replaces them with a tagged global
variable of the same contents. This new global variable will have its
size and alignment adjusted if neccesary so that they're both a multiple
of the tag granule size (16 bytes).
Global merge must also be suppressed for tagged globals, as each global
variable must have a unique tag. This can possibly be relaxed in future;
globals that are identical in size, alignment, and content can possibly
be merged. The major problem comes from tail- or head-merging, which if
left unchecked, could have partially-overlapping global variables with
different memory tags, leading to crashes at runtime.
Reviewed By: fmayer, eugenis
Differential Revision: https://reviews.llvm.org/D133392
Diffstat (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalMerge.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index 2ccf2de..3e9a12b 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -652,6 +652,14 @@ bool GlobalMerge::doInitialization(Module &M) { if (isMustKeepGlobalVariable(&GV)) continue; + // Don't merge tagged globals, as each global should have its own unique + // memory tag at runtime. TODO(hctim): This can be relaxed: constant globals + // with compatible alignment and the same contents may be merged as long as + // the globals occupy the same number of tag granules (i.e. `size_a / 16 == + // size_b / 16`). + if (GV.isTagged()) + continue; + Type *Ty = GV.getValueType(); if (DL.getTypeAllocSize(Ty) < MaxOffset) { if (TM && |