[llvm] fix: asan support aarch64be (PR #70536)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 29 02:00:07 PDT 2023


https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/70536

>From 5cd3422497a770453e4395280d1c3cf38eec61b8 Mon Sep 17 00:00:00 2001
From: hstk30-hw <hanwei62 at huawei.com>
Date: Sat, 28 Oct 2023 11:25:09 +0800
Subject: [PATCH 1/2] fix: asan support aarch64be

---
 .../Instrumentation/AddressSanitizer.cpp      |  3 ++-
 .../AddressSanitizer/aarch64.ll               | 23 +++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Instrumentation/AddressSanitizer/aarch64.ll

diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index bde5fba20f3b7a6..554c08c88bbe4ea 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -491,7 +491,8 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
   bool IsMIPS32 = TargetTriple.isMIPS32();
   bool IsMIPS64 = TargetTriple.isMIPS64();
   bool IsArmOrThumb = TargetTriple.isARM() || TargetTriple.isThumb();
-  bool IsAArch64 = TargetTriple.getArch() == Triple::aarch64;
+  bool IsAArch64 = TargetTriple.getArch() == Triple::aarch64 ||
+                   TargetTriple.getArch() == Triple::aarch64_be;
   bool IsLoongArch64 = TargetTriple.isLoongArch64();
   bool IsRISCV64 = TargetTriple.getArch() == Triple::riscv64;
   bool IsWindows = TargetTriple.isOSWindows();
diff --git a/llvm/test/Instrumentation/AddressSanitizer/aarch64.ll b/llvm/test/Instrumentation/AddressSanitizer/aarch64.ll
new file mode 100644
index 000000000000000..2e7affa3bee2c47
--- /dev/null
+++ b/llvm/test/Instrumentation/AddressSanitizer/aarch64.ll
@@ -0,0 +1,23 @@
+; RUN: opt < %s -passes='asan-pipeline' -S -mtriple=aarch64-linux-gnu | FileCheck --check-prefix=CHECK-AARCH64LE %s
+ 
+; RUN: opt < %s -passes='asan-pipeline' -S -mtriple=aarch64_be-linux-gnu | FileCheck --check-prefix=CHECK-AARCH64BE %s
+ 
+define i32 @read_4_bytes(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
+ 
+; CHECK-AARCH64LE: @read_4_bytes
+; CHECK-AARCH64LE-NOT: ret
+; Check for ASAN's Offset for AArch64 LE (1 << 36 or 68719476736)
+; CHECK-AARCH64LE: lshr {{.*}} 3
+; CHECK-AARCH64Le-NEXT: {{68719476736}}
+; CHECK-AARCH64LE: ret
+ 
+; CHECK-AARCH64BE: @read_4_bytes
+; CHECK-AARCH64BE-NOT: ret
+; Check for ASAN's Offset for AArch64 BE (1 << 36 or 68719476736)
+; CHECK-AARCH64BE: lshr {{.*}} 3
+; CHECK-AARCH64BE-NEXT: {{68719476736}}
+; CHECK-AARCH64BE: ret
\ No newline at end of file

>From e58134fbafc20fec312c3451e393996646cd80f0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at gmail.com>
Date: Fri, 27 Oct 2023 21:54:57 -0700
Subject: [PATCH 2/2] Rename aarch64.ll to aarch64be.ll

---
 .../AddressSanitizer/{aarch64.ll => aarch64be.ll}               | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 rename llvm/test/Instrumentation/AddressSanitizer/{aarch64.ll => aarch64be.ll} (97%)

diff --git a/llvm/test/Instrumentation/AddressSanitizer/aarch64.ll b/llvm/test/Instrumentation/AddressSanitizer/aarch64be.ll
similarity index 97%
rename from llvm/test/Instrumentation/AddressSanitizer/aarch64.ll
rename to llvm/test/Instrumentation/AddressSanitizer/aarch64be.ll
index 2e7affa3bee2c47..1850efaf8a927a0 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/aarch64.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/aarch64be.ll
@@ -20,4 +20,4 @@ entry:
 ; Check for ASAN's Offset for AArch64 BE (1 << 36 or 68719476736)
 ; CHECK-AARCH64BE: lshr {{.*}} 3
 ; CHECK-AARCH64BE-NEXT: {{68719476736}}
-; CHECK-AARCH64BE: ret
\ No newline at end of file
+; CHECK-AARCH64BE: ret



More information about the llvm-commits mailing list