Skip to contentSkip to conversation

package/libwebsockets: fix OpenSSL detection without libatomic

PATCH Applied Yegor Yefremov 2 participants 3 messages Oct 27 – Nov 6

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/libwebsockets: fix OpenSSL detection without libatomic

Since version 4.5.3, libwebsockets adds -latomic to the libraries used by its OpenSSL API probes whenever 64-bit atomics don't work out of the box, without checking that libatomic is available. Buildroot toolchains without thread support don't provide libatomic, so on a CPU without native 64-bit atomics (e.g. ARMv5) all probes fail to link:

ld: cannot find -latomic: No such file or directory

libwebsockets then assumes a pre-1.1 OpenSSL and fails to build:

-- Performing Test HAVE_WORKING_ATOMIC_64 - Failed
[...]
-- Looking for HMAC_CTX_new - not found
[...]
include/libwebsockets/lws-genhash.h:93:18: error: field 'ctx' has incomplete type
93 | HMAC_CTX ctx;
| ^~~

Add a patch, sent upstream, to only use libatomic if linking against it makes the 64-bit atomics test pass.

This issue has been present since commit 20c3eb6eb684 ("package/libwebsockets: bump version to 4.5.7"), which bumped libwebsockets from 4.4.1 to 4.5.7, the atomic check having been added in 4.5.3. It therefore affects 2026.05 and later.

Fixes:
https://autobuild.buildroot.org/results/863c30265623973e15a25c2d38c0e1631a39b7e8

Fixes 20c3eb6eb68432c37d5db69963be266b7f2d23f7 ("package/libwebsockets: bump version to 4.5.7")
Assisted-by Claude:claude-opus-5-5
---
 ...ly-link-libatomic-if-it-is-available.patch | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 package/libwebsockets/0001-cmake-openssl-only-link-libatomic-if-it-is-available.patch
package/libwebsockets/0001-cmake-openssl-only-link-libatomic-if-it-is-available.patch new file +61 -0
new file mode 100644
index 0000000000..84724f9c50
@@ -0,0 +1,61 @@
+From e0480a47e95a0d74c826926ae6bfef14fc8d988f Mon Sep 17 00:00:00 2001
+From: Yegor Yefremov <[email protected]>
+Date: Tue, 27 Oct 2026 08:47:29 +0100
+Subject: [PATCH] cmake: openssl: only link libatomic if it is available
+
+Commit 09aade8c9 ("cmake: openssl: Added check for atomic library")
+adds -latomic to CMAKE_REQUIRED_LIBRARIES whenever 64-bit atomics
+don't work out of the box, without checking that libatomic exists.
+
+Some toolchains don't provide libatomic at all, e.g. GCC toolchains
+built without thread support, as libatomic relies on pthreads. On such
+a toolchain for a CPU without native 64-bit atomics (e.g. ARMv5), every
+OpenSSL API probe then fails to link:
+
+  ld: cannot find -latomic: No such file or directory
+
+so lws believes it deals with a pre-1.1 OpenSSL and the build fails:
+
+  include/libwebsockets/lws-genhash.h:93:18: error: field 'ctx' has incomplete type
+     93 |         HMAC_CTX ctx;
+        |                  ^~~
+
+Only use libatomic if linking against it makes the 64-bit atomics
+test pass.
+
+Assisted-by: Claude:claude-opus-5-5
+Upstream: sent to Andy Green <[email protected]> on 2026-10-27
+Signed-off-by: Yegor Yefremov <[email protected]>
+---
+ lib/tls/CMakeLists.txt | 15 +++++++++++----
+ 1 file changed, 11 insertions(+), 4 deletions(-)
+
+diff --git a/lib/tls/CMakeLists.txt b/lib/tls/CMakeLists.txt
+index d91c3dab6..9060d32fe 100644
+--- a/lib/tls/CMakeLists.txt
++++ b/lib/tls/CMakeLists.txt
+@@ -564,10 +564,17 @@ if (DEFINED LIB_LIST)
+ endif()
+ if(UNIX AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
+   check_c_source_compiles("int main() { long long x = 0; __atomic_fetch_add(&x, 1, __ATOMIC_SEQ_CST); return 0; }" HAVE_WORKING_ATOMIC_64)
+-  if(HAVE_WORKING_ATOMIC_64)
+-    set(LWS_ATOMIC_LIB "")
+-  else()
+-    set(LWS_ATOMIC_LIB atomic)
++  set(LWS_ATOMIC_LIB "")
++  if(NOT HAVE_WORKING_ATOMIC_64)
++    # libatomic is not always available (eg, toolchains without threads),
++    # only use it if it actually provides the 64-bit atomics
++    set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
++    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic)
++    check_c_source_compiles("int main() { long long x = 0; __atomic_fetch_add(&x, 1, __ATOMIC_SEQ_CST); return 0; }" HAVE_WORKING_ATOMIC_64_WITH_LIBATOMIC)
++    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
++    if(HAVE_WORKING_ATOMIC_64_WITH_LIBATOMIC)
++      set(LWS_ATOMIC_LIB atomic)
++    endif()
+   endif()
+ endif()
+ if (UNIX AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX"))
+-- 
+2.34.1
+
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 26 lines · Yegor Yefremov

Since version 4.5.3, libwebsockets adds -latomic to the libraries used by its OpenSSL API probes whenever 64-bit atomics don't work out of the box, without checking that libatomic is available. Buildroot toolchains without thread support don't provide libatomic, so on a CPU without native 64-bit atomics (e.g. ARMv5) all probes fail to link:

ld: cannot find -latomic: No such file or directory

libwebsockets then assumes a pre-1.1 OpenSSL and fails to build:

-- Performing Test HAVE_WORKING_ATOMIC_64 - Failed
[...]
-- Looking for HMAC_CTX_new - not found
[...]
include/libwebsockets/lws-genhash.h:93:18: error: field 'ctx' has incomplete type
93 | HMAC_CTX ctx;
| ^~~

Add a patch, sent upstream, to only use libatomic if linking against it makes the 64-bit atomics test pass.

This issue has been present since commit 20c3eb6eb684 ("package/libwebsockets: bump version to 4.5.7"), which bumped libwebsockets from 4.4.1 to 4.5.7, the atomic check having been added in 4.5.3. It therefore affects 2026.05 and later.

Quoted 6 lines

Fixes:
https://autobuild.buildroot.org/results/863c30265623973e15a25c2d38c0e1631a39b7e8

Fixes 20c3eb6eb68432c37d5db69963be266b7f2d23f7 ("package/libwebsockets: bump version to 4.5.7")
Assisted-by Claude:claude-opus-5-5

Applied to master, thanks!

Best regards,

Thomas Petazzoni

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Yegor Yefremov

In reply of:

Quoted 26 lines

Since version 4.5.3, libwebsockets adds -latomic to the libraries used by its OpenSSL API probes whenever 64-bit atomics don't work out of the box, without checking that libatomic is available. Buildroot toolchains without thread support don't provide libatomic, so on a CPU without native 64-bit atomics (e.g. ARMv5) all probes fail to link:

ld: cannot find -latomic: No such file or directory

libwebsockets then assumes a pre-1.1 OpenSSL and fails to build:

-- Performing Test HAVE_WORKING_ATOMIC_64 - Failed
[...]
-- Looking for HMAC_CTX_new - not found
[...]
include/libwebsockets/lws-genhash.h:93:18: error: field 'ctx' has incomplete type
93 | HMAC_CTX ctx;
| ^~~

Add a patch, sent upstream, to only use libatomic if linking against it makes the 64-bit atomics test pass.

This issue has been present since commit 20c3eb6eb684 ("package/libwebsockets: bump version to 4.5.7"), which bumped libwebsockets from 4.4.1 to 4.5.7, the atomic check having been added in 4.5.3. It therefore affects 2026.05 and later.

Quoted 6 lines

Fixes:
https://autobuild.buildroot.org/results/863c30265623973e15a25c2d38c0e1631a39b7e8

Fixes 20c3eb6eb68432c37d5db69963be266b7f2d23f7 ("package/libwebsockets: bump version to 4.5.7")
Assisted-by Claude:claude-opus-5-5

Applied to 2026.08.x. Thanks

Quoted 62 lines
---
 ...ly-link-libatomic-if-it-is-available.patch | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 package/libwebsockets/0001-cmake-openssl-only-link-libatomic-if-it-is-available.patch
package/libwebsockets/0001-cmake-openssl-only-link-libatomic-if-it-is-available.patch new file +51 -0
new file mode 100644
index 0000000000..84724f9c50
@@ -0,0 +1,61 @@
+From e0480a47e95a0d74c826926ae6bfef14fc8d988f Mon Sep 17 00:00:00 2001
+From: Yegor Yefremov <[email protected]>
+Date: Tue, 27 Oct 2026 08:47:29 +0100
+Subject: [PATCH] cmake: openssl: only link libatomic if it is available
+
+Commit 09aade8c9 ("cmake: openssl: Added check for atomic library")
+adds -latomic to CMAKE_REQUIRED_LIBRARIES whenever 64-bit atomics
+don't work out of the box, without checking that libatomic exists.
+
+Some toolchains don't provide libatomic at all, e.g. GCC toolchains
+built without thread support, as libatomic relies on pthreads. On such
+a toolchain for a CPU without native 64-bit atomics (e.g. ARMv5), every
+OpenSSL API probe then fails to link:
+
+  ld: cannot find -latomic: No such file or directory
+
+so lws believes it deals with a pre-1.1 OpenSSL and the build fails:
+
+  include/libwebsockets/lws-genhash.h:93:18: error: field 'ctx' has incomplete type
+     93 |         HMAC_CTX ctx;
+        |                  ^~~
+
+Only use libatomic if linking against it makes the 64-bit atomics
+test pass.
+
+Assisted-by: Claude:claude-opus-5-5
+Upstream: sent to Andy Green <[email protected]> on 2026-10-27
+Signed-off-by: Yegor Yefremov <[email protected]>
+---
+ lib/tls/CMakeLists.txt | 15 +++++++++++----
+ 1 file changed, 11 insertions(+), 4 deletions(-)
+
+diff --git a/lib/tls/CMakeLists.txt b/lib/tls/CMakeLists.txt
+index d91c3dab6..9060d32fe 100644
+--- a/lib/tls/CMakeLists.txt
++++ b/lib/tls/CMakeLists.txt
+@@ -564,10 +564,17 @@ if (DEFINED LIB_LIST)
+ endif()
+ if(UNIX AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang"))
+   check_c_source_compiles("int main() { long long x = 0; __atomic_fetch_add(&x, 1, __ATOMIC_SEQ_CST); return 0; }" HAVE_WORKING_ATOMIC_64)
+-  if(HAVE_WORKING_ATOMIC_64)
+-    set(LWS_ATOMIC_LIB "")
+-  else()
+-    set(LWS_ATOMIC_LIB atomic)
++  set(LWS_ATOMIC_LIB "")
++  if(NOT HAVE_WORKING_ATOMIC_64)
++    # libatomic is not always available (eg, toolchains without threads),
++    # only use it if it actually provides the 64-bit atomics
++    set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
++    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic)
++    check_c_source_compiles("int main() { long long x = 0; __atomic_fetch_add(&x, 1, __ATOMIC_SEQ_CST); return 0; }" HAVE_WORKING_ATOMIC_64_WITH_LIBATOMIC)

package/libwebsockets/0001-cmake-openssl-only-link-libatomic-if-it-is-available.patch line 61

Quoted 10 lines
package/libwebsockets/0001-cmake-openssl-only-link-libatomic-if-it-is-available.patch new file +10 -0
++    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
++    if(HAVE_WORKING_ATOMIC_64_WITH_LIBATOMIC)
++      set(LWS_ATOMIC_LIB atomic)
++    endif()
+   endif()
+ endif()
+ if (UNIX AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX"))
+-- 
+2.34.1
+

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot