php-src/TSRM
Hao Sun 7c2a3a9400
JIT/AArch64: [macos][ZTS] Support fast path for tlv_get_addr (#7042)
* JIT/AArch64: [macos][ZTS] Support fast path for tlv_get_addr

Access to TLV(thread local variable) in macOS is in "dynamic" form and
function tlv_get_addr() is invoked to resolve the address. See the
example in [1].

Note there is one struct TLVDescriptor [2] for each TLV. The first
member holds the address of function tlv_get_addr(), and the other two
members, "key" and "offset", would be used inside tlv_get_addr().

The disassembly code for function tlv_get_addr() is shown in [3]. With
the value from system register, i.e. tpidrro_el0, together with "key"
and "offset", the TLV address can be obtained.

Note that the value from tpidrro_el0 varies for different threads, and
unique address for TLV is resolved.

It's worth noting that slow path would be executed, i.e. function
tlv_allocate_and_initialize_for_key(), for the first time of TLV access.

In this patch:
1. "_tsrm_ls_cache" is guaranteed to be accessed before any VM/JIT code
during the request startup, e.g. in init_executor(), therefore, slow
path can be avoided.

2. As TLVDecriptor is immutable and zend_jit_setup() executes once, we
get this structure in tsrm_get_ls_cache_tcb_offset(). Note the 'ldr'
instruction would be patched to 'add' by the linker.

3. Only fast path for tlv_get_addr() is implemented in macro
LOAD_TSRM_CACHE.

With this patch, all ~4k test cases can pass for ZTS+CALL in macOS on
Apple silicon.

[1] https://gist.github.com/shqking/4aab67e0105f7c1f2c549d57d5799f94
[2]
https://opensource.apple.com/source/dyld/dyld-195.6/src/threadLocalVariables.c.auto.html
[3] https://gist.github.com/shqking/329d7712c26bad49786ab0a544a4af43

Change-Id: I613e9c37e3ff2ecc3fab0f53f1e48a0246e12ee3
2021-05-31 14:27:00 +08:00
..
config.w32 Remove unused tsrm_strtok_r() function 2019-07-12 13:14:24 +02:00
LICENSE - Update to 2006 2006-01-04 23:55:42 +00:00
threads.m4 Remove PTHREADS_ASSIGN_VARS 2019-07-05 23:26:20 +02:00
tsrm_win32.c Update http->https in license (#6945) 2021-05-06 12:16:35 +02:00
tsrm_win32.h Update http->https in license (#6945) 2021-05-06 12:16:35 +02:00
TSRM.c JIT/AArch64: [macos][ZTS] Support fast path for tlv_get_addr (#7042) 2021-05-31 14:27:00 +08:00
TSRM.h Detect musl libc to not set tls_model attribute on that platform 2021-05-21 09:02:46 +01:00
tsrm.m4 Merge branch 'PHP-7.4' 2019-07-01 13:26:17 +02:00