bitcoin: Unable to build BDB 4.8 on macOS Big Sur beta or Xcode 12.0

Update 22-9-2020: this happens on macOS Catalina as well with Xcode 12.0

Update 9-10-2020; workaround suggested by @willcl-ark:

brew install llvm
export LLVM_PREFIX=$(brew --prefix llvm)
CC=$LLVM_PREFIX/bin/clang CXX=$LLVM_PREFIX/bin/clang++ LDFLAGS="-L$LLVM_PREFIX/opt/llvm/lib -Wl,-rpath,$LLVM_PREFIX/opt/llvm/lib" ./contrib/install_db4.sh .

Update 20-10-2020: better workaround suggested by @fanquake:

CFLAGS="-Wno-error=implicit-function-declaration"  ./contrib/install_db4.sh .

For more problems with macOS Big Sur (beta) see #19406.

I’m unable to build Berkeley DB 4.8. When using depends as when using contrib/install_db4.sh:

checking for mutexes... UNIX/fcntl
configure: WARNING: NO SHARED LATCH IMPLEMENTATION FOUND FOR THIS PLATFORM.
configure: error: Unable to find a mutex implementation

configure.log stdout from Big Sur beta config.log on Catalina with Xcode 12.0

I got the same error when compiling for iOs in #12557.

On macOS Catalina it finds the following:

checking for mutexes... POSIX/pthreads/library/x86_64/gcc-assembly

So perhaps something moved or was removed…

Looking at dist/configure I think I narrowed it down to this check:

#include <pthread.h>
main() {
	pthread_cond_t cond;
	pthread_mutex_t mutex;
	pthread_condattr_t condattr;
	pthread_mutexattr_t mutexattr;
	exit (
	pthread_condattr_init(&condattr) ||
	pthread_condattr_setpshared(&condattr, PTHREAD_PROCESS_SHARED) ||
	pthread_mutexattr_init(&mutexattr) ||
	pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED) ||
	pthread_cond_init(&cond, &condattr) ||
	pthread_mutex_init(&mutex, &mutexattr) ||
	pthread_mutex_lock(&mutex) ||
	pthread_mutex_unlock(&mutex) ||
	pthread_mutex_destroy(&mutex) ||
	pthread_cond_destroy(&cond) ||
	pthread_condattr_destroy(&condattr) ||
	pthread_mutexattr_destroy(&mutexattr));
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
  db_cv_mutex="POSIX/pthreads/library"
fi

If I replace the main() function body with exit(0); it still fails, but it’s “happy” when why I use return 0;. I initially assumed this was a -Werror=return-type problem, but something like exit(0); return 0; doesn’t work either. I don’t know how to inspect the compilation output.

I can replace exit with return in the above function and it compiles, bitcoind builds and wallet tests pass.

This suggests an obvious patch, but also a bit of a mystery.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 30 (24 by maintainers)

Commits related to this issue

Most upvoted comments

Another (simpler) workaround:

./install_db4.sh . --disable-mutexsupport

All wallet tests still pass, but the implications of no mutexes in the wallet db are, scary? EDIT: wallet tests do not pass (Was using the wrong db to build Bitcoin Core, had one in src/ and one in src/contrib/)

I notice that Core has a specific pthread m4 in build-aux/m4/ax_pthread.m4, which seems to be the offending header in the BDB configure, so might investigate the differences if I don’t have any other luck.

More promising I think might be to investigate this known issue of Big Sur:

New in macOS Big Sur 11 beta, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286)