Skip to content

Android: link libdl into rnp's OpenSSL feature probe - #376

Open
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:fix/android-rnp-probe-libdl
Open

Android: link libdl into rnp's OpenSSL feature probe#376
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:fix/android-rnp-probe-libdl

Conversation

@jolavillette

Copy link
Copy Markdown
Contributor

build_librnp fails while rnp configures itself:

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

rnp compiles a small 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:

if(CMAKE_CROSSCOMPILING_EMULATOR)
  target_link_options(findopensslfeatures PRIVATE -static)
endif(CMAKE_CROSSCOMPILING_EMULATOR)

but OpenSSL 1.1.1's 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. The link line ends up as

clang -O3 -DNDEBUG -static ...o -o findopensslfeatures  .../libcrypto.a -pthread

with nothing providing dlopen, dlsym, dlclose and dlerror.

The NDK does ship a static libdl.a defining those four for real, so it is
enough to link it. It is added as a linked library rather than through
CMAKE_EXE_LINKER_FLAGS, because CMake places that variable before the
objects, where a static linker has no undefined symbol to resolve yet and drops
the archive silently.

This is arguably rnp's bug — their -static path looks untested against a
static OpenSSL 1.1.1 — so the patch stays a sed next to the existing ones, and
should be dropped once rnp handles it.

Verified

build_librnp completes and installs librnp.a in the sysroot, and the whole
AAR now builds: 42 MB, jni/arm64-v8a/libretroshare.so exporting JNI_OnLoad,
the four org.retroshare.service classes in classes.jar. Ubuntu 24.04, NDK
29.0.14206865, API level 24, arm64-v8a, on top of #373 and #375.

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) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant