Skip to content

Build failure (incompatible pointer types, gcc-14) with PDO/iODBC #14367

Closed

Description

@orlitzky

Description

Originally reported at https://bugs.gentoo.org/932763 but I've confirmed with php-8.3.7:

/var/tmp/portage/dev-lang/php-8.3.6/work/sapis-build/embed/ext/pdo_odbc/odbc_driver.c: In function ‘pdo_odbc_error’:
/var/tmp/portage/dev-lang/php-8.3.6/work/sapis-build/embed/ext/pdo_odbc/odbc_driver.c:88:79: error: passing argument 5 of ‘SQLGetDiagRec’ from incompatible pointer type [-Wincompatible-pointer-types]
   88 |         rc = SQLGetDiagRec(htype, eh, recno++, (SQLCHAR *) einfo->last_state, &einfo->last_error,
      |                                                                               ^~~~~~~~~~~~~~~~~~
      |                                                                               |
      |                                                                               SDWORD * {aka long int *}
In file included from /usr/include/iodbc/sqlext.h:82,
                 from /usr/include/iodbc/sqlucode.h:81,
                 from /var/tmp/portage/dev-lang/php-8.3.6/work/sapis-build/embed/ext/pdo_odbc/php_pdo_odbc_int.h:51,
                 from /var/tmp/portage/dev-lang/php-8.3.6/work/sapis-build/embed/ext/pdo_odbc/odbc_driver.c:29:
/usr/include/iodbc/sql.h:1006:27: note: expected ‘SQLINTEGER *’ {aka ‘int *’} but argument is of type ‘SDWORD *’ {aka ‘long int *’}
 1006 |     SQLINTEGER          * NativeError,
      |     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

Both unixODBC and iODBC typedef SQLINTEGER to either an int or a long depending on the host system:

Apparently the two libraries make different choices on my system, because building against unixODBC still works, but in this case I don't think that's the root cause of the problem. If a SQLINTEGER can be either int or long, and if the PHP structure always has a fixed size SDWORD, there's probably a conversion or cast that should be done on the PHP side.

PHP Version

PHP 8.3.7

Operating System

No response

Activity

  1. SakiTakamachi commented on May 30, 2024

    @SakiTakamachi
    Member

    @orlitzky

    Could you please tell me the results of the following commands?

    php-config --configure-options
    
  2. orlitzky commented on May 30, 2024

    @orlitzky
    ContributorAuthor

    PHP did not successfully build so I don't think php-config is available? A full build log was posted to the Gentoo bug however. I will include the ./configure arguments below. For copy/pasting:

    ./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --datarootdir=/usr/share --disable-static --docdir=/usr/share/doc/php-8.3.6 --htmldir=/usr/share/doc/php-8.3.6/html --prefix=/usr/lib64/php8.3 --mandir=/usr/lib64/php8.3/man --infodir=/usr/lib64/php8.3/info --libdir=/usr/lib64/php8.3/lib --with-libdir=lib64 --localstatedir=/var --without-pear --without-valgrind --with-external-libcrypt --enable-zts --without-fpm-apparmor --with-password-argon2=/usr --with-avif --enable-bcmath --with-bz2=/usr --enable-calendar --without-capstone --enable-ctype --with-curl --enable-dom --with-enchant --enable-exif --with-ffi --enable-fileinfo --enable-filter --enable-ftp --with-gettext=/usr --with-gmp=/usr --with-mhash=/usr --with-iconv --enable-intl --enable-ipv6 --with-kerberos --with-libxml --enable-mbstring --with-openssl --enable-pcntl --enable-phar --enable-pdo --enable-opcache --with-pgsql=/usr --enable-posix --without-fpm-selinux --with-pspell=/usr --enable-simplexml --enable-shmop --with-snmp=/usr --enable-soap --enable-sockets --with-sodium --with-sqlite3 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy=/usr --enable-tokenizer --enable-xml --enable-xmlreader --enable-xmlwriter --with-xsl --with-zip --with-zlib=/usr --disable-debug --without-valgrind --enable-dba --with-cdb --with-db4=/usr --enable-flatfile --with-gdbm=/usr --enable-inifile --without-qdbm --with-tcadb=/usr --with-lmdb=/usr --with-freetype --disable-gd-jis-conv --with-jpeg --with-xpm --with-webp --enable-gd --with-imap=/usr --with-imap-ssl=/usr --with-ldap=/usr --with-ldap-sasl --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --without-unixODBC --with-iodbc --with-pdo-odbc=iODBC,/usr --with-pdo-dblib=/usr --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo-sqlite --without-pdo-firebird --with-readline=/usr --without-libedit --without-mm --with-pic --with-external-pcre --with-pcre-jit --cache-file=/var/tmp/portage/dev-lang/php-8.3.6/temp/config.cache --with-config-file-path=/etc/php/embed-php8.3 --with-config-file-scan-dir=/etc/php/embed-php8.3/ext-active --enable-embed --disable-cli --disable-cgi --disable-fpm --without-apxs2 --disable-phpdbg
    

    And for readability:

    ./configure
    --prefix=/usr
    --build=x86_64-pc-linux-gnu
    --host=x86_64-pc-linux-gnu
    --mandir=/usr/share/man
    --infodir=/usr/share/info
    --datadir=/usr/share
    --sysconfdir=/etc
    --localstatedir=/var/lib
    --datarootdir=/usr/share
    --disable-static
    --docdir=/usr/share/doc/php-8.3.6
    --htmldir=/usr/share/doc/php-8.3.6/html
    --prefix=/usr/lib64/php8.3
    --mandir=/usr/lib64/php8.3/man
    --infodir=/usr/lib64/php8.3/info
    --libdir=/usr/lib64/php8.3/lib
    --with-libdir=lib64
    --localstatedir=/var
    --without-pear
    --without-valgrind
    --with-external-libcrypt
    --enable-zts
    --without-fpm-apparmor
    --with-password-argon2=/usr
    --with-avif
    --enable-bcmath
    --with-bz2=/usr
    --enable-calendar
    --without-capstone
    --enable-ctype
    --with-curl
    --enable-dom
    --with-enchant
    --enable-exif
    --with-ffi
    --enable-fileinfo
    --enable-filter
    --enable-ftp
    --with-gettext=/usr
    --with-gmp=/usr
    --with-mhash=/usr
    --with-iconv
    --enable-intl
    --enable-ipv6
    --with-kerberos
    --with-libxml
    --enable-mbstring
    --with-openssl
    --enable-pcntl
    --enable-phar
    --enable-pdo
    --enable-opcache
    --with-pgsql=/usr
    --enable-posix
    --without-fpm-selinux
    --with-pspell=/usr
    --enable-simplexml
    --enable-shmop
    --with-snmp=/usr
    --enable-soap
    --enable-sockets
    --with-sodium
    --with-sqlite3
    --enable-sysvmsg
    --enable-sysvsem
    --enable-sysvshm
    --with-tidy=/usr
    --enable-tokenizer
    --enable-xml
    --enable-xmlreader
    --enable-xmlwriter
    --with-xsl
    --with-zip
    --with-zlib=/usr
    --disable-debug
    --without-valgrind
    --enable-dba
    --with-cdb
    --with-db4=/usr
    --enable-flatfile
    --with-gdbm=/usr
    --enable-inifile
    --without-qdbm
    --with-tcadb=/usr
    --with-lmdb=/usr
    --with-freetype
    --disable-gd-jis-conv
    --with-jpeg
    --with-xpm
    --with-webp
    --enable-gd
    --with-imap=/usr
    --with-imap-ssl=/usr
    --with-ldap=/usr
    --with-ldap-sasl
    --with-mysqli
    --with-mysql-sock=/var/run/mysqld/mysqld.sock
    --without-unixODBC
    --with-iodbc
    --with-pdo-odbc=iODBC,/usr
    --with-pdo-dblib=/usr
    --with-pdo-mysql=mysqlnd
    --with-pdo-pgsql
    --with-pdo-sqlite
    --without-pdo-firebird
    --with-readline=/usr
    --without-libedit
    --without-mm
    --with-pic
    --with-external-pcre
    --with-pcre-jit
    --cache-file=/var/tmp/portage/dev-lang/php-8.3.6/temp/config.cache
    --with-config-file-path=/etc/php/embed-php8.3
    --with-config-file-scan-dir=/etc/php/embed-php8.3/ext-active
    --enable-embed
    --disable-cli
    --disable-cgi
    --disable-fpm
    --without-apxs2
    --disable-phpdbg
    

    If you are using an older gcc, you should still be able to trigger the error with CFLAGS="${CFLAGS} -Werror=incompatible-pointer-types"

  3. SakiTakamachi commented on May 30, 2024

    @SakiTakamachi
    Member

    @orlitzky

    PHP did not successfully build so I don't think php-config is available?

    Ah, that's right. excuse me...

    Hmm. This is strange. einfo->last_error is defined as follows.
    https://github.com/php/php-src/blob/ec54edb9e1cacb95f93648a838ff5540aaf9bd37/ext/pdo_odbc/php_pdo_odbc_int.h#L115C2-L115C8

    If the SDWORD is loaded correctly, there should be no problem. And since this is code from 20 years ago, it doesn't mean that only master has been modified.

    It's already late in Japan time, so I'll investigate further tomorrow.

  4. orlitzky commented on May 30, 2024

    @orlitzky
    ContributorAuthor

    I found the problem. It's not the size of SQLINTEGER that is flaky, it's SDWORD:

    On my machine this leads to different sizes for SDWORD, one of which does not match SQLINTEGER. With unixODBC they agree,

    $ ./a.out 
    size of SQLINTEGER: 4
    size of SDWORD: 4
    

    and with iODBC they do not:

    $ ./a.out 
    size of SQLINTEGER: 4
    size of SDWORD: 8
    

    GCC has only recently started to consider this an error.

  5. SakiTakamachi commented on May 30, 2024

    @SakiTakamachi
    Member

    Ah, I see, thank you!
    In this case, it looks like we just need to cast it.

  6. NattyNarwhal commented on May 30, 2024

    @NattyNarwhal
    Member

    I did some investigation and last_error has been defined as SDWORD since the beginning of PDO_ODBC. It's an odd choice since SQLGetDiagRec defines that argument as SQLINTEGER.

    There's also some cases of its relative, SWORD being used in PDO_ODBC as well, mostly for i.e. column types. While I think those should always be equivalent to short, I think those should probably be SQLSMALLINT since that's what i.e. SQLDescribeParam call for as well.

  7. added 3 commits that reference this issue on May 31, 2024
    c30d8bb
    0987108
    c15f5a2
  8. orlitzky commented on Jun 4, 2024

    @orlitzky
    ContributorAuthor

    Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions