[llvm] [MTE] Do not allow local aliases to MTE globals (PR #106280)
Florian Mayer via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 14:31:06 PDT 2024
https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/106280
>From 139c6107ae9422826cf85e00c9c4551e3dfa1ac9 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Tue, 27 Aug 2024 12:53:18 -0700
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
=?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
llvm/lib/IR/Globals.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 2bc69cdb712b0a..6b502a08b87d08 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -110,6 +110,10 @@ bool GlobalValue::isInterposable() const {
}
bool GlobalValue::canBenefitFromLocalAlias() const {
+ if (isTagged()) {
+ // Cannot create local aliases to MTE tagged globals.
+ return false;
+ }
// See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
// references to a discarded local symbol from outside the group are not
// allowed, so avoid the local alias.
>From 4d21afa60af5a845c059d0ae53214bc848dbacdf Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Wed, 28 Aug 2024 12:58:22 -0700
Subject: [PATCH 2/3] add test
Created using spr 1.3.4
---
.../AArch64/semantic-interposition-memtag.ll | 50 +++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 llvm/test/CodeGen/AArch64/semantic-interposition-memtag.ll
diff --git a/llvm/test/CodeGen/AArch64/semantic-interposition-memtag.ll b/llvm/test/CodeGen/AArch64/semantic-interposition-memtag.ll
new file mode 100644
index 00000000000000..debd128377d4bc
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/semantic-interposition-memtag.ll
@@ -0,0 +1,50 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -relocation-model=pic < %s | FileCheck %s
+
+;; Test that we use do not the local alias for dso_local globals with MTE.
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
+target triple = "aarch64-unknown-linux-android10000"
+
+ at x = dso_local global i32 1, sanitize_memtag, align 4
+ at y = dso_local global i32 1, align 4
+
+; Function Attrs: noinline optnone
+define dso_local i32 @main() #0 {
+; CHECK-LABEL: main:
+; CHECK: .Lmain$local:
+; CHECK-NEXT: .type .Lmain$local, at function
+; CHECK-NEXT: .cfi_startproc
+; CHECK-NEXT: // %bb.0: // %entry
+; CHECK-NEXT: adrp x8, :got:x
+; CHECK-NEXT: ldr x8, [x8, :got_lo12:x]
+; CHECK-NEXT: ldr w0, [x8]
+; CHECK-NEXT: ret
+entry:
+ %0 = load i32, ptr @x, align 4
+ ret i32 %0
+}
+
+; Function Attrs: noinline optnone
+define dso_local i32 @main2() #0 {
+; CHECK-LABEL: main2:
+; CHECK: .Lmain2$local:
+; CHECK-NEXT: .type .Lmain2$local, at function
+; CHECK-NEXT: .cfi_startproc
+; CHECK-NEXT: // %bb.0: // %entry
+; CHECK-NEXT: adrp x8, .Ly$local
+; CHECK-NEXT: add x8, x8, :lo12:.Ly$local
+; CHECK-NEXT: ldr w0, [x8]
+; CHECK-NEXT: ret
+entry:
+ %0 = load i32, ptr @y, align 4
+ ret i32 %0
+}
+
+
+attributes #0 = { noinline optnone "target-cpu"="generic" "target-features"="+mte,+v8a" }
+
+!llvm.module.flags = !{!2, !3}
+
+!2 = !{i32 8, !"PIC Level", i32 2}
+!3 = !{i32 7, !"PIE Level", i32 0}
>From d822d4b65b6a698f07d9bd1fdb39ca1773c280b9 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Tue, 8 Oct 2024 14:30:50 -0700
Subject: [PATCH 3/3] upd
Created using spr 1.3.4
---
llvm/include/llvm/IR/GlobalValue.h | 4 +++-
llvm/lib/IR/Globals.cpp | 4 ----
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index d9104d7af5f972..516693db33e5d6 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -303,7 +303,9 @@ class GlobalValue : public Constant {
void setDSOLocal(bool Local) { IsDSOLocal = Local; }
bool isDSOLocal() const {
- return IsDSOLocal;
+ // Tagged globals cannot be DSO local, because the linker will put the
+ // tagged pointers into the GOT.
+ return IsDSOLocal && !isTagged();
}
bool hasPartition() const {
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 4fe7cf3eb4d980..99f4fa50e9c433 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -110,10 +110,6 @@ bool GlobalValue::isInterposable() const {
}
bool GlobalValue::canBenefitFromLocalAlias() const {
- if (isTagged()) {
- // Cannot create local aliases to MTE tagged globals.
- return false;
- }
// See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
// references to a discarded local symbol from outside the group are not
// allowed, so avoid the local alias.
More information about the llvm-commits
mailing list