Skip to content

Fix undefined references with --disable-shared.

orbea - requested to merge orbea/openldap:threads into master

When building openldap with --disable-shared and slibtool (https://dev.midipix.org/cross/slibtool) the build fails in several ways with undefined pthread references.

rdlibtool --mode=link cc -static -g -O2 -o apitest apitest.o libldap.la ../../libraries/liblber/liblber.la ../../libraries/liblutil/liblutil.a -lgnutls -luuid -lresolv

rdlibtool: lconf: {.name="libtool"}.
rdlibtool: fdcwd: {.fdcwd=AT_FDCWD, .realpath="/tmp/openldap/libraries/libldap"}.
rdlibtool: lconf: fstatat(AT_FDCWD,".",...) = 0 {.st_dev = 45, .st_ino = 121993}.
rdlibtool: lconf: openat(AT_FDCWD,"libtool",O_RDONLY,0) = -1 [ENOENT].
rdlibtool: lconf: openat(AT_FDCWD,"../",O_DIRECTORY,0) = 3.
rdlibtool: lconf: fstat(3,...) = 0 {.st_dev = 45, .st_ino = 121923}.
rdlibtool: lconf: openat(3,"libtool",O_RDONLY,0) = -1 [ENOENT].
rdlibtool: lconf: openat(3,"../",O_DIRECTORY,0) = 4.
rdlibtool: lconf: fstat(4,...) = 0 {.st_dev = 45, .st_ino = 120454}.
rdlibtool: lconf: openat(4,"libtool",O_RDONLY,0) = 3.
rdlibtool: lconf: found "/tmp/openldap/libtool".
rdlibtool: link: cc apitest.o .libs/libldap.a ../../libraries/liblber/.libs/liblber.a ../../libraries/liblutil/liblutil.a -g -O2 -L.libs -lresolv -lgnutls -lresolv -luuid -lresolv -o .libs/apitest
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: .libs/libldap.a(thr_posix.o): undefined reference to symbol 'pthread_rwlock_trywrlock@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
rdlibtool: exec error upon slbt_exec_link_create_executable(), line 1614: (see child process error messages).
rdlibtool: < returned to > slbt_exec_link(), line 1934.
make[2]: *** [Makefile:319: apitest] Error 2
make[2]: Leaving directory '/tmp/openldap/libraries/libldap'
make[1]: *** [Makefile:308: all-common] Error 1
make[1]: Leaving directory '/tmp/openldap/libraries'
make: *** [Makefile:316: all-common] Error 1

My understanding is that building static libraries exposes undefined references that otherwise would be exposed with -no-undefined. I am not sure how GNU libtool avoids this, perhaps it silently adds -lpthread? For the record GNU libtool will silently ignore -no-undefind while slibtool will not.

This exposes several related issues in openldap.

  • libldap has no configure check indicating it requires --with-threads.
  • libldap does add $(LTHREAD_LIBS) to its $(LINK_LIBS), but then actually fails to use it.
  • The client tools requires threads, but they also have no configure check indicating so.
  • The client tools do not have a configure check to disable them, but there is a --without-threads.
  • The client tools really do needs $(LTHREAD_LIBS) added to the $(LINK_LIBS).

This PR fixes all of the above including adding --enable-tools and allows the build with slibtool or GNU libtool and --disable-shared to complete successfully.

Merge request reports