php-src icon indicating copy to clipboard operation
php-src copied to clipboard

PHP extension "sockets" build error (could not compile)

Open eduard-haritonov opened this issue 4 years ago • 8 comments

Description

Short description

PHP extension sockets is not compiled due to compilation errors. Reproduced in Docker containers and on a standalone Debian host.

With Docker CE, PHP official images:

  • php:8.0.15-fpm-bullseye
  • php:8.1.2-fpm-buster
# docker run -it --rm php:8.0.15-fpm-bullseye bash
~# docker-php-source extract
~# docker-php-ext-install -j"$(nproc)" sockets
/usr/src/php/ext/sockets/sendrecvmsg.c: In function 'init_ancillary_registry':
/usr/src/php/ext/sockets/sendrecvmsg.c:128:19: error: invalid application of 'sizeof' to incomplete type 'struct cmsgcred'
  128 |  PUT_ENTRY(sizeof(struct cmsgcred), 0, 0, from_zval_write_ucred,
      |                   ^~~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:99:17: note: in definition of macro 'PUT_ENTRY'
   99 |  entry.size   = sizev; \
      |                 ^~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:129:36: error: 'SCM_CREDS' undeclared (first use in this function)
  129 |    to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
      |                                    ^~~~~~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:105:19: note: in definition of macro 'PUT_ENTRY'
  105 |  key.cmsg_type  = type; \
      |                   ^~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:129:36: note: each undeclared identifier is reported only once for each function it appears in
  129 |    to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
      |                                    ^~~~~~~~~
/usr/src/php/ext/sockets/sendrecvmsg.c:105:19: note: in definition of macro 'PUT_ENTRY'
  105 |  key.cmsg_type  = type; \
      |                   ^~~~
make: *** [Makefile:216: sendrecvmsg.lo] Error 1
make: *** Waiting for unfinished jobs....

The difference of the file /usr/src/php/ext/sockets/sendrecvmsg.c against the same file in previous PHP versions (8.0.14 and 8.1.1):

8c8
<    | https://www.php.net/license/3_01.txt                                 |
---
>    | http://www.php.net/license/3_01.txt                                  |
123a124
> #ifdef ANC_CREDS_UCRED
125a127,130
> #else
> 	PUT_ENTRY(sizeof(struct cmsgcred), 0, 0, from_zval_write_ucred,
> 			to_zval_read_ucred, SOL_SOCKET, SCM_CREDS);
> #endif
438a444
> #ifdef SCM_CREDENTIALS
439a446,448
> #else
> 	REGISTER_LONG_CONSTANT("SCM_CREDS",		SCM_CREDS,	CONST_CS | CONST_PERSISTENT);
> #endif

Temporary workaround:

I could not find struct cmsgcred definition in various sockets.h files, so I have inserted the following line at the start of the file /usr/src/php/ext/sockets/sendrecvmsg.c:

#define ANC_CREDS_UCRED 1

After that change, the sockets extension was compiled successfully.

Of course, this hack cannot be a correct fix. Please provide more acceptable workaround and fix this issue. Let me know if you have any questions.

Thanks.

-- Eduard

PHP Version

8.0.15, 8.1.2

Operating System

Debian 10, Debian 11

eduard-haritonov avatar Jan 22 '22 09:01 eduard-haritonov

I can confirm that I have the same issue. Impossible to compile sockets extension on PHP 8.1.2.

michaljusiega avatar Jan 22 '22 10:01 michaljusiega

This is a duplicate of #7978; the bug has already been fixed.

cmb69 avatar Jan 22 '22 10:01 cmb69

I confirm: the patch https://github.com/php/php-src/pull/7981/files fixes the issue:

# docker run -it --rm php:8.0.15-fpm-bullseye bash
~# docker-php-source extract
~# patch /usr/src/php/ext/sockets/config.m4 -i- <<EOF
@@ -67,6 +67,9 @@
   AC_CACHE_CHECK([if ancillary credentials uses ucred],[ac_cv_ucred],
   [
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
 #include <sys/socket.h>
   ]], [[struct ucred u = {.gid = 0};]])],
       [ac_cv_ucred=yes], [ac_cv_ucred=no])
EOF
~# docker-php-ext-install -j"$(nproc)" sockets
....
Build complete.

Thanks.

eduard-haritonov avatar Jan 22 '22 12:01 eduard-haritonov

This issue is still reproducing. I'm trying to use it inside docker container, I use official image php:8.0 and I install sockets through docker-php-ext-install sockets and has the same issue

vandal-kherson avatar Jan 31 '22 11:01 vandal-kherson

We do not provide the official Docker images, so we cannot fix anything in this regard.

cmb69 avatar Jan 31 '22 12:01 cmb69

@vandal-kherson this is adressed here, including workaround https://github.com/docker-library/php/issues/1245

proligde avatar Jan 31 '22 12:01 proligde

We do not provide the official Docker images, so we cannot fix anything in this regard.

Thank you for fixing the issue. :-) Who provides the official docker images? Just by curiosity. 😅

CViniciusSDias avatar Feb 13 '22 04:02 CViniciusSDias

@CViniciusSDias They're official from Docker. https://docs.docker.com/docker-hub/official_images/

iluuu1994 avatar Feb 13 '22 10:02 iluuu1994