Unable to build BDB 4.8 on macOS Big Sur beta or Xcode 12.0 #19411

issue Sjors opened this issue on June 29, 2020
  1. Sjors commented at 1:44 PM on June 29, 2020: member

    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.

  2. Sjors added the label Bug on Jun 29, 2020
  3. jakeleventhal commented at 7:00 AM on July 31, 2020: contributor

    @Sjors where were you making this patch? having trouble with this myself

  4. Sjors commented at 5:03 PM on July 31, 2020: member

    @jakeleventhal I haven't tried. In fact I had to ditch my Big Sur machine because it was broken. Will probably upgrade another machine later this summer and try again.

  5. jakeleventhal commented at 6:33 AM on August 2, 2020: contributor

    @Sjors i only have one machine and i need it on big sur. is there a docker image you recommend using that i can just share my workspace with as a volume? one that has most of everything installed already?

  6. jakeleventhal commented at 5:57 PM on August 2, 2020: contributor

    Update: cdecker/bitcoin-dev:common is a good docker image that lets you build bitcoin for anyone who comes across this issue in the future

  7. BioMike commented at 12:14 PM on September 21, 2020: none

    It seems that passing --enable-posixmutexes is sufficient to get configure to continue and the build to succeed. This finds /POSIX/pthreads/private when looking for mutexes. Not sure if the build libdb behaves properly though.

  8. BioMike commented at 12:14 PM on September 21, 2020: none

    It seems that passing --enable-posixmutexes is sufficient to get configure to continue and the build to succeed. This finds /POSIX/pthreads/private when looking for mutexes. Not sure if the build libdb behaves properly though.

  9. Sjors renamed this:
    Unable to build BDB 4.8 on macOS Big Sur beta (depends & contrib script)
    Unable to build BDB 4.8 on macOS Big Sur beta or Xcode 12.0
    on Sep 22, 2020
  10. Sjors commented at 10:41 AM on September 22, 2020: member

    @BioMike I tried contrib/install_db4.sh . --enable-posixmutexes but it still fails for me with checking for mutexes... configure: error: unable to find POSIX 1003.1 mutex interfaces

  11. le2Ks commented at 8:12 PM on September 24, 2020: none

    @Sjors Did you solve it? I'm stuck as you at this same error after tried with --enable-posixmutexes

  12. BioMike commented at 10:04 AM on September 25, 2020: none

    How about --with-mutex=Darwin/_spin_lock_try?

  13. Sjors commented at 3:00 PM on September 28, 2020: member

    Mmm, that's at least a different error:

    ./libtool --mode=compile cc -c -I. -I/Users/sjors/dev/bitcoin/db4/db-4.8.30.NC/dist/..  -O3  /Users/sjors/dev/bitcoin/db4/db-4.8.30.NC/dist/../mutex/mut_tas.c
    libtool: compile:  cc -c -I. -I/Users/sjors/dev/bitcoin/db4/db-4.8.30.NC/dist/.. -O3 /Users/sjors/dev/bitcoin/db4/db-4.8.30.NC/dist/../mutex/mut_tas.c  -fno-common -DPIC -o mut_tas.o
    /Users/sjors/dev/bitcoin/db4/db-4.8.30.NC/dist/../mutex/mut_tas.c:140:34: error: implicit declaration of function 'atomic_compare_exchange' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                    if (MUTEXP_IS_BUSY(mutexp) || !MUTEXP_ACQUIRE(mutexp)) {
                                                   ^
    /Users/sjors/dev/bitcoin/db4/db-4.8.30.NC/dist/../dbinc/mutex_int.h:1056:2: note: expanded from macro 'MUTEXP_ACQUIRE'
            atomic_compare_exchange(env,                            \
            ^
    /Users/sjors/dev/bitcoin/db4/db-4.8.30.NC/dist/../mutex/mut_tas.c:336:8: error: implicit declaration of function 'atomic_compare_exchange' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                        !atomic_compare_exchange(env,
                         ^
    2 errors generated.
    make: *** [mut_tas.o] Error 1
    
  14. fanquake added this to the milestone 0.21.0 on Sep 29, 2020
  15. fanquake added the label macOS on Sep 29, 2020
  16. willcl-ark commented at 7:26 PM on October 8, 2020: contributor

    @Sjors I just upgraded to Big Sur and saw this issue mentioned in the meeting...

    I can get this to compile by using brew-installed llvm like so:

    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 .
    
  17. Sjors commented at 8:58 AM on October 9, 2020: member

    I assume you upgraded to the latest beta version 9? This workaround seems to work on macOS 10.15.7 Catalina as well, with Xcode 12.0.1 and llvm 10.0.1 via Homebrew. At least it doesn't break any wallet tests.

  18. willcl-ark commented at 6:03 PM on October 11, 2020: contributor

    @Sjors yes I am on Version 11 Beta (20A5384c) and latest Xcode Beta.

    Not really a satisfying fix, but at least good to have some sort of workaround in the iterim. I will try a bit more tomorrow to see if I can find what the issue is with system compiler and libs...

  19. willcl-ark commented at 10:17 AM on October 12, 2020: contributor

    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)

  20. willcl-ark commented at 11:26 AM on October 13, 2020: contributor

    Some progress towards identifying a fix:

    • Modify ./contrib/install_db4.sh to break at line 91 then run once with ./contrib/install_db4.sh .

    • Modify db4/db-4.8.30.NC/dist/aclocal/mutex.m4 with the following patch (I believe AC_TRY_RUN... was silently failing without #include <stdlib.h>???):

    --- mutex-orig.m4	2020-10-13 11:17:55.000000000 +0100
    +++ mutex.m4	2020-10-13 11:15:56.000000000 +0100
    @@ -4,6 +4,7 @@
     AC_DEFUN(AM_PTHREADS_SHARED, [
     AC_TRY_RUN([
     #include <pthread.h>
    +#include <stdlib.h>
     main() {
     	pthread_cond_t cond;
     	pthread_mutex_t mutex;
    @@ -24,7 +25,8 @@
     	pthread_mutexattr_destroy(&mutexattr));
     }], [db_cv_mutex="$1"],,
     AC_TRY_LINK([
    -#include <pthread.h>],[
    +#include <pthread.h>
    +#include <stdlib.h>],[
     	pthread_cond_t cond;
     	pthread_mutex_t mutex;
     	pthread_condattr_t condattr;
    @@ -46,6 +48,7 @@
     AC_DEFUN(AM_PTHREADS_PRIVATE, [
     AC_TRY_RUN([
     #include <pthread.h>
    +#include <stdlib.h>
     main() {
     	pthread_cond_t cond;
     	pthread_mutex_t mutex;
    @@ -65,6 +68,7 @@
     }], [db_cv_mutex="$1"],,
     AC_TRY_LINK([
     #include <pthread.h>],[
    +#include <stdlib.h>
     	pthread_cond_t cond;
     	pthread_mutex_t mutex;
     	pthread_condattr_t condattr;
    
    • Next:
    cd db4/db-4.8.30.NC/dist/
    sudo rm -Rf autom4te.cache/ configure
    sudo autoreconf -i
    

    This results in the following warnings: autoreconf_output.txt

    • Comment out lines 28-67 and 70-88 and re-run ./contrib/install_db4.sh .

    This gets us past configure mutex checks successfully:

    checking for mutexes... POSIX/pthreads/library
    checking pthread.h usability... yes
    checking pthread.h presence... yes
    checking for pthread.h... yes
    checking for main in -lpthread... yes
    ...
    checking for fcntl/F_SETFD... yes
    
    • Comment out lines 28-67 and 70-88 and re-run ./contrib/install_db4.sh .

    This however still results in the following error:

    libtool: compile:  cc -c -I. -I/Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/.. -O3 /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_method.c  -fno-common -DPIC -o env_method.o
    ./libtool --mode=compile cc -c -I. -I/Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/..  -O3  /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_name.c
    libtool: compile:  cc -c -I. -I/Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/.. -O3 /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_name.c  -fno-common -DPIC -o env_name.o
    ./libtool --mode=compile cc -c -I. -I/Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/..  -O3  /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_open.c
    libtool: compile:  cc -c -I. -I/Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/.. -O3 /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_open.c  -fno-common -DPIC -o env_open.o
    /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_open.c:33:14: error: use of undeclared identifier
          '__EDIT_DB_VERSION_MAJOR__'
                    *majverp = DB_VERSION_MAJOR;
                               ^
    ./db.h:45:26: note: expanded from macro 'DB_VERSION_MAJOR'
    #define DB_VERSION_MAJOR        __EDIT_DB_VERSION_MAJOR__
                                    ^
    /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_open.c:35:14: error: use of undeclared identifier
          '__EDIT_DB_VERSION_MINOR__'
                    *minverp = DB_VERSION_MINOR;
                               ^
    ./db.h:46:26: note: expanded from macro 'DB_VERSION_MINOR'
    #define DB_VERSION_MINOR        __EDIT_DB_VERSION_MINOR__
                                    ^
    /Users/will/src/bitcoin/db4/db-4.8.30.NC/dist/../env/env_open.c:37:13: error: use of undeclared identifier
          '__EDIT_DB_VERSION_PATCH__'
                    *patchp = DB_VERSION_PATCH;
                              ^
    ./db.h:47:26: note: expanded from macro 'DB_VERSION_PATCH'
    #define DB_VERSION_PATCH        __EDIT_DB_VERSION_PATCH__
                                    ^
    3 errors generated.
    make: *** [env_open.o] Error 1
    

    Running clang -x c -v -E /dev/null shows the default clang config:

    Apple clang version 12.0.0 (clang-1200.0.32.6)
    Target: x86_64-apple-darwin20.1.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
     "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=11.0 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609.5 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -fdebug-compilation-dir /Users/will/src/bitcoin -ferror-limit 19 -fmessage-length 126 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-11.0.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c /dev/null
    clang -cc1 version 12.0.0 (clang-1200.0.32.6) default target x86_64-apple-darwin20.1.0
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/include
     /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
     /Library/Developer/CommandLineTools/usr/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    # 1 "/dev/null"
    # 1 "<built-in>" 1
    # 1 "<built-in>" 3
    # 366 "<built-in>" 3
    # 1 "<command line>" 1
    # 1 "<built-in>" 2
    # 1 "/dev/null" 2
    
  21. willcl-ark commented at 2:49 PM on October 13, 2020: contributor

    I can see that configure.ac is listing abort.o as a LIBOBJS, so configure thinks the system ones should be replaced:

    LIBOBJS=' ${LIBOBJDIR}abort$U.o ${LIBOBJDIR}atoi$U.o ${LIBOBJDIR}atol$U.o ${LIBOBJDIR}getenv$U.o ${LIBOBJDIR}qsort$U.o ${LIBOBJDIR}rand$U.o ${LIBOBJDIR}strtol$U.o ${LIBOBJDIR}strtoul$U.o'

    config.log shows:

    configure:20634: checking for abort
    configure:20634: cc -o conftest -O3  -include stdlib.h  conftest.c  -lpthread >&5
    conftest.c:75:6: error: conflicting types for 'abort'
    char abort ();
         ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:131:7: note: previous declaration is here
    void     abort(void) __cold __dead2;
             ^
    conftest.c:86:8: error: returning 'void' from a function with incompatible result type 'int'
    return abort ();
           ^~~~~~~~
    2 errors generated.
    

    ...which is why I assume it want to replace it.

    (full log section: abort.txt)

  22. willcl-ark commented at 8:50 PM on October 13, 2020: contributor

    Command line tools for Xcode 12.2 Beta 3 (Oct 13th) does not solve the issue.

  23. willcl-ark commented at 8:47 AM on October 14, 2020: contributor

    Brew-installed clang passes the same configure tests for abort, atoi, atol etc.:

    configure:20634: checking for abort
    configure:20634: /usr/local/opt/llvm/bin/clang -o conftest -O3   -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib conftest.c  -lpthread >&5
    conftest.c:75:6: warning: incompatible redeclaration of library function 'abort' [-Wincompatible-library-redeclaration]
    char abort ();
         ^
    conftest.c:75:6: note: 'abort' is a builtin with type 'void (void) __attribute__((noreturn))'
    1 warning generated.
    configure:20634: $? = 0
    configure:20634: result: yes
    configure:20634: checking for atoi
    configure:20634: /usr/local/opt/llvm/bin/clang -o conftest -O3   -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib conftest.c  -lpthread >&5
    configure:20634: $? = 0
    configure:20634: result: yes
    

    vs system-installed clang (with CPPFLAGS="-include stdlib.h"):

    configure:20634: checking for abort
    configure:20634: cc -o conftest -O3  -I/usr/local/opt/llvm/include -include stdlib.h -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib conftest.c  -lpthread >&5
    conftest.c:75:6: error: conflicting types for 'abort'
    char abort ();
         ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:131:7: note: previous declaration is here
    void     abort(void) __cold __dead2;
             ^
    conftest.c:86:8: error: returning 'void' from a function with incompatible result type 'int'
    return abort ();
           ^~~~~~~~
    2 errors generated.
    configure:20634: $? = 1
    configure: failed program was:
    | /* confdefs.h */
    | #define PACKAGE_NAME "Berkeley DB"
    | #define PACKAGE_TARNAME "db-4.8.30"
    | #define PACKAGE_VERSION "4.8.30"
    | #define PACKAGE_STRING "Berkeley DB 4.8.30"
    | #define PACKAGE_BUGREPORT "Oracle Technology Network Berkeley DB forum"
    | #define PACKAGE_URL ""
    | #define HAVE_UPGRADE_SUPPORT 1
    | #define STDC_HEADERS 1
    | #define HAVE_SYS_TYPES_H 1
    | #define HAVE_SYS_STAT_H 1
    | #define HAVE_STDLIB_H 1
    | #define HAVE_STRING_H 1
    | #define HAVE_MEMORY_H 1
    | #define HAVE_STRINGS_H 1
    | #define HAVE_INTTYPES_H 1
    | #define HAVE_STDINT_H 1
    | #define HAVE_UNISTD_H 1
    | #define HAVE_DLFCN_H 1
    | #define LT_OBJDIR ".libs/"
    | #define HAVE_SYSTEM_INCLUDE_FILES 1
    | #define TIME_WITH_SYS_TIME 1
    | #define HAVE_DIRENT_H 1
    | #define HAVE_EXECINFO_H 1
    | #define HAVE_SYS_SELECT_H 1
    | #define HAVE_SYS_SOCKET_H 1
    | #define HAVE_SYS_TIME_H 1
    | #define HAVE_STRUCT_STAT_ST_BLKSIZE 1
    | #define SIZEOF_CHAR 1
    | #define SIZEOF_UNSIGNED_CHAR 1
    | #define SIZEOF_SHORT 2
    | #define SIZEOF_UNSIGNED_SHORT 2
    | #define SIZEOF_INT 4
    | #define SIZEOF_UNSIGNED_INT 4
    | #define SIZEOF_LONG 8
    | #define SIZEOF_UNSIGNED_LONG 8
    | #define SIZEOF_LONG_LONG 8
    | #define SIZEOF_UNSIGNED_LONG_LONG 8
    | #define SIZEOF_CHAR_P 8
    | #define SIZEOF_SIZE_T 8
    | #define HAVE_EXIT_SUCCESS 1
    | #define HAVE_GETOPT_OPTRESET 1
    | #define HAVE_MUTEX_PTHREADS 1
    | #define HAVE_MUTEX_X86_64_GCC_ASSEMBLY 1
    | #define HAVE_MUTEX_SUPPORT 1
    | #define HAVE_SHARED_LATCHES 1
    | #define HAVE_MUTEX_HYBRID 1
    | #define HAVE_SIMPLE_THREAD_TYPE 1
    | #define HAVE_ATOMIC_SUPPORT 1
    | #define HAVE_ATOMIC_X86_GCC_ASSEMBLY 1
    | /* end confdefs.h.  */
    | /* Define abort to an innocuous variant, in case <limits.h> declares abort.
    |    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
    | #define abort innocuous_abort
    | 
    | /* System header to define __stub macros and hopefully few prototypes,
    |     which can conflict with char abort (); below.
    |     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
    |     <limits.h> exists even on freestanding compilers.  */
    | 
    | #ifdef __STDC__
    | # include <limits.h>
    | #else
    | # include <assert.h>
    | #endif
    | 
    | #undef abort
    | 
    | /* Override any GCC internal prototype to avoid an error.
    |    Use char because int might match the return type of a GCC
    |    builtin and then its argument prototype would still apply.  */
    | #ifdef __cplusplus
    | extern "C"
    | #endif
    | char abort ();
    | /* The GNU C library defines this for functions which it implements
    |     to always fail with ENOSYS.  Some functions are actually named
    |     something starting with __ and the normal name is an alias.  */
    | #if defined __stub_abort || defined __stub___abort
    | choke me
    | #endif
    | 
    | int
    | main ()
    | {
    | return abort ();
    |   ;
    |   return 0;
    | }
    configure:20634: result: no
    configure:20634: checking for atoi
    configure:20634: cc -o conftest -O3  -I/usr/local/opt/llvm/include -include stdlib.h -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib conftest.c  -lpthread >&5
    conftest.c:75:6: error: conflicting types for 'atoi'
    char atoi ();
         ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:135:6: note: previous declaration is here
    int      atoi(const char *);
             ^
    conftest.c:86:14: error: too few arguments to function call, expected 1, have 0
    return atoi ();
           ~~~~  ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdlib.h:135:1: note: 'atoi' declared here
    int      atoi(const char *);
    ^
    2 errors generated.
    configure:20634: $? = 1
    configure: failed program was:
    | /* confdefs.h */
    | #define PACKAGE_NAME "Berkeley DB"
    | #define PACKAGE_TARNAME "db-4.8.30"
    | #define PACKAGE_VERSION "4.8.30"
    | #define PACKAGE_STRING "Berkeley DB 4.8.30"
    | #define PACKAGE_BUGREPORT "Oracle Technology Network Berkeley DB forum"
    | #define PACKAGE_URL ""
    | #define HAVE_UPGRADE_SUPPORT 1
    | #define STDC_HEADERS 1
    | #define HAVE_SYS_TYPES_H 1
    | #define HAVE_SYS_STAT_H 1
    | #define HAVE_STDLIB_H 1
    | #define HAVE_STRING_H 1
    | #define HAVE_MEMORY_H 1
    | #define HAVE_STRINGS_H 1
    | #define HAVE_INTTYPES_H 1
    | #define HAVE_STDINT_H 1
    | #define HAVE_UNISTD_H 1
    | #define HAVE_DLFCN_H 1
    | #define LT_OBJDIR ".libs/"
    | #define HAVE_SYSTEM_INCLUDE_FILES 1
    | #define TIME_WITH_SYS_TIME 1
    | #define HAVE_DIRENT_H 1
    | #define HAVE_EXECINFO_H 1
    | #define HAVE_SYS_SELECT_H 1
    | #define HAVE_SYS_SOCKET_H 1
    | #define HAVE_SYS_TIME_H 1
    | #define HAVE_STRUCT_STAT_ST_BLKSIZE 1
    | #define SIZEOF_CHAR 1
    | #define SIZEOF_UNSIGNED_CHAR 1
    | #define SIZEOF_SHORT 2
    | #define SIZEOF_UNSIGNED_SHORT 2
    | #define SIZEOF_INT 4
    | #define SIZEOF_UNSIGNED_INT 4
    | #define SIZEOF_LONG 8
    | #define SIZEOF_UNSIGNED_LONG 8
    | #define SIZEOF_LONG_LONG 8
    | #define SIZEOF_UNSIGNED_LONG_LONG 8
    | #define SIZEOF_CHAR_P 8
    | #define SIZEOF_SIZE_T 8
    | #define HAVE_EXIT_SUCCESS 1
    | #define HAVE_GETOPT_OPTRESET 1
    | #define HAVE_MUTEX_PTHREADS 1
    | #define HAVE_MUTEX_X86_64_GCC_ASSEMBLY 1
    | #define HAVE_MUTEX_SUPPORT 1
    | #define HAVE_SHARED_LATCHES 1
    | #define HAVE_MUTEX_HYBRID 1
    | #define HAVE_SIMPLE_THREAD_TYPE 1
    | #define HAVE_ATOMIC_SUPPORT 1
    | #define HAVE_ATOMIC_X86_GCC_ASSEMBLY 1
    | /* end confdefs.h.  */
    | /* Define atoi to an innocuous variant, in case <limits.h> declares atoi.
    |    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
    | #define atoi innocuous_atoi
    | 
    | /* System header to define __stub macros and hopefully few prototypes,
    |     which can conflict with char atoi (); below.
    |     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
    |     <limits.h> exists even on freestanding compilers.  */
    | 
    | #ifdef __STDC__
    | # include <limits.h>
    | #else
    | # include <assert.h>
    | #endif
    | 
    | #undef atoi
    | 
    | /* Override any GCC internal prototype to avoid an error.
    |    Use char because int might match the return type of a GCC
    |    builtin and then its argument prototype would still apply.  */
    | #ifdef __cplusplus
    | extern "C"
    | #endif
    | char atoi ();
    | /* The GNU C library defines this for functions which it implements
    |     to always fail with ENOSYS.  Some functions are actually named
    |     something starting with __ and the normal name is an alias.  */
    | #if defined __stub_atoi || defined __stub___atoi
    | choke me
    | #endif
    | 
    | int
    | main ()
    | {
    | return atoi ();
    |   ;
    |   return 0;
    | }
    configure:20634: result: no
    

    I think the mandatory include of <stdlib.h> in every function test is causing configure to fail on these functions where they should be replaced, perhaps patching mutex.m4 and fixing the DB_VERSION error might end up being "cleaner"?

  24. willcl-ark commented at 1:01 PM on October 14, 2020: contributor

    In absence of being able to fix the issue directly, I propose a workaround here:

    https://github.com/willcl-ark/bitcoin/tree/build_bdb_big_sur @fanquake is such a workaround likely to be an acceptable "solution" to this?

  25. fanquake commented at 2:09 AM on October 15, 2020: member

    @willcl-ark I need to catch up here, but that would only be a partial fix, as depends builds would still be would still be broken. I'd like to make sure we understand what the issue is, and patch it pre-build, rather than filling up our db4 install script with a bunch of macOS specific hacks, and still have it broken in depends.

  26. willcl-ark commented at 8:57 AM on October 15, 2020: contributor

    @fanquake I agree it's not a real solution.

    I've just tested BDB18.1 and that compiles on stock Big Sur with Xcode 12, so perhaps I can finally hunt down the fix.

  27. willcl-ark commented at 1:23 PM on October 19, 2020: contributor

    I don't see a way we can fix this on Big Sur which doesn't involve either:

    a) using brew-installed LLVM or b) massively patching quite a number of the .m4 files, removing autom4te.cache and configure and then autoreconf -i-ing, all of which require permissions changes to the extracted files.

    Neither is ideal.

    There was another note in mutex.m4 from bdb v18 which might be of note to anyone else looking to pick this up, although it does seem like, if this was the (primary) issue, we would have picked it up earlier...:

    		# Mac OS 10.7 Lion has broken pthread_*_setpshared() calls.
    		# Most BSD-like operating systems have pointers in their mutex
    		# and condition variables, and cannot be shared between
    		# proceses.  Earlier Mac OS releases correctly returned EINVAL
    		# from *_setpshared(PTHREAD_PROCESS_SHARED), but 10.7 returns
    		# success. Since we can't trust those calls anymore we now
    		# avoid these probes for multiprocess pthreads.
    
  28. fanquake commented at 8:54 AM on October 20, 2020: member

    @willcl-ark thanks for the investigation. However I've taken a look and determined that the problem is actually that Apple has enabled -Werror=implicit-function-declaration by default in the Clang shipped with Xcode 12.0:

    Clang now reports an error when you use a function without an explicit declaration when building C or Objective-C code for macOS (-Werror=implicit-function-declaration flag is on). This additional error detection unifies Clang’s behavior for iOS/tvOS and macOS 64-bit targets for this diagnostic. (49917738)

    This causes warnings which were already present in the mutex related checks, i.e:

    configure:18704: checking for mutexes
    configure:18815: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -mmacosx-version-min=10.12 --sysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o conftest -pipe -O2  -I/Users/michael/github/fanquake-bitcoin/depends/x86_64-apple-darwin19.6.0/include -L/Users/michael/github/fanquake-bitcoin/depends/x86_64-apple-darwin19.6.0/lib conftest.c  -lpthread >&5
    conftest.c:46:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
    main() {
    ^
    conftest.c:51:2: error: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Werror,-Wimplicit-function-declaration]
            exit (
            ^
    conftest.c:51:2: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
    1 warning and 1 error generated.
    

    to be converted into errors, and the hence the mutex check fails.

    I'll open a PR with a fix shortly.

  29. awesome-doge commented at 9:38 AM on October 20, 2020: none

    I encountered the same problem in "macos big sur beta 11.0" & "Command_Line_Tools_for_Xcode_12.2_beta_3".

    Using your(@willcl-ark ) solution "https://github.com/willcl-ark/bitcoin/tree/build_bdb_big_sur" will cause an error.

    Detected macOS Big Sur v11.0...
    Error: No such keg: /usr/local/Cellar/llvm
    Found brew-installed LLVM, using for compilation:
    Using CC:
    ...
    ...
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether the C compiler works... no
    configure: error: in `/Users/doge/git/bitcoin/db4/db-4.8.30.NC/build_unix':
    configure: error: C compiler cannot create executables
    See `config.log' for more details.
    

    After I reinstalled "brew install llvm" It works

  30. fanquake referenced this in commit 0729d1a025 on Oct 20, 2020
  31. willcl-ark referenced this in commit ccb338a3a0 on Oct 23, 2020
  32. fanquake referenced this in commit d0a829e963 on Oct 27, 2020
  33. laanwj closed this on Oct 29, 2020

  34. laanwj referenced this in commit 5b82f253b6 on Oct 29, 2020
  35. sidhujag referenced this in commit faf425a4f6 on Oct 29, 2020
  36. fanquake referenced this in commit 314e79581f on Oct 30, 2020
  37. MarkLTZ referenced this in commit 11254d49e6 on Nov 21, 2020
  38. xdustinface referenced this in commit 53ad08710c on Feb 17, 2021
  39. shuaaa commented at 5:11 PM on June 8, 2021: none

    it's 1year later and I am having this problem, I have Catalan 10.15.4. Did anyone find a working solution to the error: Unable to find a mutex implementation

  40. hebasto commented at 5:32 PM on June 8, 2021: member

    @shuaaa

    it's 1year later and I am having this problem, I have Catalan 10.15.4. Did anyone find a working solution to the error: Unable to find a mutex implementation

    Could you open a new issue, and describe all steps to reproduce your problem?

  41. fanquake commented at 1:17 AM on June 9, 2021: member

    Did anyone find a working solution to the error: Unable to find a mutex implementation

    Yes. This was fixed in #20195, which is in master, the 0.21 and 0.20 branches.

  42. furszy referenced this in commit 07f08d4b3f on Jun 30, 2021
  43. Sjors commented at 2:17 PM on August 10, 2022: member

    It's back! (or I forgot some critical step)

    On master @ a6fc293c0a1f27ba1e573bfa16fd76d5f58988b2, macOS 12.5 (Intel), Xcode 13.4.1.

    git clean -dfx
    contrib/install_db4.sh `pwd`
    
    …
    checking for ANSI C exit success/failure values... yes
    checking for getopt optreset variable... yes
    checking for mutexes... UNIX/fcntl
    configure: WARNING: NO SHARED LATCH IMPLEMENTATION FOUND FOR THIS PLATFORM.
    configure: error: Unable to find a mutex implementation
    

    (I'll open a new issue if nobody reminds me of the stupid thing I forgot)

  44. fanquake commented at 2:18 PM on August 10, 2022: member

    It's not!

    The contrib script doesn't apply the same patch as depends.

  45. Sjors commented at 2:23 PM on August 10, 2022: member

    Ah yes, as I noticed in my own review: #20195 (comment)

  46. lyricidal referenced this in commit 942cc48eb6 on Mar 27, 2023
  47. lyricidal referenced this in commit c13f14d8e3 on Mar 27, 2023
  48. bitcoin locked this on Aug 10, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-28 06:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me