|
19 | 19 | #include "jit/ir/ir.h" |
20 | 20 | #include "jit/ir/ir_builder.h" |
21 | 21 |
|
| 22 | +#if defined(__APPLE__) && defined(__x86_64__) |
| 23 | +# include <mach-o/dyld.h> |
| 24 | +#endif |
| 25 | + |
22 | 26 | #if defined(IR_TARGET_X86) |
23 | 27 | # define IR_REG_SP 4 /* IR_REG_RSP */ |
24 | 28 | # define IR_REG_FP 5 /* IR_REG_RBP */ |
@@ -3329,6 +3333,24 @@ static void zend_jit_setup_unwinder(void) |
3329 | 3333 | } |
3330 | 3334 | #endif |
3331 | 3335 |
|
| 3336 | +#if defined(__APPLE__) && defined(__x86_64__) |
| 3337 | +/* Thunk format used since dydl 1284 (approx. MacOS 15) |
| 3338 | + * https://github.com/apple-oss-distributions/dyld/blob/9307719dd8dc9b385daa412b03cfceb897b2b398/libdyld/ThreadLocalVariables.h#L146 */ |
| 3339 | +struct TLV_Thunkv2 |
| 3340 | +{ |
| 3341 | + void* func; |
| 3342 | + uint32_t key; |
| 3343 | + uint32_t offset; |
| 3344 | +}; |
| 3345 | + |
| 3346 | +/* Thunk format used in earlier versions */ |
| 3347 | +struct TLV_Thunkv1 |
| 3348 | +{ |
| 3349 | + void* func; |
| 3350 | + size_t key; |
| 3351 | + size_t offset; |
| 3352 | +}; |
| 3353 | +#endif |
3332 | 3354 |
|
3333 | 3355 | static void zend_jit_setup(bool reattached) |
3334 | 3356 | { |
@@ -3436,12 +3458,25 @@ static void zend_jit_setup(bool reattached) |
3436 | 3458 | # elif defined(__APPLE__) && defined(__x86_64__) |
3437 | 3459 | tsrm_ls_cache_tcb_offset = tsrm_get_ls_cache_tcb_offset(); |
3438 | 3460 | if (tsrm_ls_cache_tcb_offset == 0) { |
3439 | | - size_t *ti; |
| 3461 | + struct TLV_Thunkv2 *thunk; |
3440 | 3462 | __asm__( |
3441 | 3463 | "leaq __tsrm_ls_cache(%%rip),%0" |
3442 | | - : "=r" (ti)); |
3443 | | - tsrm_tls_offset = ti[2]; |
3444 | | - tsrm_tls_index = ti[1] * 8; |
| 3464 | + : "=r" (thunk)); |
| 3465 | + |
| 3466 | + /* Detect dyld 1284: With dyld 1284, thunk->func will be _tlv_get_addr. |
| 3467 | + * Unfortunately this symbol is private, but we can find it |
| 3468 | + * as _tlv_bootstrap+8: https://github.com/apple-oss-distributions/dyld/blob/9307719dd8dc9b385daa412b03cfceb897b2b398/libdyld/threadLocalHelpers.s#L54 |
| 3469 | + * In earlier versions, thunk->func will be tlv_get_addr, which is not |
| 3470 | + * _tlv_bootstrap+8. |
| 3471 | + */ |
| 3472 | + if (thunk->func == (void*)((char*)_tlv_bootstrap + 8)) { |
| 3473 | + tsrm_tls_offset = thunk->offset; |
| 3474 | + tsrm_tls_index = (size_t)thunk->key * 8; |
| 3475 | + } else { |
| 3476 | + struct TLV_Thunkv1 *thunkv1 = (struct TLV_Thunkv1*) thunk; |
| 3477 | + tsrm_tls_offset = thunkv1->offset; |
| 3478 | + tsrm_tls_index = thunkv1->key * 8; |
| 3479 | + } |
3445 | 3480 | } |
3446 | 3481 | # elif defined(__GNUC__) && defined(__x86_64__) |
3447 | 3482 | tsrm_ls_cache_tcb_offset = tsrm_get_ls_cache_tcb_offset(); |
|
0 commit comments