diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 7037bf89d6532..2cbce3b01c0ee 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -861,7 +861,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 cf7b5062aae32..a67fca1b96a29 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 b9666a40861d4..a8b59b8a2eb9a 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 #include +#elif SANITIZER_SOLARIS +#include #elif SANITIZER_FUCHSIA #include #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_data_lookup(s, "clock_MHz")); + + auto clock = + nm->data_type == KSTAT_DATA_INT32 ? nm->value.i32 : nm->value.i64; + TSCFrequency = static_cast(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 58f310e3a1083..8c4095466354a 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 diff --git a/compiler-rt/test/xray/lit.cfg.py b/compiler-rt/test/xray/lit.cfg.py index f73ae3acd7715..491d5c1ff4e57 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: diff --git a/third-party/benchmark/src/sysinfo.cc b/third-party/benchmark/src/sysinfo.cc index 46df973b069a7..d02a9009c8b0b 100644 --- a/third-party/benchmark/src/sysinfo.cc +++ b/third-party/benchmark/src/sysinfo.cc @@ -502,7 +502,7 @@ int GetNumCPUsImpl() { PrintErrorAndDie("sysconf(_SC_NPROCESSORS_ONLN) failed with error: ", strerror(errno)); } - return (int)num_cpu; + return static_cast(num_cpu); #elif defined(BENCHMARK_OS_QNX) return static_cast(_syspage_ptr->num_cpu); #elif defined(BENCHMARK_OS_QURT) @@ -779,8 +779,8 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) { std::cerr << "failed to read from /dev/kstat\n"; return -1; } - kstat_named_t* knp = (kstat_named_t*)kstat_data_lookup( - ksp, const_cast("current_clock_Hz")); + kstat_named_t* knp = reinterpret_cast(kstat_data_lookup( + ksp, const_cast("current_clock_Hz"))); if (!knp) { std::cerr << "failed to lookup data in /dev/kstat\n"; return -1;