]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
time: Make TscClock fail to compile on non-x86/AArch64 systems
authorMichael Altizer <mialtize@cisco.com>
Thu, 15 Aug 2019 18:41:01 +0000 (14:41 -0400)
committerMichael Altizer <mialtize@cisco.com>
Thu, 15 Aug 2019 18:43:03 +0000 (14:43 -0400)
Also, don't bother to install tsc_clock.h when Snort is compiled without
TSC clock support.

Thanks to Bill Meeks <billmeeks8@gmail.com> for reporting the issue.

src/time/CMakeLists.txt
src/time/tsc_clock.h

index 91ea5345b426a20b325ca0e5b46fa2fcdad9e931..ab93755c992b1d1251ed8ac8f64b6dfbd5d9ab0f 100644 (file)
@@ -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}
index 342652503b1fb2278d0b991bd5af5bb8e4821312..73573ab0bcbb0b7cb40827498b2deca64f7fd3c5 100644 (file)
@@ -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
     }