Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion TSRM/TSRM.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,10 @@ TSRM_API void *tsrm_get_ls_cache(void)
/* Returns offset of tsrm_ls_cache slot from Thread Control Block address */
TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
{/*{{{*/
#if defined(__APPLE__) && defined(__x86_64__)
#if defined(TSRM_TLS_MODEL_USE_DEFAULT) && defined(__PIC__) && !defined(__PIE__)
/* The compiler may use dynamic TLS. Do not force a static TLS relocation. */
return 0;
#elif defined(__APPLE__) && defined(__x86_64__)
// TODO: Implement support for fast JIT ZTS code ???
return 0;
#elif defined(__x86_64__) && defined(__GNUC__) && !defined(__FreeBSD__) && \
Expand Down
9 changes: 7 additions & 2 deletions TSRM/TSRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ TSRM_API bool tsrm_is_managed_thread(void);
# define TSRM_TLS_MODEL_ATTR
# define TSRM_TLS_MODEL_DEFAULT
#elif defined(__PIC__) && !defined(__PIE__)
# define TSRM_TLS_MODEL_ATTR __attribute__((tls_model("initial-exec")))
# define TSRM_TLS_MODEL_INITIAL_EXEC
# if defined(TSRM_TLS_MODEL_USE_DEFAULT)
# define TSRM_TLS_MODEL_ATTR
# define TSRM_TLS_MODEL_DEFAULT
Comment on lines +170 to +172

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an extra block under PIC && !PIE instead of adding it above, because we want to keep the explicit local-exec choice in !PIC || PIE.

# else
# define TSRM_TLS_MODEL_ATTR __attribute__((tls_model("initial-exec")))
# define TSRM_TLS_MODEL_INITIAL_EXEC
# endif
#else
# define TSRM_TLS_MODEL_ATTR __attribute__((tls_model("local-exec")))
# define TSRM_TLS_MODEL_LOCAL_EXEC
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ PHP 8.6 INTERNALS UPGRADE NOTES
HAVE_STRUCT_STAT_ST_BLOCKS).
. Added a new configure option --disable-apache2-conf to prevent apxs from
editing httpd.conf during installation.
. Apache ZTS builds now use the compiler's default TLS model. To opt into
initial-exec, add -ftls-model=initial-exec to CFLAGS (and CXXFLAGS for C++
code). This may require increasing the host processes static TLS surplus,
e.g. by setting GLIBC_TUNABLES=glibc.rtld.optional_static_tls=8192.

- Windows build system changes:
. Function SETUP_OPENSSL() doesn't accept 6th argument anymore and doesn't
Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ SAPI_SHARED=libs/$SAPI_LIBNAME_SHARED
SAPI_STATIC=libs/$SAPI_LIBNAME_STATIC
SAPI_LIBTOOL=libphp.la

dnl Set by SAPIs whose host program dlopen()s libphp without linking against it.
php_tsrm_dlopened_sapi=no

PHP_CONFIGURE_PART([Configuring SAPI modules])

esyscmd(./build/config-stubs sapi)
Expand Down Expand Up @@ -885,6 +888,20 @@ AS_VAR_IF([PHP_THREAD_SAFETY], [yes], [

AC_MSG_CHECKING([for POSIX threads])
AC_MSG_RESULT([yes])

AS_VAR_IF([php_tsrm_dlopened_sapi], [yes], [
php_tsrm_tls_model=
for flag in $CFLAGS $EXTRA_CFLAGS; do
AS_CASE([$flag], [-ftls-model=*], [php_tsrm_tls_model=$flag])
done

dnl Define TSRM_TLS_MODEL_USE_DEFAULT to avoid forcing static TLS in dlopened SAPIs.
dnl Omit it for explicit initial-exec to enable the TCB offset fast path.
AS_IF([test "$php_tsrm_tls_model" != "-ftls-model=initial-exec"], [
AC_DEFINE([TSRM_TLS_MODEL_USE_DEFAULT], [1],
[Define to 1 to use the compiler's default TLS model.])
])
])
])

PHP_ARG_ENABLE([rtld-now],
Expand Down
5 changes: 5 additions & 0 deletions sapi/apache2handler/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ if test "$PHP_APXS2" != "no"; then
LIBPHP_CFLAGS="-shared"
PHP_SUBST([LIBPHP_CFLAGS])

dnl httpd dlopen's libphp.so without linking against it, so we must
dnl use global-dynamic by default. Use -ftls-model=initial-exec to
dnl override the compiler choice, see UPGRADING.INTERNALS
php_tsrm_dlopened_sapi=yes

php_sapi_apache2handler_type=shared
AS_CASE([$host_alias],
[*aix*], [
Expand Down
Loading