@@ -201,56 +201,35 @@ static uint32_t default_mflags = 0;
201201static bool delayed_call_chain = false; // TODO: remove this var (use jit->delayed_call_level) ???
202202
203203#ifdef ZTS
204- static size_t tsrm_ls_cache_tcb_offset = 0;
205- static size_t tsrm_tls_index = -1;
206- static size_t tsrm_tls_offset = -1;
207-
208- # ifdef ZEND_EG_TLS
209- /* When nonzero, &executor_globals_tls/&compiler_globals_tls equal the thread
210- * pointer plus this offset, so the JIT forms them without a runtime call. */
211204static size_t eg_tls_tcb_offset = 0;
212205static size_t cg_tls_tcb_offset = 0;
213206/* gottpoff yields the offset from the %fs-based thread pointer that ir_TLS(0)
214207 * loads. */
215- # if defined(__ELF__) && defined(__x86_64__) && defined(__GNUC__) && !defined(TSRM_TLS_MODEL_DEFAULT)
216- # define ZEND_JIT_TLS_TCB_OFFSET(sym) __extension__({ \
208+ # if defined(__ELF__) && defined(__x86_64__) && defined(__GNUC__) && !defined(TSRM_TLS_MODEL_DEFAULT)
209+ # define ZEND_JIT_TLS_TCB_OFFSET(sym) __extension__({ \
217210 size_t _off; \
218211 __asm__ ("movq " #sym "@gottpoff(%%rip),%0" : "=r" (_off)); \
219212 _off; \
220213 })
221- # elif defined(__ELF__) && defined(__aarch64__) && !defined(__APPLE__) && \
214+ # elif defined(__ELF__) && defined(__aarch64__) && !defined(__APPLE__) && \
222215 (defined(__GNUC__) || defined(__clang__))
223216/* The TLS variable sits at a fixed offset from tpidr_el0 (the thread pointer
224217 * the JIT reads with mrs); compute it once on the main thread. Subtracting the
225218 * thread pointer is model-independent (works for both local- and initial-exec)
226219 * and matches tsrm_get_ls_cache_tcb_offset()'s tprel reasoning. */
227- # define ZEND_JIT_TLS_TCB_OFFSET(sym) __extension__({ \
220+ # define ZEND_JIT_TLS_TCB_OFFSET(sym) __extension__({ \
228221 char *_tp; \
229222 __asm__ ("mrs %0, tpidr_el0" : "=r" (_tp)); \
230223 (size_t)((char*)&(sym) - _tp); \
231224 })
232- # else
233- # define ZEND_JIT_TLS_TCB_OFFSET(sym) ((size_t)0)
234- # endif
225+ # else
226+ # define ZEND_JIT_TLS_TCB_OFFSET(sym) ((size_t)0)
235227# endif
236228
237- # define EG_TLS_OFFSET(field) \
238- (executor_globals_offset + offsetof(zend_executor_globals, field))
239-
240- # define CG_TLS_OFFSET(field) \
241- (compiler_globals_offset + offsetof(zend_compiler_globals, field))
242-
243- # ifdef ZEND_EG_TLS
244- # define jit_EG(_field) \
229+ # define jit_EG(_field) \
245230 ir_ADD_OFFSET(jit_EG_base(jit), offsetof(zend_executor_globals, _field))
246- # define jit_CG(_field) \
231+ # define jit_CG(_field) \
247232 ir_ADD_OFFSET(jit_CG_base(jit), offsetof(zend_compiler_globals, _field))
248- # else
249- # define jit_EG(_field) \
250- ir_ADD_OFFSET(jit_TLS(jit), EG_TLS_OFFSET(_field))
251- # define jit_CG(_field) \
252- ir_ADD_OFFSET(jit_TLS(jit), CG_TLS_OFFSET(_field))
253- # endif
254233
255234#else
256235
@@ -333,12 +312,9 @@ typedef struct _zend_jit_ctx {
333312 uint32_t delayed_call_level;
334313 int b; /* current basic block number or -1 */
335314#ifdef ZTS
336- ir_ref tls;
337- # ifdef ZEND_EG_TLS
338315 ir_ref tp; /* cached thread pointer for &EG/&CG */
339316 ir_ref eg_tls; /* cached base of __thread executor_globals_tls */
340317 ir_ref cg_tls; /* cached base of __thread compiler_globals_tls */
341- # endif
342318#endif
343319 ir_ref fp;
344320 ir_ref poly_func_ref; /* restored from parent trace snapshot */
@@ -529,12 +505,6 @@ static const char* zend_reg_name(int8_t reg)
529505/* IR helpers */
530506
531507#ifdef ZTS
532- static void * ZEND_FASTCALL zend_jit_get_tsrm_ls_cache(void)
533- {
534- return _tsrm_ls_cache;
535- }
536-
537- # ifdef ZEND_EG_TLS
538508static void * ZEND_FASTCALL zend_jit_get_eg_tls(void)
539509{
540510 return &executor_globals_tls;
@@ -583,44 +553,12 @@ static ir_ref jit_GLOBALS_TLS_call(zend_jit_ctx *jit, ir_ref *cache, const void
583553 }
584554 return *cache;
585555}
586- # define jit_EG_base(jit) (eg_tls_tcb_offset \
556+ # define jit_EG_base(jit) (eg_tls_tcb_offset \
587557 ? ir_ADD_OFFSET(jit_TP(jit), eg_tls_tcb_offset) \
588558 : jit_GLOBALS_TLS_call((jit), &(jit)->eg_tls, zend_jit_get_eg_tls))
589- # define jit_CG_base(jit) (cg_tls_tcb_offset \
559+ # define jit_CG_base(jit) (cg_tls_tcb_offset \
590560 ? ir_ADD_OFFSET(jit_TP(jit), cg_tls_tcb_offset) \
591561 : jit_GLOBALS_TLS_call((jit), &(jit)->cg_tls, zend_jit_get_cg_tls))
592- # endif
593-
594- static ZEND_ATTRIBUTE_UNUSED ir_ref jit_TLS(zend_jit_ctx *jit)
595- {
596- ZEND_ASSERT(jit->ctx.control);
597- if (jit->tls) {
598- /* Emit "TLS" once for basic block */
599- ir_insn *insn;
600- ir_ref ref = jit->ctx.control;
601-
602- while (1) {
603- if (ref == jit->tls) {
604- return jit->tls;
605- }
606- insn = &jit->ctx.ir_base[ref];
607- if (insn->op >= IR_START || insn->op == IR_CALL) {
608- break;
609- }
610- ref = insn->op1;
611- }
612- }
613-
614- if (tsrm_ls_cache_tcb_offset == 0 && tsrm_tls_index == -1) {
615- jit->tls = ir_CALL(IR_ADDR, ir_CONST_FC_FUNC(zend_jit_get_tsrm_ls_cache));
616- } else {
617- jit->tls = ir_TLS(
618- tsrm_ls_cache_tcb_offset ? tsrm_ls_cache_tcb_offset : tsrm_tls_index,
619- tsrm_ls_cache_tcb_offset ? IR_NULL : tsrm_tls_offset);
620- }
621-
622- return jit->tls;
623- }
624562#endif
625563
626564static ir_ref jit_CONST_ADDR(zend_jit_ctx *jit, uintptr_t addr)
@@ -2917,12 +2855,9 @@ static void zend_jit_init_ctx(zend_jit_ctx *jit, uint32_t flags)
29172855 delayed_call_chain = false;
29182856 jit->b = -1;
29192857#ifdef ZTS
2920- jit->tls = IR_UNUSED;
2921- # ifdef ZEND_EG_TLS
29222858 jit->tp = IR_UNUSED;
29232859 jit->eg_tls = IR_UNUSED;
29242860 jit->cg_tls = IR_UNUSED;
2925- # endif
29262861#endif
29272862 jit->fp = IR_UNUSED;
29282863 jit->poly_func_ref = IR_UNUSED;
@@ -3316,11 +3251,8 @@ static void zend_jit_setup_disasm(void)
33163251
33173252 REGISTER_DATA(CG(map_ptr_base));
33183253#else /* ZTS */
3319- REGISTER_HELPER(zend_jit_get_tsrm_ls_cache);
3320- # ifdef ZEND_EG_TLS
33213254 REGISTER_HELPER(zend_jit_get_eg_tls);
33223255 REGISTER_HELPER(zend_jit_get_cg_tls);
3323- # endif
33243256#endif
33253257#endif
33263258}
@@ -3531,19 +3463,8 @@ static void zend_jit_setup(bool reattached)
35313463#endif
35323464
35333465#ifdef ZTS
3534- zend_result result = zend_jit_resolve_tsrm_ls_cache_offsets(
3535- &tsrm_ls_cache_tcb_offset,
3536- &tsrm_tls_index,
3537- &tsrm_tls_offset
3538- );
3539- if (result == FAILURE) {
3540- zend_accel_error(ACCEL_LOG_INFO,
3541- "Could not get _tsrm_ls_cache offsets, will fallback to runtime resolution");
3542- }
3543- # ifdef ZEND_EG_TLS
35443466 eg_tls_tcb_offset = ZEND_JIT_TLS_TCB_OFFSET(executor_globals_tls);
35453467 cg_tls_tcb_offset = ZEND_JIT_TLS_TCB_OFFSET(compiler_globals_tls);
3546- # endif
35473468#endif
35483469
35493470#if !defined(ZEND_WIN32) && !defined(IR_TARGET_AARCH64)
0 commit comments