|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81634 ZEND_ENABLE_STATIC_TSRMLS_CACHE produces extensions with the STATIC_TLS flag
Submitted: 2021-11-18 11:02 UTC Modified: 2021-11-18 14:03 UTC
From: Assigned: dmitry (profile)
Status: Closed Package: *General Issues
PHP Version: 8.0.12 OS: Linux
Private report: No CVE-ID: None
 [2021-11-18 11:02 UTC]
Starting in PHP 8, defining causes ZEND_ENABLE_STATIC_TSRMLS_CACHE causes the resulting extension to produce static TLS relocations. The resulting module will have the STATIC_TLS flag.

Depending on the size of the TLS are of the module and the other extensions already loaded, this can cause the glibc not to be able to load the extension, with the error "cannot allocate memory in static TLS block".

glibc has this comment in the relevant oath:
/* We are trying to perform a static TLS relocation in MAP, but it was
   dynamically loaded.  This can only work if there is enough surplus in
   the static TLS area already allocated for each running thread... */

This seems to happen even if the macros ZEND_TSRMLS_CACHE_EXTERN/DEFINE are not used by the extension so as to avoid the TSRM_TLS_MODEL_ATTR macro. I haven't tracked the exact effect of the ZEND_TSRMLS_CACHE_EXTERN macro but perhaps it is related to the usage of SG/PG/EG on the extension.

Test script:
readelf -d   | grep STATIC_TLS

Expected result:
The STATIC_TLS flags should not be found. IIUC, relocations related to the initial-exec model (R_X86_64_TPOFF64) should not be found in the extension.

Actual result:
The STATIC_TLS flags is found.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-18 11:03 UTC]
-Assigned To: +Assigned To: dmitry
 [2021-11-18 14:03 UTC]
Could you please check if fixes the problem for master branch.

I'm not sure if we will able to commit the fix into PHP-8.0 and PHP-8.1 brunches.
 [2021-11-24 17:48 UTC]
Automatic comment on behalf of dstogov
Log: Fixed bug #81634 (ZEND_ENABLE_STATIC_TSRMLS_CACHE produces extensionswith the STATIC_TLS flag)
 [2021-11-24 17:48 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Feb 03 16:03:49 2023 UTC