1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-11188: Error when building TSRM in ARM64

Although the issue mentioned FreeBSD, this is a broader problem:
the current ARM64 code to load the TLS offset assumes a setup with
the non-default TLS model. This problem can also apply on some
configurations on other platforms.

Closes GH-11236.
This commit is contained in:
nielsdos
2023-05-12 20:04:51 +02:00
committed by Niels Dossche
parent 75f6132818
commit 644d3628e3
4 changed files with 51 additions and 3 deletions

View File

@@ -777,11 +777,20 @@ TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
asm("adrp %0, #__tsrm_ls_cache@TLVPPAGE\n\t"
"ldr %0, [%0, #__tsrm_ls_cache@TLVPPAGEOFF]"
: "=r" (ret));
# else
# elif defined(TSRM_TLS_MODEL_DEFAULT)
/* Surplus Static TLS space isn't guaranteed. */
ret = 0;
# elif defined(TSRM_TLS_MODEL_INITIAL_EXEC)
asm("adrp %0, :gottprel:_tsrm_ls_cache\n\t"
"ldr %0, [%0, #:gottprel_lo12:_tsrm_ls_cache]"
: "=r" (ret));
# elif defined(TSRM_TLS_MODEL_LOCAL_EXEC)
asm("mov %0, xzr\n\t"
"add %0, %0, #:tprel_hi12:_tsrm_ls_cache, lsl #12\n\t"
"add %0, %0, #:tprel_lo12_nc:_tsrm_ls_cache"
: "=r" (ret));
# else
# error "TSRM TLS model not set"
# endif
return ret;
#else

View File

@@ -150,10 +150,13 @@ TSRM_API const char *tsrm_api_name(void);
#if !__has_attribute(tls_model) || defined(__FreeBSD__) || defined(__MUSL__) || defined(__HAIKU__)
# define TSRM_TLS_MODEL_ATTR
# define TSRM_TLS_MODEL_DEFAULT
#elif __PIC__
# define TSRM_TLS_MODEL_ATTR __attribute__((tls_model("initial-exec")))
# define TSRM_TLS_MODEL_INITIAL_EXEC
#else
# define TSRM_TLS_MODEL_ATTR __attribute__((tls_model("local-exec")))
# define TSRM_TLS_MODEL_LOCAL_EXEC
#endif
#define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1)