mlocati/docker-php-extension-installer

`pdo_oci` config.m4 checks are always false on Alpine

Closed this issue · 6 comments

Version of install-php-extensions

latest

Error description

On Alpine images, all pdo_oci config.m4 checks are always false:

checking if we're at 64-bit platform... yes
checking Oracle version... 21.1
checking for oci.h... /usr/lib/oracle/21.1/client64/lib/sdk/include
checking for OCIEnvCreate in -lclntsh... no
checking for OCIEnvNlsCreate in -lclntsh... no
checking for OCIStmtFetch2 in -lclntsh... no
checking for PDO includes... /usr/local/include/php/ext

source: https://github.com/mvorisek/image-php/runs/5451037385?check_suite_focus=true#step:4:3978

but on Debian images, these checks are non-false:

checking if we're at 64-bit platform... yes
checking Oracle version... 21.1
checking for oci.h... /usr/lib/oracle/21.1/client64/lib/sdk/include
checking for OCIEnvCreate in -lclntsh... yes
checking for OCIEnvNlsCreate in -lclntsh... yes
checking for OCIStmtFetch2 in -lclntsh... yes
checking for PDO includes... /usr/local/include/php/ext

source: https://github.com/mvorisek/image-php/runs/5451038354?check_suite_focus=true#step:4:3293

the usage of this installer is like:

install-php-extensions pdo_oci

if the config.m4 checks are false, multibyte support is broken

as the Oracle Instant Client libs are installed the same on both platforms, I expect the config.m4 checks to be the same too (same on Alpine as on Debian)

maybe something needs to be added to the PATH on Alpine

Docker image

see desc

Minimal Dockerfile

No response

I guess it's a question that should be asked to the PHP maintainers...

@mlocati is it possible to build the OCI lib with always with HAVE_OCISTMTFETCH2 for Alpine? We know what OCI libs we download, so it will be always correct.

It is needed to correctly enable php/php-src@4df4264 needed for correct support for large CLOB DB fields, test case: https://github.com/php/php-src/blob/PHP-8.2.6/ext/pdo_oci/tests/bug60994.phpt

We can't define HAVE_OCISTMTFETCH2 manually: it's defined by the config.m4 file.

What config.m4 does? It tries to compile a simple program containing the OCIStmtFetch2 function by linking to the clntsh library: if it suceedes, HAVE_OCISTMTFETCH2 is defined to 1.
If it fails, that means that clntsh can't be found: if we maually patch config.m4 to always define HAVE_OCISTMTFETCH2, the compilation of the PHP extension would fail because the clntsh library won't be found.

I'm going to check why the clntsh library can't be found.

It seems that there's something really wrong.

I installed the Oracle Instant Client with this code.

Then I created a very simple test.c file:

#include <oci.h>

void test(OCIStmt* stmt, OCIError* err)
{
    OCIStmtFetch2(stmt, err, 1, OCI_FETCH_NEXT, 0, OCI_DEFAULT);
}
int main()
{
    return 0;
}

And tried to compile it with:

gcc -o test test.c -I/usr/lib/oracle/21.1/client64/lib/sdk/include -L/usr/lib/oracle/21.1/client64/lib -lclntsh

And it fails:

usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: warning: libnnz21.so, 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/12.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/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: warning: libclntshcore.so.21.1, 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/12.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/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `ztcedec'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `sltstan'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `larch_query'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `LhtStrSearch'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `lpusets'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `LdiDateFromString1'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `ztcedchk'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `lxkRegexpComp2'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.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/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `lrmpaa'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `lnxcpng'
/usr/lib/gcc/x86_64-alpine-linux-musl/12.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/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `LdiInitDef'
[...omissis...]
/usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/oracle/21.1/client64/lib/libclntsh.so: undefined reference to `lnxcmp'
collect2: error: ld returned 1 exit status

Until we find a way to fix this error, I guess that the OCI stuff won't work correctly on Alpine Linux...

It seems the LD fix for Alpine is not complete or some extra dep needs to be installed.

In https://github.com/mvorisek/image-php I fixed this by sed -E 's~#if HAVE_OCILOBREAD2$~#if 1~' -i ext/pdo_oci/oci_statement.c. The https://github.com/php/php-src/blob/PHP-8.2.6/ext/pdo_oci/tests/bug60994.phpt test passes then even on Alpine... But I am not sure if this hotpatching can/should be done in the installer itself as this does not address the reason and can change anytime.

@mlocati let's please fix this issue by patching the ext for Alpine using this command:

sed -E 's~#if HAVE_OCILOBREAD2$~#if 1~' -i ext/pdo_oci/oci_statement.c

In https://github.com/mvorisek/image-php/blob/8d6cedaf0c/make.php#L323 I have been using it for more than a year and no issues were reported. It fixed php/php-src#8197 well.

For Debian no patch is needed as #if HAVE_OCILOBREAD2 is working, but for Alpine, the patch is needed in order to support large strings (they are corrupted otherwise - related PR atk4/data#974 containing a testcase).