From bd4485e6b8be53c42dab8b4331bd7621ff16a44b Mon Sep 17 00:00:00 2001 From: jolavillette Date: Mon, 17 Aug 2026 09:33:14 +0200 Subject: [PATCH] Android: link libdl into rnp's OpenSSL feature probe rnp builds a findopensslfeatures helper and runs it to enumerate the OpenSSL features. When cross-compiling it links that helper statically so it does not need the Android dynamic linker, but OpenSSL 1.1.1 libcrypto.a pulls in dso_dlfcn.o, which references the dl* API, and CMake's FindOpenSSL does not add ${CMAKE_DL_LIBS} to the OpenSSL::Crypto interface here. Nothing provides those symbols and build_librnp dies at ld.lld: error: undefined symbol: dlopen >>> referenced by dso_dlfcn.c >>> dso_dlfcn.o:(dlfcn_load) in archive >>> .../sysroot/usr/lib/libcrypto.a CMake Error at cmake/Modules/FindOpenSSLFeatures.cmake:149 (message): Error building findopensslfeatures The NDK ships a static libdl.a defining dlopen/dlsym/dlclose/dlerror, so link it explicitly. It is added as a linked library, not through CMAKE_EXE_LINKER_FLAGS, because it must appear after libcrypto.a on the link line for the static linker to resolve from it. Co-Authored-By: Claude Opus 5 (1M context) --- misc/Android/prepare-toolchain-clang.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/misc/Android/prepare-toolchain-clang.sh b/misc/Android/prepare-toolchain-clang.sh index 43f2103de..b232aee59 100755 --- a/misc/Android/prepare-toolchain-clang.sh +++ b/misc/Android/prepare-toolchain-clang.sh @@ -878,6 +878,23 @@ endif(CMAKE_CROSSCOMPILING_EMULATOR)' \ sed -i 's|COMMAND "${FOF}" "${feature}"|COMMAND ${FOF} "${feature}"|' \ "${S_dir}/cmake/Modules/FindOpenSSLFeatures.cmake" + # The feature probe is linked statically, and OpenSSL 1.1.1 libcrypto.a + # pulls in dso_dlfcn.o which references dlopen/dlsym/dlclose/dlerror. + # CMake's FindOpenSSL does not put ${CMAKE_DL_LIBS} in the OpenSSL::Crypto + # interface here, so nothing provides them and the link dies with + # + # ld.lld: error: undefined symbol: dlopen + # >>> referenced by dso_dlfcn.c + # >>> dso_dlfcn.o:(dlfcn_load) in archive .../libcrypto.a + # + # The NDK ships a static libdl.a defining those symbols, so link it + # explicitly. It has to come after libcrypto.a for the static linker to + # pick it up, hence a linked library rather than CMAKE_EXE_LINKER_FLAGS, + # which CMake places before the objects. + sed -i \ + 's|(findopensslfeatures PRIVATE OpenSSL::Crypto)|(findopensslfeatures PRIVATE OpenSSL::Crypto dl)|' \ + "${S_dir}/cmake/Modules/FindOpenSSLFeatures.cmake" + rm -rf "$B_dir"; mkdir "$B_dir" pushd "$B_dir" || return $? # CRYPTO_BACKEND use openssl on which we already depends instead of default