Fix glibc version detection.
authorPauli <paul.dale@oracle.com>
Thu, 8 Feb 2018 01:04:30 +0000 (11:04 +1000)
committerRichard Levitte <levitte@openssl.org>
Fri, 9 Feb 2018 09:10:45 +0000 (10:10 +0100)
Simplify Posix timer detection.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5279)

crypto/rand/rand_lib.c

index 69c3c79c6da29624d0c61e04fed4c05d45e149a2..faec18dd99251ff937501ce007ed4229e4a86063 100644 (file)
 /* Macro to convert two thirty two bit values into a sixty four bit one */
 #define TWO32TO64(a, b) ((((uint64_t)(a)) << 32) + (b))
 
 /* Macro to convert two thirty two bit values into a sixty four bit one */
 #define TWO32TO64(a, b) ((((uint64_t)(a)) << 32) + (b))
 
+/*
+ * Check for the existence and support of POSIX timers.  The standard
+ * says that the _POSIX_TIMERS macro will have a positive value if they
+ * are available.
+ *
+ * However, we want an additional constraint: that the timer support does
+ * not require an extra library dependency.  Early versions of glibc
+ * require -lrt to be specified on the link line to access the timers,
+ * so this needs to be checked for.
+ *
+ * It is worse because some libraries define __GLIBC__ but don't
+ * support the version testing macro (e.g. uClibc).  This means
+ * an extra check is needed.
+ *
+ * The final condition is:
+ *      "have posix timers and either not glibc or glibc without -lrt"
+ *
+ * The nested #if sequences are required to avoid using a parameterised
+ * macro that might be undefined.
+ */
+#undef OSSL_POSIX_TIMER_OKAY
+#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
+# if defined(__GLIBC__)
+#  if defined(__GLIBC_PREREQ)
+#   if __GLIBC_PREREQ(2, 17)
+#    define OSSL_POSIX_TIMER_OKAY
+#   endif
+#  endif
+# else
+#  define OSSL_POSIX_TIMER_OKAY
+# endif
+#endif
+
 #ifndef OPENSSL_NO_ENGINE
 /* non-NULL if default_RAND_meth is ENGINE-provided */
 static ENGINE *funct_ref;
 #ifndef OPENSSL_NO_ENGINE
 /* non-NULL if default_RAND_meth is ENGINE-provided */
 static ENGINE *funct_ref;
@@ -228,11 +261,7 @@ static uint64_t get_timer_bits(void)
     }
 #else
 
     }
 #else
 
-# if defined(_POSIX_C_SOURCE) \
-     && defined(_POSIX_TIMERS) \
-     && _POSIX_C_SOURCE >= 199309L \
-     && (!defined(__GLIBC__) \
-         || (defined(__GLIBC_PREREQ) && __GLIBC_PREREQ(2, 17)))
+#if defined(OSSL_POSIX_TIMER_OKAY)
     {
         struct timespec ts;
         clockid_t cid;
     {
         struct timespec ts;
         clockid_t cid;