[clang] [compiler-rt] [compiler-rt] adding safestack support for sunos platforms. (PR #95648)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 15 01:55:25 PDT 2024


https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/95648

>From 33f68c3c59549a966871ea87f0f4b4c5df0a3d04 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sat, 15 Jun 2024 09:48:58 +0000
Subject: [PATCH] [compiler-rt] adding safestack support for sunos platforms.

---
 clang/lib/Driver/ToolChains/Solaris.cpp        |  1 +
 compiler-rt/cmake/config-ix.cmake              |  2 +-
 compiler-rt/lib/safestack/safestack_platform.h | 11 ++++++++++-
 compiler-rt/test/safestack/lit.cfg.py          |  2 +-
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index 7126e018ca5b6..e82ed2ca79ffd 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -341,6 +341,7 @@ SanitizerMask Solaris::getSupportedSanitizers() const {
     Res |= SanitizerKind::PointerCompare;
     Res |= SanitizerKind::PointerSubtract;
   }
+  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Vptr;
   return Res;
 }
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index bddaa37579fd7..c05bdd58519fb 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -833,7 +833,7 @@ else()
 endif()
 
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
-    OS_NAME MATCHES "Linux|FreeBSD|NetBSD")
+    OS_NAME MATCHES "Linux|FreeBSD|NetBSD|SunOS")
   set(COMPILER_RT_HAS_SAFESTACK TRUE)
 else()
   set(COMPILER_RT_HAS_SAFESTACK FALSE)
diff --git a/compiler-rt/lib/safestack/safestack_platform.h b/compiler-rt/lib/safestack/safestack_platform.h
index 2b1fc139baa90..2d952de034ea9 100644
--- a/compiler-rt/lib/safestack/safestack_platform.h
+++ b/compiler-rt/lib/safestack/safestack_platform.h
@@ -25,7 +25,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX)
+#if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX || \
+      SANITIZER_SOLARIS)
 #error "Support for your platform has not been implemented"
 #endif
 
@@ -39,6 +40,10 @@ extern "C" void *__mmap(void *, size_t, int, int, int, int, off_t);
 #include <sys/thr.h>
 #endif
 
+#if SANITIZER_SOLARIS
+#  include <thread.h>
+#endif
+
 namespace safestack {
 
 #if SANITIZER_NETBSD
@@ -73,6 +78,8 @@ inline ThreadId GetTid() {
   long Tid;
   thr_self(&Tid);
   return Tid;
+#elif SANITIZER_SOLARIS
+  return thr_self();
 #else
   return syscall(SYS_gettid);
 #endif
@@ -83,6 +90,8 @@ inline int TgKill(pid_t pid, ThreadId tid, int sig) {
   DEFINE__REAL(int, _lwp_kill, int a, int b);
   (void)pid;
   return _REAL(_lwp_kill, tid, sig);
+#elif SANITIZER_SOLARIS
+  return syscall(SYS_lwp_kill, tid, sig);
 #elif SANITIZER_FREEBSD
   return syscall(SYS_thr_kill2, pid, tid, sig);
 #else
diff --git a/compiler-rt/test/safestack/lit.cfg.py b/compiler-rt/test/safestack/lit.cfg.py
index aadb8bf0d5c77..17dfae46a412b 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -33,5 +33,5 @@
         )
     )
 
-if config.host_os not in ["Linux", "FreeBSD", "NetBSD"]:
+if config.host_os not in ["Linux", "FreeBSD", "NetBSD", "SunOS"]:
     config.unsupported = True



More information about the llvm-commits mailing list