From 139c6107ae9422826cf85e00c9c4551e3dfa1ac9 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Tue, 27 Aug 2024 12:53:18 -0700 Subject: [PATCH 1/5] =?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 2bc69cdb712b0..6b502a08b87d0 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 Date: Wed, 28 Aug 2024 12:58:22 -0700 Subject: [PATCH 2/5] 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 0000000000000..debd128377d4b --- /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" + +@x = dso_local global i32 1, sanitize_memtag, align 4 +@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,@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,@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 Date: Tue, 8 Oct 2024 14:30:50 -0700 Subject: [PATCH 3/5] 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 d9104d7af5f97..516693db33e5d 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 4fe7cf3eb4d98..99f4fa50e9c43 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. From 939564037b94a21350fe16c9ea92dd1abf953d14 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Mon, 21 Oct 2024 15:23:23 -0700 Subject: [PATCH 4/5] cmt Created using spr 1.3.4 --- llvm/lib/IR/Globals.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 4fe7cf3eb4d98..1290c712c5b2b 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -111,7 +111,9 @@ bool GlobalValue::isInterposable() const { bool GlobalValue::canBenefitFromLocalAlias() const { if (isTagged()) { - // Cannot create local aliases to MTE tagged globals. + // Cannot create local aliases to MTE tagged globals. Th address of a + // tagged global includes a tag that is assigned by the loader in the + // GOT. return false; } // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind, From 30cf44144d3e788aa61d644bff0341ee0af38063 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Mon, 21 Oct 2024 15:24:28 -0700 Subject: [PATCH 5/5] typo Created using spr 1.3.4 --- llvm/lib/IR/Globals.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 1290c712c5b2b..db5e1cb57b1ba 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -111,7 +111,7 @@ bool GlobalValue::isInterposable() const { bool GlobalValue::canBenefitFromLocalAlias() const { if (isTagged()) { - // Cannot create local aliases to MTE tagged globals. Th address of a + // Cannot create local aliases to MTE tagged globals. The address of a // tagged global includes a tag that is assigned by the loader in the // GOT. return false;