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

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 21:51:16 PDT 2023


https://github.com/hstk30-hw created https://github.com/llvm/llvm-project/pull/70536

fix bad `Offset` for aarch64be asan

>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] 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



More information about the llvm-commits mailing list