libresolv unavailable on FreeBSD when connecting with mongodb+srv
MGlaus opened this issue · 10 comments
Bug Report
On FreeBSD, when i try to connect to a database with an Atlas connection string (mongodb+srv), i get an error that libresolv is unavailable.
There was a similar issue for AIX systems (#1171). I tried to exclude the build flag -lresolv
for a build, but this didn't work.
Environment
- PHP: 7.4 (8.0 / 8.1 too but only tested with extension version 1.12)
- MongoDB extension version => 1.12.1 (newer versions wont build on FreeBSD, there is some issue with libmongocrypt)
-
- libbson bundled version => 1.20.1
-
- libmongoc bundled version => 1.20.1
- MongoDB Library: 1.11.0
- FreeBSD: 12.3
Test Script
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new MongoDB\Client(
'mongodb+srv://some-atlas-connection-string'
);
$db = $client->listDatabases();
Expected and Actual Behavior
Expected
No error
Actual
PHP Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: libresolv unavailable, cannot use mongodb+srv URI in /path/to/dir/vendor/mongodb/mongodb/src/functions.php:487
Stack trace:
#0 /path/to/dir/vendor/mongodb/mongodb/src/functions.php(487): MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference))
#1 /path/to/dir/vendor/mongodb/mongodb/src/Client.php(308): MongoDB\select_server(Object(MongoDB\Driver\Manager), Array)
#2 /path/to/dir/mongo.php(6): MongoDB\Client->listDatabases()
#3 {main}
thrown in /path/to/dir/vendor/mongodb/mongodb/src/functions.php on line 487
I've managed to get version 1.14.0 of the extension working. The issue is still there, but with a different exception.
PHP Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse URI options: libresolv unavailable, cannot use mongodb+srv URI in /path/to/dir/vendor/mongodb/mongodb/src/Client.php:130
Stack trace:
#0 /path/to/dir/vendor/mongodb/mongodb/src/Client.php(130): MongoDB\Driver\Manager->__construct('mongodb+srv://r...', Array, Array)
#1 /path/to/dir/mongo.php(4): MongoDB\Client->__construct('mongodb+srv://r...')
#2 {main}
thrown in /path/to/dir/vendor/mongodb/mongodb/src/Client.php on line 130
(newer versions wont build on FreeBSD, there is some issue with libmongocrypt)
Assuming this is unrelated, any issue pertaining to libmongocrypt can be reported via the MONGOCRYPT project in MongoDB's JIRA.
The issue is still there, but with a different exception.
That exception message is equivalent to the original error. The format was changed in CDRIVER-4437.
Since you have extension version 1.14 compiling and producing the same exception, let's stick with that for diagnosing this issue. I have two requests:
- Following the steps in Building the MongoDB PHP Driver from source, please share the entire output from the
configure
script. Specifically, I'd like to see what CheckResolv.m4 is doing, as well as the final build configuration emitted at the end of the script. - Following Installing the MongoDB C Driver (libmongoc) and BSON library (libbson), install libmongoc and libbson as system libraries and then build the PHP driver while specifying
--with-mongodb-system-libs=yes
toconfigure
(also discussed in the build instructions linked above). Assuming the driver compiles, run your script again and let us know if the same error message is produced. This should help me infer whether the issue is specific to ourCheckResolv.m4
script or something to do with libmongoc directly.
Assuming this is unrelated, any issue pertaining to libmongocrypt can be reported via the MONGOCRYPT project in MongoDB's JIRA.
I've reported it by now. I didn't have time yesterday to do it. Link in case it's relevant for this issue: https://jira.mongodb.org/browse/MONGOCRYPT-470
Output of ./configure
for a normal build.
./configure --prefix=/usr/local/php74/
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/local/bin/gsed
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... amd64-unknown-freebsd12.3
checking host system type... amd64-unknown-freebsd12.3
checking target system type... amd64-unknown-freebsd12.3
checking for PHP prefix... /usr/local/php74
checking for PHP includes... -I/usr/local/php74/include/php -I/usr/local/php74/include/php/main -I/usr/local/php74/include/php/TSRM -I/usr/local/php74/include/php/Zend -I/usr/local/php74/include/php/ext -I/usr/local/php74/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php74/lib/php/20190902
checking for PHP installed headers prefix... /usr/local/php74/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... gawk
checking whether to enable MongoDB support... yes, shared
checking PHP version... 7.4.30
checking whether to enable developer build flags... no
checking whether to enable code coverage... no
checking whether to compile against system libraries instead of bundled... no
checking whether to use system libbson... no
checking whether to use system libmongoc... no
checking whether to enable client-side encryption... auto
checking for gcc... (cached) cc
checking whether the compiler supports GNU C... (cached) yes
checking whether cc accepts -g... (cached) yes
checking for cc option to enable C11 features... (cached) none needed
checking for g++... no
checking for c++... c++
checking whether the compiler supports GNU C++... yes
checking whether c++ accepts -g... yes
checking for c++ option to enable C++11 features... none needed
checking accept ARG2 => struct sockaddr ARG3 => socklen_t ... ok
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for typeof syntax and keyword spelling... typeof
checking for __sync_add_and_fetch_4... yes
checking for __sync_add_and_fetch_8... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for _Bool... yes
checking for stdbool.h that conforms to C99... yes
checking for strings.h... (cached) yes
checking whether byte ordering is bigendian... no
checking for strnlen... yes
checking for reallocf... yes
checking for syscall... yes
checking for SYS_gettid... no
checking for snprintf... yes
checking for strlcpy... yes
checking for struct timespec... yes
checking for library containing clock_gettime... none required
checking for library containing floor... -lm
checking for gmtime_r... yes
checking for rand_r... yes
checking for arc4random_buf... yes
checking if compiler needs -Werror to reject unknown flags... yes
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... -D_THREAD_SAFE
checking for PTHREAD_PRIO_INHERIT... yes
checking whether PTHREAD_ONCE_INIT needs braces... no
checking for PHP_MONGODB_SNAPPY... yes
checking for PHP_MONGODB_ZLIB... yes
checking for PHP_MONGODB_ZSTD... yes
checking for res_nsearch... no
checking for res_search... no
checking whether to enable SASL for Kerberos authentication... auto
checking for PHP_MONGODB_SASL... yes
checking for sasl_client_done in -lsasl2... yes
checking which SASL library to use... cyrus
checking whether to enable crypto and TLS... auto
checking deprecated option for OpenSSL library path... auto
checking for cc options needed to detect all undeclared functions... -fno-builtin
configure: checking whether OpenSSL is available
checking for PHP_MONGODB_SSL... yes
checking whether ASN1_STRING_get0_data is declared... yes
checking which TLS library to use... openssl
checking whether to use system crypto profile... no
checking deprecated option for whether to use system crypto profile... no
checking whether to enable ICU for SASLPrep with SCRAM-SHA-256 authentication... auto
checking for PHP_MONGODB_ICU... yes
checking for shm_open... yes
checking for sched_getcpu... no
checking for socklen_t... yes
checking for struct sockaddr_storage.ss_family... yes
checking for pthread_join in LIBS= with CFLAGS=-D_THREAD_SAFE -pthread... yes
checking if compiler needs -Werror to reject unknown flags... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... -D_THREAD_SAFE
checking for PTHREAD_PRIO_INHERIT... (cached) yes
checking if weak symbols are supported... yes
checking which crypto library to use for libmongocrypt... openssl
checking whether byte ordering is bigendian... (cached) no
checking for a sed that does not truncate output... /usr/local/bin/gsed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/local/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 393216
checking command to parse /usr/local/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... freebsd12.3 ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by c++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the c++ linker (/usr/bin/ld) supports shared libraries... yes
checking for c++ option to produce PIC... -fPIC
checking if c++ PIC flag -fPIC works... yes
checking if c++ static flag -static works... yes
checking if c++ supports -c -o file.o... yes
checking whether the c++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... freebsd12.3 ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
configure: patching config.h.in
configure: creating ./config.status
mongodb was configured with the following options:
Build configuration:
CFLAGS : -g -O2
Extra CFLAGS :
Developers flags (slow) :
Code Coverage flags (extra slow) :
libmongoc : Bundled (1.22.0)
libbson : Bundled (1.22.0)
libmongocrypt : Bundled (1.5.0)
LDFLAGS :
EXTRA_LDFLAGS :
MONGODB_SHARED_LIBADD : -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -pthread -lsnappy -lz -lzstd -lsasl2 -lssl -lcrypto -licuuc -licudata -pthread
Please submit bugreports at:
https://jira.mongodb.org/browse/PHPC
config.status: creating /root/mglaus/mongodb/mongo-php-driver/src/libmongoc/src/common/common-config.h
config.status: creating /root/mglaus/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson-config.h
config.status: creating /root/mglaus/mongodb/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson-version.h
config.status: creating /root/mglaus/mongodb/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h
config.status: creating /root/mglaus/mongodb/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h
config.status: creating /root/mglaus/mongodb/mongo-php-driver/src/libmongocrypt/src/mongocrypt-config.h
config.status: creating config.h
The build with system-libs causes the same error. Just in case, here is the output for ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/local/bin/gsed
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... amd64-unknown-freebsd12.3
checking host system type... amd64-unknown-freebsd12.3
checking target system type... amd64-unknown-freebsd12.3
checking for PHP prefix... /usr/local/php74
checking for PHP includes... -I/usr/local/php74/include/php -I/usr/local/php74/include/php/main -I/usr/local/php74/include/php/TSRM -I/usr/local/php74/include/php/Zend -I/usr/local/php74/include/php/ext -I/usr/local/php74/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php74/lib/php/20190902
checking for PHP installed headers prefix... /usr/local/php74/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... gawk
checking whether to enable MongoDB support... yes, shared
checking PHP version... 7.4.30
checking whether to enable developer build flags... no
checking whether to enable code coverage... no
checking whether to compile against system libraries instead of bundled... yes
checking whether to use system libbson... no
checking whether to use system libmongoc... no
checking whether to enable client-side encryption... auto
checking for pkg-config... /usr/local/bin/pkg-config
checking for libbson... version 1.22.1 found
checking for libmongoc... version 1.22.1 found
checking for libmongocrypt... version 1.6.0-dev+20220809git9a6ff24730 found
checking for a sed that does not truncate output... /usr/local/bin/gsed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/local/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 393216
checking command to parse /usr/local/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... freebsd12.3 ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
mongodb was configured with the following options:
Build configuration:
CFLAGS : -g -O2
Extra CFLAGS :
Developers flags (slow) :
Code Coverage flags (extra slow) :
libmongoc : System (1.22.1)
libbson : System (1.22.1)
libmongocrypt : System (1.6.0-dev+20220809git9a6ff24730)
LDFLAGS :
EXTRA_LDFLAGS :
MONGODB_SHARED_LIBADD : -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lbson-1.0 -lmongoc-1.0 -lbson-1.0 -lmongocrypt
Please submit bugreports at:
https://jira.mongodb.org/browse/PHPC
config.status: creating config.h
Looking at the configure
output from the first build (with bundled dependencies) it looks like CheckResolv.m4 finds neither res_nsearch
nor res_search
:
checking for res_nsearch... no
checking for res_search... no
I assume if you look in the generated src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h
file both MONGOC_HAVE_RES_NSEARCH
and MONGOC_HAVE_RES_SEARCH
will be defined as 0
.
The build with system-libs causes the same error.
If these libraries aren't found when building libmongoc as system library using CMake, I assume any problem isn't specific to our Autotools scripts. Do either of these libraries actually exist on your system?
The FreeBSD man page for res_search(3)
shows it as included in "Standard C Library (libc, -lc)". That doesn't appear in the "Build configuration" of either configure
output, but I would assume your compiler would link it by default. Is it possible FreeBSD requires it to be explicitly linked?
I took a look at the configure script, and i saw that the checks for res_nsearch
and res_search
try to link -lresolv
. AFAIK no such library is available on FreeBSD, and therefore the script fails to link it and thinks the functions are not present.
I tried to remove all references of -lresolv
and this caused the configure script to recognise res_nsearch
and res_ndestroy
, but no mention of res_search
. But with this fix, the build fails.
Remove -lresolv
:
--- a/scripts/autotools/libmongoc/CheckResolv.m4
+++ b/scripts/autotools/libmongoc/CheckResolv.m4
@@ -6,7 +6,7 @@ need_libresolv="no"
old_LIBS="$LIBS"
dnl On AIX, resolv functions are in libc.
if test "x$os_aix" = "xno"; then
- LIBS="$LIBS -lresolv"
+ LIBS="$LIBS"
fi
dnl Thread-safe DNS query function for _mongoc_client_get_srv.
Output ./configure
:
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/local/bin/gsed
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether cc accepts -g... yes
checking for cc option to enable C11 features... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... amd64-unknown-freebsd12.3
checking host system type... amd64-unknown-freebsd12.3
checking target system type... amd64-unknown-freebsd12.3
checking for PHP prefix... /usr/local/php74
checking for PHP includes... -I/usr/local/php74/include/php -I/usr/local/php74/include/php/main -I/usr/local/php74/include/php/TSRM -I/usr/local/php74/include/php/Zend -I/usr/local/php74/include/php/ext -I/usr/local/php74/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php74/lib/php/20190902
checking for PHP installed headers prefix... /usr/local/php74/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... gawk
checking whether to enable MongoDB support... yes, shared
checking PHP version... 7.4.30
checking whether to enable developer build flags... no
checking whether to enable code coverage... no
checking whether to compile against system libraries instead of bundled... no
checking whether to use system libbson... no
checking whether to use system libmongoc... no
checking whether to enable client-side encryption... auto
checking for gcc... (cached) cc
checking whether the compiler supports GNU C... (cached) yes
checking whether cc accepts -g... (cached) yes
checking for cc option to enable C11 features... (cached) none needed
checking for g++... no
checking for c++... c++
checking whether the compiler supports GNU C++... yes
checking whether c++ accepts -g... yes
checking for c++ option to enable C++11 features... none needed
checking accept ARG2 => struct sockaddr ARG3 => socklen_t ... ok
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for typeof syntax and keyword spelling... typeof
checking for __sync_add_and_fetch_4... yes
checking for __sync_add_and_fetch_8... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for _Bool... yes
checking for stdbool.h that conforms to C99... yes
checking for strings.h... (cached) yes
checking whether byte ordering is bigendian... no
checking for strnlen... yes
checking for reallocf... yes
checking for syscall... yes
checking for SYS_gettid... no
checking for snprintf... yes
checking for strlcpy... yes
checking for struct timespec... yes
checking for library containing clock_gettime... none required
checking for library containing floor... -lm
checking for gmtime_r... yes
checking for rand_r... yes
checking for arc4random_buf... yes
checking if compiler needs -Werror to reject unknown flags... yes
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... -D_THREAD_SAFE
checking for PTHREAD_PRIO_INHERIT... yes
checking whether PTHREAD_ONCE_INIT needs braces... no
checking for PHP_MONGODB_SNAPPY... yes
checking for PHP_MONGODB_ZLIB... yes
checking for PHP_MONGODB_ZSTD... yes
checking for res_nsearch... yes
checking for res_ndestroy... yes
checking whether to enable SASL for Kerberos authentication... auto
checking for PHP_MONGODB_SASL... yes
checking for sasl_client_done in -lsasl2... yes
checking which SASL library to use... cyrus
checking whether to enable crypto and TLS... auto
checking deprecated option for OpenSSL library path... auto
checking for cc options needed to detect all undeclared functions... -fno-builtin
configure: checking whether OpenSSL is available
checking for PHP_MONGODB_SSL... yes
checking whether ASN1_STRING_get0_data is declared... yes
checking which TLS library to use... openssl
checking whether to use system crypto profile... no
checking deprecated option for whether to use system crypto profile... no
checking whether to enable ICU for SASLPrep with SCRAM-SHA-256 authentication... auto
checking for PHP_MONGODB_ICU... yes
checking for shm_open... yes
checking for sched_getcpu... no
checking for socklen_t... yes
checking for struct sockaddr_storage.ss_family... yes
checking for pthread_join in LIBS= with CFLAGS=-D_THREAD_SAFE -pthread... yes
checking if compiler needs -Werror to reject unknown flags... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... -D_THREAD_SAFE
checking for PTHREAD_PRIO_INHERIT... (cached) yes
checking if weak symbols are supported... yes
checking which crypto library to use for libmongocrypt... openssl
checking whether byte ordering is bigendian... (cached) no
checking for a sed that does not truncate output... /usr/local/bin/gsed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/local/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 393216
checking command to parse /usr/local/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... freebsd12.3 ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by c++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the c++ linker (/usr/bin/ld) supports shared libraries... yes
checking for c++ option to produce PIC... -fPIC
checking if c++ PIC flag -fPIC works... yes
checking if c++ static flag -static works... yes
checking if c++ supports -c -o file.o... yes
checking whether the c++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... freebsd12.3 ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
configure: patching config.h.in
configure: creating ./config.status
mongodb was configured with the following options:
Build configuration:
CFLAGS : -g -O2
Extra CFLAGS :
Developers flags (slow) :
Code Coverage flags (extra slow) :
libmongoc : Bundled (1.22.0)
libbson : Bundled (1.22.0)
libmongocrypt : Bundled (1.5.0)
LDFLAGS :
EXTRA_LDFLAGS :
MONGODB_SHARED_LIBADD : -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/local/lib -L/usr/local/lib -pthread -lsnappy -lz -lzstd -lsasl2 -lssl -lcrypto -licuuc -licudata -pthread
Please submit bugreports at:
https://jira.mongodb.org/browse/PHPC
config.status: creating /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/common/common-config.h
config.status: creating /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson-config.h
config.status: creating /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libbson/src/bson/bson-version.h
config.status: creating /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h
config.status: creating /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h
config.status: creating /root/mglaus/mongo_2/mongo-php-driver/src/libmongocrypt/src/mongocrypt-config.h
config.status: creating config.h
Error message of build:
/bin/sh /root/mglaus/mongo_2/mongo-php-driver/libtool --mode=compile cc -DBSON_COMPILATION -DMONGOC_COMPILATION -D_DEFAULT_SOURCE -D_THREAD_SAFE -pthread -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -DKMS_MESSAGE_ENABLE_CRYPTO=1 -DKMS_MESSAGE_ENABLE_CRYPTO_LIBCRYPTO=1 -I/usr/local/include -D_THREAD_SAFE -D_THREAD_SAFE -pthread -DKMS_MESSAGE_LITTLE_ENDIAN=1 -DMONGOCRYPT_LITTLE_ENDIAN=1 -Isrc/libmongoc/src/libmongoc/src/mongoc/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/ -DPHP_ATOM_INC -I/root/mglaus/mongo_2/mongo-php-driver/include -I/root/mglaus/mongo_2/mongo-php-driver/main -I/root/mglaus/mongo_2/mongo-php-driver -I/usr/local/php74/include/php -I/usr/local/php74/include/php/main -I/usr/local/php74/include/php/TSRM -I/usr/local/php74/include/php/Zend -I/usr/local/php74/include/php/ext -I/usr/local/php74/include/php/ext/date/lib -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/common/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libbson/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libbson/src/jsonsl/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongocrypt/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongocrypt/kms-message/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongocrypt-compat/ -I/root/mglaus/mongo_2/mongo-php-driver/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/BSON/ -I/root/mglaus/mongo_2/mongo-php-driver/src/MongoDB/ -I/root/mglaus/mongo_2/mongo-php-driver/src/MongoDB/Exception/ -I/root/mglaus/mongo_2/mongo-php-driver/src/MongoDB/Monitoring/ -I/root/mglaus/mongo_2/mongo-php-driver/src/contrib/ -DHAVE_CONFIG_H -g -O2 -c /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c -o src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.lo
cc -DBSON_COMPILATION -DMONGOC_COMPILATION -D_DEFAULT_SOURCE -D_THREAD_SAFE -pthread -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -DKMS_MESSAGE_ENABLE_CRYPTO=1 -DKMS_MESSAGE_ENABLE_CRYPTO_LIBCRYPTO=1 -I/usr/local/include -D_THREAD_SAFE -D_THREAD_SAFE -pthread -DKMS_MESSAGE_LITTLE_ENDIAN=1 -DMONGOCRYPT_LITTLE_ENDIAN=1 -Isrc/libmongoc/src/libmongoc/src/mongoc/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/ -DPHP_ATOM_INC -I/root/mglaus/mongo_2/mongo-php-driver/include -I/root/mglaus/mongo_2/mongo-php-driver/main -I/root/mglaus/mongo_2/mongo-php-driver -I/usr/local/php74/include/php -I/usr/local/php74/include/php/main -I/usr/local/php74/include/php/TSRM -I/usr/local/php74/include/php/Zend -I/usr/local/php74/include/php/ext -I/usr/local/php74/include/php/ext/date/lib -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/common/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libbson/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libbson/src/jsonsl/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongocrypt/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongocrypt/kms-message/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/libmongocrypt-compat/ -I/root/mglaus/mongo_2/mongo-php-driver/src/ -I/root/mglaus/mongo_2/mongo-php-driver/src/BSON/ -I/root/mglaus/mongo_2/mongo-php-driver/src/MongoDB/ -I/root/mglaus/mongo_2/mongo-php-driver/src/MongoDB/Exception/ -I/root/mglaus/mongo_2/mongo-php-driver/src/MongoDB/Monitoring/ -I/root/mglaus/mongo_2/mongo-php-driver/src/contrib/ -DHAVE_CONFIG_H -g -O2 -c /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c -fPIC -DPIC -o src/libmongoc/src/libmongoc/src/mongoc/.libs/mongoc-client.o
In file included from /root/mglaus/mongo_2/mongo-php-driver/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:30:
/usr/include/resolv.h:159:14: error: array has incomplete element type 'struct sockaddr_in'
nsaddr_list[MAXNS]; /*%< address of name server */
^
/usr/include/resolv.h:158:9: note: forward declaration of 'struct sockaddr_in'
struct sockaddr_in
^
/usr/include/resolv.h:173:18: error: field has incomplete type 'struct in_addr'
struct in_addr addr;
^
/usr/include/resolv.h:173:10: note: forward declaration of 'struct in_addr'
struct in_addr addr;
^
/usr/include/resolv.h:198:21: error: field has incomplete type 'struct sockaddr_in'
struct sockaddr_in sin;
^
/usr/include/resolv.h:158:9: note: forward declaration of 'struct sockaddr_in'
struct sockaddr_in
^
3 errors generated.
gmake: *** [Makefile:326: src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.lo] Error 1
Apologies for the delayed response on this. I reached out to the libmongoc team and they confirmed that the driver has never explicitly supported FreeBSD and noted that it has never been tested in CI. I opened CDRIVER-4465 as the primary tracking ticket for this issue (along with PHPC-2133), but there is no indication when/if it can be addressed.
Since libmongoc itself has the issue, I expect code changes will be required and possibly some build changes for CMake. I don't think we should focus on CheckResolv.m4; it would make more sense to address that after we know what libmongoc build changes are required (if any).
If you're willing to continue troubleshooting this and try to develop a PR that'd be appreciated (that's how the AIX issue was addressed). If so, I would suggest focusing on the libmongoc repository and continuing to test libmongoc as a system library in the PHP driver.
The error: array has incomplete element type 'struct sockaddr_in
build error you observed seems related to this thread in Mozilla's bug tracker. The fix there is likely to include additional headers instead of just relying on resolv.h
.
Given my previous comment about res_search
appearing in the standard C library on FreeBSD (#1343 (comment)), it's possible the necessary build changes would just be to assume resolution functions are always available on FreeBSD (e.g. skip detection logic in both CMake and PHP's Autotools scripts) and then ensure we include the necessary headers from within libmongoc. That might be a useful starting point if you're willing to work on a PR.
I've managed to get a build working. Following changes have i made.
diff --git a/scripts/autotools/libmongoc/CheckResolv.m4 b/scripts/autotools/libmongoc/CheckResolv.m4
index c44da842..6dea186d 100644
--- a/scripts/autotools/libmongoc/CheckResolv.m4
+++ b/scripts/autotools/libmongoc/CheckResolv.m4
@@ -6,7 +6,7 @@ need_libresolv="no"
old_LIBS="$LIBS"
dnl On AIX, resolv functions are in libc.
if test "x$os_aix" = "xno"; then
- LIBS="$LIBS -lresolv"
+ LIBS="$LIBS"
fi
dnl Thread-safe DNS query function for _mongoc_client_get_srv.
Submodule src/libmongoc contains modified content
diff --git a/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c b/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c
index 457c841a8..0d27d2563 100644
--- a/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c
+++ b/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c
@@ -26,6 +26,7 @@
#if defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH)
#include <netdb.h>
#include <netinet/tcp.h>
+#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
#define BSON_INSIDE
Submodule src/libmongocrypt contains modified content
diff --git a/src/libmongocrypt/src/mongocrypt-util.c b/src/libmongocrypt/src/mongocrypt-util.c
index bd77a02..787f4b8 100644
--- a/src/libmongocrypt/src/mongocrypt-util.c
+++ b/src/libmongocrypt/src/mongocrypt-util.c
@@ -78,7 +78,7 @@ current_module_path ()
}
free (path);
}
-#elif defined(_GNU_SOURCE) || defined(_DARWIN_C_SOURCE)
+#elif 1 || defined(_GNU_SOURCE) || defined(_DARWIN_C_SOURCE)
// Darwin/BSD/glibc define extensions for finding dynamic library info from
// the address of a symbol.
Dl_info info;
diff --git a/src/libmongocrypt/src/os_posix/os_dll.c b/src/libmongocrypt/src/os_posix/os_dll.c
index 52b4db6..6fc1812 100644
--- a/src/libmongocrypt/src/os_posix/os_dll.c
+++ b/src/libmongocrypt/src/os_posix/os_dll.c
@@ -105,7 +105,7 @@ mcr_dll_path (mcr_dll dll)
.error_string = mstr_copy_cstr ("Handle not found in loaded modules")};
}
-#elif defined(__linux__)
+#elif 1 || defined(__linux__)
#include <link.h>
It seems that there are 3 issues, in 3 different projects:
- This project tries to link
resolv
, which does not exist on FreeBSD - libmongocrypt does not detect FreeBSD
- libmongoc does not include a header file needed on FreeBSD
Based on the AIX issue, i probably be able to create a PR for this project. But i don't think i am able to create PR's for the other issues. I only have a basic understanding of programming and i never really used C and most of the other tools these projects are using.
Sorry for losing track of this. I noted that you opened MONGOCRYPT-470 for the libmongocrypt issue, which is currently being investigated, so I'll ignore the last half of the diff above so we can focus on the libresolv issue.
I understand what we'll need to revise CheckResolv.m4 in the PHP driver (we can address that in PHPC-2133), but I want to determine exactly what is required to get libmongoc working independent of PHP's build scripts. This will tell me exactly what needs to be done for CDRIVER-4465 and whether libmongoc's CMake build scripts need additional changes.
If you manually patch mongoc-client.c
in libmongoc to include netinet/in.h
, are you able to build libmongoc as a system library and then link it with the PHP driver and connect successfully? Note that you can specify --with-mongodb-client-side-encryption=no
when configuring the PHP driver to ignore libmongocrypt.
Following up. CDRIVER-4465 has been resolved for libmongoc 1.24.0, which will be included in the upcoming 1.16.0 release of the PHP driver. I've scheduled PHPC-2133 to ensure we incorporate any upstream fixes into our Autotools scripts.
Also, MONGOCRYPT-470 was fixed in libmongocrypt 1.7.0, which will also be included in the upcoming PHP driver release.