[php-src] Issue #8834: _GNU_SOURCE definition not effective - memrchr() missing
| From: | rainerjung | Date: | Mon, 20 Jun 2022 20:04:48 +0000 |
| Subject: | [php-src] Issue #8834: _GNU_SOURCE definition not effective - memrchr() missing | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241772@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8834
Author: rainerjung
### Description
Compilation warns
```
warning: cast to pointer from integer of different size [-Wint-to-pointe
r-cast]
return (const void*)memrchr(s, c, n);
...
warning: implicit declaration of function 'memrchr'; did you mean 'memc
hr'? [-Wimplicit-function-declaration]
return (const void*)memrchr(s, c, n);
```
Although configure sets _GNU_SOURCE in main/php_config.h which should make memrchr() available, in
practise this does not suffice. For example Zend/zend_strtod.c includes zend_operators.h, which
includes Zend/zend_portability.h, Zend/zend_config.h and finally main/php_config. There _GNU_SOURCE
gets defined and then string.h is included, but nevertheles memrchr ist not available. Looking at
string.h, memrchr needs __USE_GNU to define memrchr. __USE_GNU should not be set directly, but gets
set from _GNU_SOURCE in features.h. This header file as most system header files gets loaded only
once and is inluded by most system header files. So whenever another system header file is included
before php_main.h, the setting of _GNU_SOURCE there no longer is effective.
For example Zend/zend_operators.h loads errno.h and assert.h before it loads zend_portability.h,
Zend/zend_config.h and finally main/php_config. Both if these system header files already load
features.h
Since reorganizing he header file orders might be brittle, it seems better to add _GNU_SOURCE to
CFLAGS or CPPFLAGS by the Makefile (which already does it for a few compilation units) and probably
to make the Makefile or an include of it configure controlled.
### PHP Version
PHP 8.2.0alpha1
### Operating System
Linux eg. RHEL 8