php / php/php-src

opcache/zend_shared_alloc.c: needed but ineffective pre-processor instructions

Open
#16,567 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: opcache Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

_GNU_SOURCE enabled sys/mman.h is needed for memfd_create and MFD_CLOEXEC, yet the needed pre-processor instructions at the top of zend_shared_alloc.c are useless since they are wrapped with ifdef HAVE_MEMFD_CREATE, which is defined in a *config.h not yet included.

See https://github.com/php/php-src/blob/master/ext/opcache/zend_shared_alloc.c#L22-L27

As a consequence, the build failed for me on Ubuntu-24.04 with GCC-13.

'./configure' \
'--disable-all' \
'--enable-debug' \
'--enable-cli' \
'--enable-opcache' 
make -j
/bin/bash /home/mike/src/php-src/libtool --silent --preserve-dup-deps --tag=CC --mode=compile cc -Iext/opcache/ -I/home/mike/src/php-src/ext/opcache/ -I/home/mike/src/php-src/main -I/home/mike/src/php-src -I/home/mike/src/php-src/ext/date/lib -I/home/mike/src/php-src/ext/raphf/src -I/home/mike/src/php-src/ext/raphf -I/home/mike/src/php-src/ext/http/src -I/home/mike/src/php-src/TSRM -I/home/mike/src/php-src/Zend    -fno-common -Wstrict-prototypes -Wformat-truncation -Wlogical-op -Wduplicated-cond -Wno-clobbered -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -g -ffp-contract=off -fvisibility=hidden -O0 -Wno-strict-prototypes -Wimplicit-fallthrough=1 -DZEND_SIGNALS    -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/jit/ir -DIR_TARGET_X64 -DIR_PHP -DIR_DEBUG -DZEND_COMPILE_DL_EXT=1 -c /home/mike/src/php-src/ext/opcache/zend_shared_alloc.c -o ext/opcache/zend_shared_alloc.lo  -MMD -MF ext/opcache/zend_shared_alloc.dep -MT ext/opcache/zend_shared_alloc.lo
In file included from /home/mike/src/php-src/Zend/zend.h:454,
                 from /home/mike/src/php-src/Zend/zend_objects.h:23,
                 from /home/mike/src/php-src/Zend/zend_globals.h:35,
                 from /home/mike/src/php-src/Zend/zend_compile.h:843,
                 from /home/mike/src/php-src/Zend/zend_extensions.h:23,
                 from /home/mike/src/php-src/ext/opcache/ZendAccelerator.h:51,
                 from /home/mike/src/php-src/ext/opcache/zend_shared_alloc.c:30:
/home/mike/src/php-src/Zend/zend_operators.h: In function ‘zend_memrchr’:
/home/mike/src/php-src/Zend/zend_operators.h:221:29: warning: implicit declaration of function ‘memrchr’; did you mean ‘memchr’? [-Wimplicit-function-declaration]
  221 |         return (const void*)memrchr(s, c, n);
      |                             ^~~~~~~
      |                             memchr
/home/mike/src/php-src/Zend/zend_operators.h:221:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  221 |         return (const void*)memrchr(s, c, n);
      |                ^
/home/mike/src/php-src/ext/opcache/zend_shared_alloc.c: In function ‘zend_shared_alloc_create_lock’:
/home/mike/src/php-src/ext/opcache/zend_shared_alloc.c:98:21: warning: implicit declaration of function ‘memfd_create’; did you mean ‘timer_create’? [-Wimplicit-function-declaration]
   98 |         lock_file = memfd_create("opcache_lock", MFD_CLOEXEC);
      |                     ^~~~~~~~~~~~
      |                     timer_create
/home/mike/src/php-src/ext/opcache/zend_shared_alloc.c:98:50: error: ‘MFD_CLOEXEC’ undeclared (first use in this function); did you mean ‘FD_CLOEXEC’?
   98 |         lock_file = memfd_create("opcache_lock", MFD_CLOEXEC);
      |                                                  ^~~~~~~~~~~
      |                                                  FD_CLOEXEC
/home/mike/src/php-src/ext/opcache/zend_shared_alloc.c:98:50: note: each undeclared identifier is reported only once for each function it appears in
make: *** [Makefile:794: ext/opcache/zend_shared_alloc.lo] Error 1
PHP Version

master

Operating System

Ubuntu 24.04

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The affected file is ext/opcache/zend_shared_alloc.c, with the preprocessor block near lines 22-27. Reproduce with the reported configure options and make -j on Ubuntu 24.04, then confirm the opcache build completes without the memfd_create/MFD_CLOEXEC errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.