From e98aa461df2de61507767b821dbbf0972cfb285f Mon Sep 17 00:00:00 2001 From: Michael Altizer Date: Thu, 15 Aug 2019 14:41:01 -0400 Subject: [PATCH] time: Make TscClock fail to compile on non-x86/AArch64 systems Also, don't bother to install tsc_clock.h when Snort is compiled without TSC clock support. Thanks to Bill Meeks for reporting the issue. --- src/time/CMakeLists.txt | 19 +++++++++++-------- src/time/tsc_clock.h | 12 ++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/time/CMakeLists.txt b/src/time/CMakeLists.txt index 91ea5345b..ab93755c9 100644 --- a/src/time/CMakeLists.txt +++ b/src/time/CMakeLists.txt @@ -1,22 +1,25 @@ +set ( TIME_INCLUDES + clock_defs.h + packet_time.h + stopwatch.h +) + set ( TIME_INTERNAL_SOURCES packet_time.cc periodic.cc periodic.h timersub.h - tsc_clock.cc ) +if ( USE_TSC_CLOCK ) + list ( APPEND TIME_INCLUDES tsc_clock.h ) + list ( APPEND TIME_INTERNAL_SOURCES tsc_clock.cc ) +endif ( USE_TSC_CLOCK ) + if ( ENABLE_UNIT_TESTS ) list ( APPEND TIME_INTERNAL_SOURCES stopwatch_test.cc ) endif ( ENABLE_UNIT_TESTS ) -set ( TIME_INCLUDES - clock_defs.h - packet_time.h - stopwatch.h - tsc_clock.h -) - add_library ( time OBJECT ${TIME_INTERNAL_SOURCES} ${TIME_INCLUDES} diff --git a/src/time/tsc_clock.h b/src/time/tsc_clock.h index 342652503..73573ab0b 100644 --- a/src/time/tsc_clock.h +++ b/src/time/tsc_clock.h @@ -44,16 +44,16 @@ struct TscClock static uint64_t counter() { -#if defined(__aarch64__) +#if defined(__i386__) || defined(__x86_64__) + uint32_t lo, hi; + asm volatile("rdtsc" : "=a" (lo), "=d" (hi)); + return ((uint64_t)hi << 32) | lo; +#elif defined(__aarch64__) uint64_t ticks; - asm volatile("mrs %0, CNTVCT_EL0" : "=r" (ticks)); return ticks; #else - // Default to x86, other archs will compile error anyway - uint32_t lo, hi; - asm volatile("rdtsc" : "=a" (lo), "=d" (hi)); - return ((uint64_t)hi << 32) | lo; +#error "TscClock is not supported on this architecture!" #endif } -- 2.47.3