[compiler-rt] [LoongArch][sanitizer] Fix SC_ADDRERR_{RD,WR} missing in the musl environment (PR #108557)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 06:09:12 PDT 2024


https://github.com/heiher updated https://github.com/llvm/llvm-project/pull/108557

>From 8f9d73bb173d382fc0fbcf36b5275acf3e396797 Mon Sep 17 00:00:00 2001
From: WANG Rui <wangrui at loongson.cn>
Date: Fri, 13 Sep 2024 20:34:57 +0800
Subject: [PATCH 1/2] [LoongArch][sanitizer] Fix SC_ADDRERR_{RD,WR} missing in
 the musl environment

Fixes #108550
---
 compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 16d06c69a38f32..f4a2f46c6ea022 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2018,6 +2018,18 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
     return Unknown;
   return esr & ESR_ELx_WNR ? Write : Read;
 #  elif defined(__loongarch__)
+     // In the musl environment, the Linux kernel uapi sigcontext.h is not
+     // included in signal.h. To avoid missing the SC_ADDRERR_{RD,WR} macros,
+     // copy them here. The LoongArch Linux kernel uapi is already stable,
+     // so there's no need to worry about the value changing.
+#    ifndef SC_ADDRERR_RD
+       // Address error was due to memory load
+#      define SC_ADDRERR_RD		(1 << 30)
+#    endif
+#    ifndef SC_ADDRERR_WR
+       // Address error was due to memory store
+#      define SC_ADDRERR_WR		(1 << 31)
+#    endif
   u32 flags = ucontext->uc_mcontext.__flags;
   if (flags & SC_ADDRERR_RD)
     return SignalContext::Read;

>From 6df71699b1fae3e9d924a42f3c35b4834149c3b3 Mon Sep 17 00:00:00 2001
From: WANG Rui <wangrui at loongson.cn>
Date: Fri, 13 Sep 2024 21:09:31 +0800
Subject: [PATCH 2/2] Update the code formatting

---
 .../lib/sanitizer_common/sanitizer_linux.cpp     | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index f4a2f46c6ea022..6359f4348e3c48 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2018,17 +2018,17 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
     return Unknown;
   return esr & ESR_ELx_WNR ? Write : Read;
 #  elif defined(__loongarch__)
-     // In the musl environment, the Linux kernel uapi sigcontext.h is not
-     // included in signal.h. To avoid missing the SC_ADDRERR_{RD,WR} macros,
-     // copy them here. The LoongArch Linux kernel uapi is already stable,
-     // so there's no need to worry about the value changing.
+  // In the musl environment, the Linux kernel uapi sigcontext.h is not
+  // included in signal.h. To avoid missing the SC_ADDRERR_{RD,WR} macros,
+  // copy them here. The LoongArch Linux kernel uapi is already stable,
+  // so there's no need to worry about the value changing.
 #    ifndef SC_ADDRERR_RD
-       // Address error was due to memory load
-#      define SC_ADDRERR_RD		(1 << 30)
+  // Address error was due to memory load
+#      define SC_ADDRERR_RD (1 << 30)
 #    endif
 #    ifndef SC_ADDRERR_WR
-       // Address error was due to memory store
-#      define SC_ADDRERR_WR		(1 << 31)
+  // Address error was due to memory store
+#      define SC_ADDRERR_WR (1 << 31)
 #    endif
   u32 flags = ucontext->uc_mcontext.__flags;
   if (flags & SC_ADDRERR_RD)



More information about the llvm-commits mailing list