summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-04-04 13:04:15 +0000
committerDean Michael Berris <dberris@google.com>2018-04-04 13:04:15 +0000
commitfe79b04a7441b5a1931d26fb268d942685af7c51 (patch)
tree17074a09dc35f9c82491f38e5a6ef9db9ce580b9
parentaf2dfc697bbba1dd4035671652e97a71c392fe69 (diff)
downloadbcm5719-llvm-fe79b04a7441b5a1931d26fb268d942685af7c51.tar.gz
bcm5719-llvm-fe79b04a7441b5a1931d26fb268d942685af7c51.zip
[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 llvm-svn: 329189
-rw-r--r--compiler-rt/cmake/config-ix.cmake2
-rw-r--r--compiler-rt/lib/xray/xray_x86_64.cc13
2 files changed, 12 insertions, 3 deletions
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 58377979adc..cdeae90d0d9 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -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)
diff --git a/compiler-rt/lib/xray/xray_x86_64.cc b/compiler-rt/lib/xray/xray_x86_64.cc
index dfd663152b2..52c5535c45d 100644
--- a/compiler-rt/lib/xray/xray_x86_64.cc
+++ b/compiler-rt/lib/xray/xray_x86_64.cc
@@ -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_INSTRUMENT {
}
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");
OpenPOWER on IntegriCloud