Edit report at https://bugs.php.net/bug.php?id=78303&edit=1
ID: 78303
Updated by: nikic@php.net
Reported by: theultramage at gmail dot com
Summary: repeating crashes in php_basename with
event-mpm+mod_php
Status: Open
Type: Bug
Package: *General Issues
Operating System: FreeBSD 12.0
PHP Version: 7.3.7
Block user comment: N
Private report: N
New Comment:
If it's possible to restore that code in the FreeBSD port, that would be good. We should
probably also change the check on our side from defined(_REENTRANT) to defined(ZTS), as we perform
the availability check without _REENTRANT and I don't believe this symbol has a dependence on
it. The absence of _REENTRANT might affect other things as well though...
Previous Comments:
------------------------------------------------------------------------
[2019-07-17 11:46:31] theultramage at gmail dot com
The usage of the routines in the autoconf module you referenced, PTHREADS_FLAGS and PTHREADS_CHECK,
has been deliberately patched out in the freebsd ports tree. This is why the flag isn't being
applied.
I traced the port's svn history and it goes back all the way to 2004 and php 4.3.9. It says
"Fix compilation of thread-safe PHP after the PTHREAD_LIBS change" which might be
referring to some sort of systems code restructuring effort.
Originally, they just removed the freebsd piece of code in PTHREADS_FLAGS:
https://svnweb.freebsd.org/ports/head/lang/php4/files/patch-configure?revision=118610&view=markup&pathrev=160333
It was then changed to remove the invocation of the autoconf macros:
https://svnweb.freebsd.org/ports/head/lang/php4/files/patch-configure.in?revision=161492&view=markup&pathrev=170333
------------------------------------------------------------------------
[2019-07-17 11:03:34] nikic@php.net
I got confused here and mixed up CPPFLAGS and CXXFLAGS... adding to CPPFLAGS is right and should
work, so I'm not sure why it isn't happening.
------------------------------------------------------------------------
[2019-07-17 10:52:23] theultramage at gmail dot com
Good catch. On my end, I found a stackoverflow post, stating "Use g++ -pthread, it is
equivalent to g++ -lpthread -D_REENTRANT". So gcc (and it seems clang as well) have this fancy
helper parameter. The freebsd ports makefile only does "LIBS += -lpthread" and thus
apparently does not invoke this mechanism. I'll correct it from this end and see if it changes
anything.
------------------------------------------------------------------------
[2019-07-17 10:45:48] nikic@php.net
-D_REENTRANT should be added by configure in https://github.com/php/php-src/blob/master/TSRM/threads.m4#L44
... but looks like it's only added to CPPFLAGS, not CFLAGS in https://github.com/php/php-src/blob/master/TSRM/threads.m4#L58.
------------------------------------------------------------------------
[2019-07-17 10:31:20] theultramage at gmail dot com
mbrlen is available according to config.log.
I dug a bit deeper and found that php's /ext/standard/php_string.h does a weird thing:
#elif defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T)
# define php_mblen(ptr, len) ((int) mbrlen(ptr, len, &BG(mblen_state)))
Instead of letting configure do the work, it instead relies on an obsolete internal flag
'_REENTRANT'.
Earlier I wasn't specific enough. By 'whatever thread safety flags available' I meant
all the ones supplied by the freebsd ports system. That is, one just adds -lpthread and the other
adds --enable-maintainer-zts and pthreads_working="yes".
Possible scenarios to investigate: clang not automatically defining _REENTRANT. Inclusion of
libpthread not automatically defining _REENTRANT. Header/include ordering issue resulting in
_REENTRANT not propagating properly.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=78303
--
Edit this bug report at https://bugs.php.net/bug.php?id=78303&edit=1