[compiler-rt] r329189 - [XRay][compiler-rt] Build XRay runtime for OpenBSD

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 4 06:04:15 PDT 2018


Author: dberris
Date: Wed Apr  4 06:04:15 2018
New Revision: 329189

URL: http://llvm.org/viewvc/llvm-project?rev=329189&view=rev
Log:
[XRay][compiler-rt] Build XRay runtime for OpenBSD

Summary:
This is D45125; the patch enables the build of XRay on OpenBSD. We also
introduce some OpenBSD specific changes to the runtime implementation,
involving how we get the TSC rate through the syscall interface specific
to OpenBSD.

Reviewers: dberris

Authored by: devnexen

Subscribers: dberris, mgorny, krytarowski, llvm-commits

Differential Revision: https://reviews.llvm.org/D45125

Modified:
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/xray/xray_x86_64.cc

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=329189&r1=329188&r2=329189&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Wed Apr  4 06:04:15 2018
@@ -600,7 +600,7 @@ else()
 endif()
 
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND XRAY_SUPPORTED_ARCH AND
-    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD")
+    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|OpenBSD")
   set(COMPILER_RT_HAS_XRAY TRUE)
 else()
   set(COMPILER_RT_HAS_XRAY FALSE)

Modified: compiler-rt/trunk/lib/xray/xray_x86_64.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_x86_64.cc?rev=329189&r1=329188&r2=329189&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_x86_64.cc (original)
+++ compiler-rt/trunk/lib/xray/xray_x86_64.cc Wed Apr  4 06:04:15 2018
@@ -3,8 +3,12 @@
 #include "xray_defs.h"
 #include "xray_interface_internal.h"
 
-#if SANITIZER_FREEBSD || SANITIZER_NETBSD
+#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD
 #include <sys/types.h>
+#if SANITIZER_OPENBSD
+#include <sys/time.h>
+#include <machine/cpu.h>
+#endif
 #include <sys/sysctl.h>
 #endif
 
@@ -77,13 +81,18 @@ uint64_t getTSCFrequency() XRAY_NEVER_IN
   }
   return TSCFrequency == -1 ? 0 : static_cast<uint64_t>(TSCFrequency);
 }
-#elif SANITIZER_FREEBSD || SANITIZER_NETBSD
+#elif SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD
 uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
     long long TSCFrequency = -1;
     size_t tscfreqsz = sizeof(TSCFrequency);
+#if SANITIZER_OPENBSD
+    int Mib[2] = { CTL_MACHDEP, CPU_TSCFREQ };
+    if (sysctl(Mib, 2, &TSCFrequency, &tscfreqsz, NULL, 0) != -1) {
 
+#else
     if (sysctlbyname("machdep.tsc_freq", &TSCFrequency, &tscfreqsz,
         NULL, 0) != -1) {
+#endif
         return static_cast<uint64_t>(TSCFrequency);
     } else {
       Report("Unable to determine CPU frequency for TSC accounting.\n");




More information about the llvm-commits mailing list