aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/GlobalMerge.cpp
diff options
context:
space:
mode:
authorMitch Phillips <31459023+hctim@users.noreply.github.com>2023-01-31 09:24:13 -0800
committerMitch Phillips <31459023+hctim@users.noreply.github.com>2023-01-31 09:24:18 -0800
commit4edfcff71e150770675a19576f698c7bbe788ee2 (patch)
tree91589ac7f0ab86ee236d240bca663fd793f7717c /llvm/lib/CodeGen/GlobalMerge.cpp
parent6a1b2d04288296606767bce08b3229e0e72e0100 (diff)
downloadllvm-4edfcff71e150770675a19576f698c7bbe788ee2.zip
llvm-4edfcff71e150770675a19576f698c7bbe788ee2.tar.gz
llvm-4edfcff71e150770675a19576f698c7bbe788ee2.tar.bz2
[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.cpp8
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 &&