-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libbson Bug Report : variable ret value type error #1445
Comments
@jingjingxyk: Can you confirm that the error also appears when compiling the extension on its own (i.e. not statically linked to PHP)? I just want to rule that out. Looking at the compiler flags in the screenshot, I see the following:
According to the Clang docs, Looking at the #elif defined(__GNUC__) && defined(_GNU_SOURCE)
ret = strerror_r (err_code, buf, buflen);
#else /* XSI strerror_r */
if (strerror_r (err_code, buf, buflen) == 0) {
ret = buf;
}
#endif And then consider the following from strerror_r(3):
My guess is that Alpine is also defining Note: I do not suggest using A workaround may require either manually changing defined constants or patching the code for now. |
@jmikola According to your suggestion, after verification, I found that this error only appears in alpine linux and clang compilers and PHP versions greater than 8.2.0. static links and non-static links also report errors . verify result:
PHP 8.2 New features: https://github.com/php/php-src/blob/72e2e25066e2f50ce1c1b1da4fc5721f3460510c/configure.ac#L273C37-L273C37 |
verify commandbuild script
set -uex
mkdir -p /tmp/t
cd /tmp/t
PHP_VERSION=8.1.21
PHP_VERSION=8.2.1
test -f php-${PHP_VERSION}.tar.gz || wget -O php-${PHP_VERSION}.tar.gz https://github.com/php/php-src/archive/refs/tags/php-${PHP_VERSION}.tar.gz
test -d php-src && rm -rf php-src
mkdir -p php-src
tar --strip-components=1 -C php-src -xf php-${PHP_VERSION}.tar.gz
test -f mongodb-1.16.1.tgz || wget -O mongodb-1.16.1.tgz https://github.com/mongodb/mongo-php-driver/releases/download/1.16.1/mongodb-1.16.1.tgz
mkdir -p mongodb
tar --strip-components=1 -C mongodb -xf mongodb-1.16.1.tgz
test -d php-src/ext/mongodb && rm -rf php-src/ext/mongodb
mv mongodb php-src/ext/
export CC=gcc
export CXX=g++
export LD=ld
export CC=clang
export CXX=clang++
export LD=ld.lld
cd php-src
./buildconf --force
./configure \
--disable-all \
--disable-cgi \
--enable-shared=no \
--enable-static=yes \
--enable-cli \
--disable-phpdbg \
--without-valgrind \
--enable-mongodb \
--with-mongodb-system-libs=no \
--with-mongodb-ssl=no \
--with-mongodb-sasl=no \
--with-mongodb-icu=no \
--with-mongodb-client-side-encryption=no
make -j $(nproc)
file sapi/cli/php
readelf -h sapi/cli/php debian environmentdocker run --rm -ti --init -v .:/work -w /work debian:11
apt update -y
apt install -y git curl wget ca-certificates \
xz-utils autoconf automake clang-tools clang lld libtool cmake bison re2c gettext coreutils lzip zip unzip \
pkg-config bzip2 flex p7zip \
gcc g++ vim
alpine environmentdocker run --rm -ti --init -v .:/work -w /work alpine:3.17
apk update
apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake \
bison re2c gettext coreutils gcc g++ \
bash p7zip zip unzip flex pkgconf ca-certificates \
wget git curl \
libc++-static libltdl-static
|
I found that there is a difference between php8.1.21 and php8.2.0 compilation parameters . # php 8.1.21
:<<'EOF'
-fno-common
-Wstrict-prototypes
-Wall
-Wextra
-Wno-strict-aliasing
-Wno-unused-parameter
-Wno-sign-compare -g -O2
-fvisibility=hidden
-DZEND_SIGNALS
EOF
# php 8.2.1
:<<'EOF'
-D_GNU_SOURCE
-fno-common
-Wstrict-prototypes
-Wall
-Wextra
-Wno-strict-aliasing
-Wno-unused-parameter
-Wno-sign-compare -g -O2
-fvisibility=hidden
-DZEND_SIGNALS
-DBSON_COMPILATION
-DMONGOC_COMPILATION
-D_DEFAULT_SOURCE
-DKMS_MESSAGE_LITTLE_ENDIAN=1
-DMONGOCRYPT_LITTLE_ENDIAN=1
EOF
|
On x86_64 glibc memrchr() uses SSE/AVX CPU extensions and works much faster then naive loop. On x86 32-bit we still use inlined version. memrchr() is a GNU extension. Its prototype becomes available when <string.h> is included with defined _GNU_SOURCE macro. Previously, we defined it in "php_config.h", but some sources may include <string.h> befire it. To avod mess we also pass -D_GNU_SOURCE to C compiler.
@jingjingxyk: Thanks for the extensive testing. The addition of |
/bin/sh /private/tmp/pear/temp/pear-build-rootP1ik7m/mongodb-1.15.1/libtool --mode=compile cc -Isrc/libmongoc/src/libbson/src/bson/ -I/private/tmp/pear/temp/mongodb/src/libmongoc/src/libbson/src/bson/ -I/private/tmp/pear/temp/pear-build-rootP1ik7m/mongodb-1.15.1/include -I/private/tmp/pear/temp/pear-build-rootP1ik7m/mongodb-1.15.1/main -I/private/tmp/pear/temp/mongodb -I/Applications/MAMP/bin/php/php8.2.0/include/php -I/Applications/MAMP/bin/php/php8.2.0/include/php/main -I/Applications/MAMP/bin/php/php8.2.0/include/php/TSRM -I/Applications/MAMP/bin/php/php8.2.0/include/php/Zend -I/Applications/MAMP/bin/php/php8.2.0/include/php/ext -I/Applications/MAMP/bin/php/php8.2.0/include/php/ext/date/lib -I/private/tmp/pear/temp/mongodb/src/libmongoc/src/common/ -I/private/tmp/pear/temp/mongodb/src/libmongoc/src/libbson/src/ -I/private/tmp/pear/temp/mongodb/src/libmongoc/src/libbson/src/jsonsl/ -I/private/tmp/pear/temp/mongodb/src/libmongoc/src/libmongoc/src/ -I/private/tmp/pear/temp/mongodb/src/libmongoc/src/zlib-1.2. |
Note: above comment is a duplicate of #1541. |
Bug Report
https://github.com/mongodb/mongo-c-driver/blob/6b7caf9da30eeae09c8eb0c539ebacbb31b9e520/src/libbson/src/bson/bson-error.c#L113
test php static link on alpine 3.17
The text was updated successfully, but these errors were encountered: