`OCIStmtFetch2 in -lclntsh...` (`HAVE_OCILOBREAD2`) check is always `no` on Alpine
Description
see https://github.com/mlocati/docker-php-extension-installer/issues/523
the Oracle Instant Client is installed using https://github.com/mlocati/docker-php-extension-installer/blob/c14bd17033b7bc45c262c9bf48a6f26b9ba92bc1/install-php-extensions#L1913 and added to ldconf path in https://github.com/mlocati/docker-php-extension-installer/blob/c14bd17033b7bc45c262c9bf48a6f26b9ba92bc1/install-php-extensions#L1454
the problematic config.m4 check is done in https://github.com/php/php-src/blob/5b01c4863fe9e4bc2702b2bbf66d292d23001a18/ext/pdo_oci/config.m4#L178
it seems the Alpine ldconf patch in /etc/ld-musl-x86_64.path is completely ignored by PHP_CHECK_LIBRARY
how to reproduce:
- run clean & latest Docker Alpine image
- download https://github.com/mlocati/docker-php-extension-installer/blob/master/install-php-extensions
- run
install-php-extensions pdo_oci - notice Oracle Instant Client is downloaded, instaled, php pdo_oci ext is configured & successfully built, but configure
check is alwayschecking for OCIStmtFetch2 in -lclntsh... nono(butyeson Debian image, with exactly the same steps & sources)
PHP Version
any
Operating System
Alpine
when I run:
readelf -Ws /usr/lib/oracle/21.1/client64/lib/libclntsh.so | grep OCIStmtFetch2
on both OSs, I get:
4653: 00000000033a4e90 16 FUNC GLOBAL DEFAULT 13 OCIStmtFetch2
49009: 00000000033a4e90 16 FUNC GLOBAL DEFAULT 13 OCIStmtFetch2
it seems PHP_CHECK_LIBRARY configure macro is broken
Dockerfile to reproduce:
FROM php:8.1-alpine
RUN apk update && apk upgrade \
&& apk add bash git make unzip gnupg ca-certificates strace coreutils binutils \
&& rm -rf /var/cache/apk/*
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
# notice the configure output, especially the "checking for OCIStmtFetch2 in -lclntsh..." line
RUN install-php-extensions pdo_oci
RUN readelf -Ws /usr/lib/oracle/21.1/client64/lib/libclntsh.so | grep OCIStmtFetch2
Any idea how to fix this? It here anyone skilled in autoconf, can you please help how debug PHP_CHECK_LIBRARY with minimalistic repro config/script?
Well, here I installed pdo_oci manually in the dockerfile alpine image.
cd /tmp/ \
&& tar -xf /usr/src/php.tar.xz php-7.4.30/ext/pdo_oci \
&& cd /tmp/php-7.4.30/ext/pdo_oci \
&& echo 'AC_DEFINE(HAVE_OCIENVNLSCREATE,1,[ ])' >> config.m4 \
&& phpize && ./configure --with-pdo-oci=instantclient,/usr/local/instantclient \
&& make && make install
After this the PDO_OCI driver was accepting the charset argument.
$pdo = new PDO("oci:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=abc.def)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=name)(SERVER=DEDICATED)));charset=utf8", "abc", "def");
@petk, you are the configure expert, any idea why https://github.com/php/php-src/blob/5b01c4863f/ext/pdo_oci/config.m4#L178 fails on Alpine and how to fix it?
@mvorisek, I've only quickly checked and I might be wrong here but there are some undefined references to GLIBC in that Oracle client. I'm not sure that this Oracle client library that is downloaded can be used with the Musl library. Alpine doesn't have GLIBC, and uses a very minimalistic Musl C library.
configure:6109: checking for OCILobRead2 in -lclntsh
configure:6132: cc -o conftest -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wl,-rpath,/usr/lib/oracle/21.1/client64/lib -L/usr/lib/oracle/21.1/client64/lib -Wl,-rpath,/usr/lib/oracle/21.1/client64/lib -L/usr/lib/oracle/21.1/client64/lib -Wl,-O1 -pie -lclntsh conftest.c -lclntsh >&5
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: warning: libdl.so.2, needed by /usr/lib/oracle/21.1/client64/lib/libclntsh.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `vsnprintf@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `fstatfs@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `timezone@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `accept@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `acos@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `sin@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `send@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `fscanf@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `sched_getparam@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `regexec@GLIBC_2.3.4'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `connect@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntshcore.so.21.1: undefined reference to `pthread_attr_setschedparam@GLIBC_2.2.5'
Yes, confirming. On Debian it works ok because it has GNU C library (glibc). Above is output from /usr/src/php/ext/pdo_oci/config.log for OCILobRead2 on Alpine, but applies also to OCIStmtFetch2 issue.
I'd suggest to move this issue to https://github.com/php/pecl-database-pdo_oci and it probably would be good to know if Oracle Client library should even be built on Alpine.
The GLIBC can be workaround using https://github.com/php/php-src/blob/php-8.3.3/.github/actions/setup-oracle/action.yml#L25 (or similarly in https://github.com/mlocati/docker-php-extension-installer/blob/2.2.2/install-php-extensions#L2014-L2032) ldconfig setup.
The pdo_oci is then fully working, but the workaround is not working for the configure. https://github.com/php/php-src/blob/5b01c4863f/ext/pdo_oci/config.m4#L178 is always false on Alpine and currently it must be overridden manually using https://github.com/mvorisek/image-php/blob/8d6cedaf0c/make.php#L323 (or possibly https://github.com/php/php-src/issues/8197#issuecomment-1254199508).
So currently pdo_oci already honors the ldconfig setup and is working with Alpine, but the configure check doesn't.
Any idea how to fix the https://github.com/php/php-src/blob/5b01c4863f/ext/pdo_oci/config.m4#L178 configure check to honor the ldconfig as the pdo_oci does?
I was checking this but still can't figured it out. Something needs to be additionally linked or passed to these PHP_CHECK_LIBRARY(clntsh, ... calls. Either via LIBS, LDFLAGS, or CFLAGS. But I have no idea what else is missing to the libclntsh at the moment. I've tried linking all sorts of libraries and adding -L flags to these defined in the /etc/ld-musl-x86_64.path.
/usr/src/php/ext/pdo_oci # ldd /usr/lib/oracle/21.1/client64/lib/libclntsh.so
/lib/ld-musl-x86_64.so.1 (0x7fd95c2fa000)
libnnz21.so => /usr/lib/oracle/21.1/client64/lib/libnnz21.so (0x7fd9577cf000)
libdl.so.2 => /lib/ld-musl-x86_64.so.1 (0x7fd95c2fa000)
libm.so.6 => /lib/ld-musl-x86_64.so.1 (0x7fd95c2fa000)
libpthread.so.0 => /lib/ld-musl-x86_64.so.1 (0x7fd95c2fa000)
librt.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fd95c2fa000)
libaio.so.1 => /usr/lib/libaio.so.1 (0x7fd9577ca000)
libresolv.so.2 => /lib/libresolv.so.2 (0x7fd9577b8000)
libc.so.6 => /lib/ld-musl-x86_64.so.1 (0x7fd95c2fa000)
ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fd9577b1000)
libclntshcore.so.21.1 => /usr/lib/oracle/21.1/client64/lib/libclntshcore.so.21.1 (0x7fd957200000)
libucontext.so.1 => /lib/libucontext.so.1 (0x7fd9571fb000)
libobstack.so.1 => /usr/lib/libobstack.so.1 (0x7fd9571f6000)
Error relocating /usr/lib/oracle/21.1/client64/lib/libclntsh.so: canonicalize_file_name: symbol not found
Error relocating /usr/lib/oracle/21.1/client64/lib/libclntsh.so: __dn_expand: symbol not found
Error relocating /usr/lib/oracle/21.1/client64/lib/libclntsh.so: __res_nsearch: symbol not found
Error relocating /usr/lib/oracle/21.1/client64/lib/libclntsh.so: bindresvport: symbol not found
Error relocating /usr/lib/oracle/21.1/client64/lib/libclntsh.so: __dn_skipname: symbol not found
Thank you. Given OCIStmtFetch2 is unconditionally used in oci8 ext https://github.com/php/pecl-database-oci8/blob/94def1f975/oci8_statement.c#L269 it can/should be used unconditionally in pdo_oci.
It is supported since at least y2003 / 10.1 [1] [2].
[1] https://docs.oracle.com/cd/B13789_01/appdev.101/b10779/oci16ms3.htm [2] https://en.wikipedia.org/wiki/Oracle_Database#Releases_and_versions
Good one. I was also thinking if some of these are available by using some minimum version but I wasn't sure. Then the check can be even removed. Are there more of these besides OCIStmtFetch2 that can be assumed they are always available?