-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Setup:
- vcpkg is the package manager
- device: RPi 3B+
- OS: Raspian/Debian 12
- arch: arm7v
Repro:
Attempt to build the libwebsockets library
vcpkg install libwebsockets
Result:
Compilation fails.
Log:
In file included from /home/azure/agent/_work/55/no-cache/b/libwebsockets/src/v4.4.1-86cef274ae.clean/include/libwebsockets.h:778,
from /home/azure/agent/_work/55/no-cache/b/libwebsockets/src/v4.4.1-86cef274ae.clean/lib/core/./private-lib-core.h:150,
from /home/azure/agent/_work/55/no-cache/b/libwebsockets/src/v4.4.1-86cef274ae.clean/lib/plat/unix/unix-init.c:28:
/home/azure/agent/_work/55/no-cache/b/libwebsockets/src/v4.4.1-86cef274ae.clean/include/libwebsockets/lws-genhash.h:93:18: error: field ‘ctx’ has incomplete type
93 | HMAC_CTX ctx;
| ^~~
Investigation:
Investigation found that on this device the config call that sets up the LWS_HAVE_HMAC_CTX_new variable in tls/CMakeLists.txt always returns false on the system.
~line 349:
CHECK_FUNCTION_EXISTS(${VARIA}HMAC_CTX_new LWS_HAVE_HMAC_CTX_new PARENT_SCOPE)
OpenSSL is not installed on the system but it is built by vcpkg (as one of lws dependencies). I've verified that OpenSSL was properly built as a dependency. I've also confirmed that the vcpkg folders for include and libraries are listed in CMAKE_REQUIRED_INCLUDES and CMAKE_REQUIRED_LIBRARIES variables, respectively, before calling check_function_exists. Everything is properly setup but the check failed nonetheless.
The reason is because OpenSSL’s ARMv7 build depends on 64‑bit GCC atomics in libatomic. Without including that library as a required library, the check function would never succeed.
I wrote a simple test app to determine why the check was failing - was it really forcing use of the older api or something else?
App:
include <openssl/hmac.h>
int main() {
HMAC_CTX *ctx = HMAC_CTX_new();
return ctx == NULL;
}
Result of Compilation without atomic
Failure with warnings and lots of linker errors
gcc test.cpp -I/home/azure/agent/_work/69/vcpkg/installed/arm-linux/include -L/home/azure/agent/_work/69/vcpkg/installed/arm-linux/lib -lcrypto -lssl -o test
test.cpp: In function ‘int main()’:
test.cpp:3:42: warning: ‘HMAC_CTX* HMAC_CTX_new()’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
3 | int main() { HMAC_CTX *ctx = HMAC_CTX_new(); return ctx == NULL; }
| ~~~~~~~~~~~~^~
In file included from test.cpp:1:
/home/azure/agent/_work/69/vcpkg/installed/arm-linux/include/openssl/hmac.h:33:33: note: declared here
33 | OSSL_DEPRECATEDIN_3_0 HMAC_CTX *HMAC_CTX_new(void);
| ^~~~~~~~~~~~
/usr/bin/ld: /home/azure/agent/_work/69/vcpkg/installed/arm-linux/lib/libcrypto.a(libcrypto-lib-threads_pthread.o): in function `ossl_rcu_read_lock':
threads_pthread.c:(.text+0x304): undefined reference to `__atomic_fetch_sub_8'
/usr/bin/ld: threads_pthread.c:(.text+0x320): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: /home/azure/agent/_work/69/vcpkg/installed/arm-linux/lib/libcrypto.a(libcrypto-lib-threads_pthread.o): in function `ossl_rcu_read_unlock':
Result of Compilation with atomic
Success with warnings:
gcc test.cpp -I/home/azure/agent/_work/69/vcpkg/installed/arm-linux/include -L/home/azure/agent/_work/69/vcpkg/installed/arm-linux/lib -lcrypto -lssl -latomic -o test
test.cpp: In function ‘int main()’:
test.cpp:3:42: warning: ‘HMAC_CTX* HMAC_CTX_new()’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
3 | int main() { HMAC_CTX *ctx = HMAC_CTX_new(); return ctx == NULL; }
| ~~~~~~~~~~~~^~
In file included from test.cpp:1:
/home/azure/agent/_work/69/vcpkg/installed/arm-linux/include/openssl/hmac.h:33:33: note: declared here
33 | OSSL_DEPRECATEDIN_3_0 HMAC_CTX *HMAC_CTX_new(void);
| ^~~~~~~~~~~~
Result: the program compiles and links. Only warnings stating that a deprecated api is in use. This provided 2 key pieces of info - the atomic library needed to be referenced, and the built version of OpenSSL was usable for the LWS_HAVE_HMAC_CTX_new compilation branches.
I will push a PR shortly that contains a recommended fix.
Reference issue:
microsoft/vcpkg#48725