openssl: crypto/threads_pthread.c: compilation fails on RHEL 6 and SLES 11

There’s a copy and paste error in crypto/threads_pthread.c likely introduced by #26478. Lines 196 and 214 are the same. Compilation error:

crypto/threads_pthread.c:214: error: redefinition of 'fallback_atomic_exchange_n_uint64_t'
crypto/threads_pthread.c:196: note: previous definition of 'fallback_atomic_exchange_n_uint64_t' was here
crypto/threads_pthread.c: In function 'update_qp':
crypto/threads_pthread.c:564: warning: implicit declaration of function 'fallback_atomic_compare_exchange_n_uint64_t'
crypto/threads_pthread.c:564: error: '__ATOMIC_ACQ_REL' undeclared (first use in this function)
crypto/threads_pthread.c:564: error: (Each undeclared identifier is reported only once
crypto/threads_pthread.c:564: error: for each function it appears in.)
crypto/threads_pthread.c:564: error: '__ATOMIC_RELAXED' undeclared (first use in this function)

The trivial patch should be:

--- crypto/threads_pthread.c	2025-02-11 21:59:59.585719305 +0100
+++ crypto/threads_pthread.c	2025-02-11 22:42:55.183159198 +0100
@@ -211,7 +211,7 @@
         return ret;                                                                   \
     }
 
-IMPL_fallback_atomic_exchange_n(uint64_t)
+IMPL_fallback_atomic_compare_exchange_n(uint64_t)
 
 #  define ATOMIC_COMPARE_EXCHANGE_N(t, p, e, d, s, f) fallback_atomic_compare_exchange_n_##t(p, e, d, s, f)

Observed for OpenSSL 3.4.1. Code seems to contain the same problem for main. I didn’t check which other versions might also be broken.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

The patch needs to be enhanced, maybe:

@@ -199,7 +199,7 @@
 #  define ATOMIC_EXCHANGE_N(t, p, v, o) fallback_atomic_exchange_n_##t(p, v)
 
 #  define IMPL_fallback_atomic_compare_exchange_n(t)                                  \
-    static ossl_inline int fallback_atomic_compare_exchange_n_##t(t *p, t *e, t d, s, f) \
+    static ossl_inline int fallback_atomic_compare_exchange_n_##t(t *p, t *e, t d, int s, int f) \
     {                                                                                 \
         int ret = 1;                                                                 \
         pthread_mutex_lock(&atomic_sim_lock);                                         \
@@ -210,8 +210,7 @@
         pthread_mutex_unlock(&atomic_sim_lock);                                       \
         return ret;                                                                   \
     }
-
-IMPL_fallback_atomic_exchange_n(uint64_t)
+IMPL_fallback_atomic_compare_exchange_n(uint64_t)
 
 #  define ATOMIC_COMPARE_EXCHANGE_N(t, p, e, d, s, f) fallback_atomic_compare_exchange_n_##t(p, e, d, s, f)
 

But even then, the second part of the error still happens:

crypto/threads_pthread.c: In function 'update_qp':
crypto/threads_pthread.c:563: error: '__ATOMIC_ACQ_REL' undeclared (first use in this function)
crypto/threads_pthread.c:563: error: (Each undeclared identifier is reported only once
crypto/threads_pthread.c:563: error: for each function it appears in.)
crypto/threads_pthread.c:563: error: '__ATOMIC_RELAXED' undeclared (first use in this function)