[compiler-rt] [compiler-rt][xray] porting to sunos platforms. (PR #90362)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 27 16:32:54 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-xray
Author: David CARLIER (devnexen)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/90362.diff
5 Files Affected:
- (modified) compiler-rt/cmake/config-ix.cmake (+1-1)
- (modified) compiler-rt/lib/xray/CMakeLists.txt (+4)
- (modified) compiler-rt/lib/xray/xray_x86_64.cpp (+33)
- (modified) compiler-rt/test/xray/TestCases/Posix/fork_basic_logging.cpp (+4)
- (modified) compiler-rt/test/xray/lit.cfg.py (+1-1)
``````````diff
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index ba740af9e1d60f..a891e23b02acf0 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -871,7 +871,7 @@ else()
endif()
if (COMPILER_RT_HAS_SANITIZER_COMMON AND XRAY_SUPPORTED_ARCH AND
- OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Fuchsia")
+ OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS")
set(COMPILER_RT_HAS_XRAY TRUE)
else()
set(COMPILER_RT_HAS_XRAY FALSE)
diff --git a/compiler-rt/lib/xray/CMakeLists.txt b/compiler-rt/lib/xray/CMakeLists.txt
index cf7b5062aae32d..551997d8d14684 100644
--- a/compiler-rt/lib/xray/CMakeLists.txt
+++ b/compiler-rt/lib/xray/CMakeLists.txt
@@ -189,6 +189,10 @@ if (TARGET cxx-headers OR HAVE_LIBCXX)
set(XRAY_DEPS cxx-headers)
endif()
+if (CMAKE_SYSTEM_NAME STREQUAL "SunOs")
+ set(XRAY_LINK_LIBS ${XRAY_LINK_LIBS} kstat)
+endif()
+
if (APPLE)
add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
add_weak_symbols("xray" WEAK_SYMBOL_LINK_FLAGS)
diff --git a/compiler-rt/lib/xray/xray_x86_64.cpp b/compiler-rt/lib/xray/xray_x86_64.cpp
index b9666a40861d48..a8b59b8a2eb9a3 100644
--- a/compiler-rt/lib/xray/xray_x86_64.cpp
+++ b/compiler-rt/lib/xray/xray_x86_64.cpp
@@ -9,6 +9,8 @@
#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_APPLE
#include <sys/types.h>
#include <sys/sysctl.h>
+#elif SANITIZER_SOLARIS
+#include <kstat.h>
#elif SANITIZER_FUCHSIA
#include <zircon/syscalls.h>
#endif
@@ -101,6 +103,37 @@ uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
return 0;
}
+#elif SANITIZER_SOLARIS
+uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
+ kstat_named_t *nm;
+ kstat_ctl_t *ctl;
+ kstat_t *s;
+ uint64_t TSCFrequency;
+
+ ctl = kstat_open();
+ if (!ctl) {
+ return 0;
+ }
+ s = kstat_lookup(ctl, "cpu_info", 0, NULL);
+ if (!s) {
+ kstat_close(ctl);
+ return 0;
+ }
+
+ if (kstat_read(ctl, s, NULL) == -1) {
+ kstat_close(ctl);
+ return 0;
+ }
+
+ nm = reinterpret_cast<kstat_named_t *>(kstat_data_lookup(s, "clock_MHz"));
+
+ auto clock =
+ nm->data_type == KSTAT_DATA_INT32 ? nm->value.i32 : nm->value.i64;
+ TSCFrequency = static_cast<uint64_t>(clock) * 1000000;
+ kstat_close(ctl);
+
+ return TSCFrequency;
+}
#elif !SANITIZER_FUCHSIA
uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
/* Not supported */
diff --git a/compiler-rt/test/xray/TestCases/Posix/fork_basic_logging.cpp b/compiler-rt/test/xray/TestCases/Posix/fork_basic_logging.cpp
index 58f310e3a1083f..8c4095466354a9 100644
--- a/compiler-rt/test/xray/TestCases/Posix/fork_basic_logging.cpp
+++ b/compiler-rt/test/xray/TestCases/Posix/fork_basic_logging.cpp
@@ -13,6 +13,10 @@
// Not ported.
// UNSUPPORTED: target={{.*netbsd.*}}
+// Not ported.
+// UNSUPPORTED: target={{.*solaris.*}}
+// Not ported.
+// UNSUPPORTED: target={{.*illumos.*}}
#include "xray/xray_log_interface.h"
#include <stdio.h>
diff --git a/compiler-rt/test/xray/lit.cfg.py b/compiler-rt/test/xray/lit.cfg.py
index f73ae3acd77154..491d5c1ff4e57c 100644
--- a/compiler-rt/test/xray/lit.cfg.py
+++ b/compiler-rt/test/xray/lit.cfg.py
@@ -56,7 +56,7 @@ def build_invocation(compile_flags):
# Default test suffixes.
config.suffixes = [".c", ".cpp"]
-if config.host_os not in ["FreeBSD", "Linux", "NetBSD", "OpenBSD"]:
+if config.host_os not in ["FreeBSD", "Linux", "NetBSD", "OpenBSD", "SunOS"]:
config.unsupported = True
elif "64" not in config.host_arch:
if "arm" in config.host_arch:
``````````
</details>
https://github.com/llvm/llvm-project/pull/90362
More information about the llvm-commits
mailing list