diff options
author | Dean Michael Berris <dberris@google.com> | 2018-04-04 13:04:15 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2018-04-04 13:04:15 +0000 |
commit | ae804f9d681a5648ba9087c916b80835978908bd (patch) | |
tree | 45a0d048739041f9bfdf8e552bb5a1f8defcb0b2 /lib | |
parent | 66c28c2521ccc42f5052a1e603142498305c9f5a (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@329189 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/xray/xray_x86_64.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/xray/xray_x86_64.cc b/lib/xray/xray_x86_64.cc index dfd663152..52c5535c4 100644 --- a/lib/xray/xray_x86_64.cc +++ b/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"); |