Loading...
libdyld/threadLocalHelpers.s dyld-940 dyld-1335
--- dyld/dyld-940/libdyld/threadLocalHelpers.s
+++ dyld/dyld-1335/libdyld/threadLocalHelpers.s
@@ -20,8 +20,11 @@
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
- 
-#include <System/machine/cpu_capabilities.h>
+
+#include <TargetConditionals.h>
+#if !TARGET_OS_EXCLAVEKIT
+  #include <System/machine/cpu_capabilities.h>
+#endif
 
 // bool save_xxm = (*((uint32_t*)_COMM_PAGE_CPU_CAPABILITIES) & kHasAVX1_0) != 0;
 
@@ -48,15 +51,30 @@
 #define XMM7_SAVE_RSP			0x70
 
 
+// Note: dyld cache builder finds __tlv_get_addr as _tlv_bootstrap+8
+    .globl          __tlv_bootstrap
+#if TARGET_OS_DRIVERKIT
+    .private_extern __tlv_bootstrap
+#endif
+__tlv_bootstrap:
+    jmp   __tlv_bootstrap_error
+    nop
+    nop
+    nop
+
 	// returns address of TLV in %rax, all other registers preserved
-	.globl _tlv_get_addr
-	.private_extern _tlv_get_addr
-_tlv_get_addr:
-	movq	8(%rdi),%rax			// get key from descriptor
+	.globl          __tlv_get_addr
+	.private_extern __tlv_get_addr
+    .alt_entry      __tlv_get_addr
+__tlv_get_addr:
+	movl	8(%rdi),%eax			// get 32-bit key from descriptor (TLV_Thunkv2.key)
 	movq	%gs:0x0(,%rax,8),%rax	// get thread value
 	testq	%rax,%rax				// if NULL, lazily allocate
 	je		LlazyAllocate
-	addq	16(%rdi),%rax			// add offset from descriptor
+    pushq   %rdi
+    movl    12(%rdi),%edi           // load 32-bit offset from descriptor (TLV_Thunkv2.offset)
+	addq	%rdi,%rax               // add offset to allocation base
+    popq    %rdi
 	ret
 LlazyAllocate:
 	pushq		%rbp
@@ -133,8 +151,7 @@
 
 Lalloc:
 	movq		RDI_SAVE_RBP(%rbp),%rdi
-	movq		8(%rdi),%rdi		        // get key from descriptor
-	call		_instantiateTLVs_thunk      // instantiateTLVs(key)
+    call        __ZN4dyld20ThreadLocalVariables19instantiateVariableERKNS0_5ThunkE  // ThreadLocalVariables::instantiateVariable(ThreadLocalVariables::Thunk&)
 
 	cmpl		$0, _hasXSave(%rip)
 	jne			Lxrstror
@@ -159,6 +176,8 @@
 
 Ldone:
 	movq		RDI_SAVE_RBP(%rbp),%rdi
+    movl        12(%rdi),%esi               // load 32-bit offset from descriptor (TLV_Thunkv2.offset)
+    addq        %rsi,%rax                   // add offset to allocation base
 	movq		RSI_SAVE_RBP(%rbp),%rsi
 	movq		RDX_SAVE_RBP(%rbp),%rdx
 	movq		RCX_SAVE_RBP(%rbp),%rcx
@@ -169,7 +188,6 @@
 	movq		R11_SAVE_RBP(%rbp),%r11
 	movq		%rbp,%rsp
 	popq		%rbp
- 	addq		16(%rdi),%rax			// result = buffer + offset
 	ret
 
 	.data
@@ -180,60 +198,33 @@
 _bufferSize32:		.long 0
 _hasXSave:			.long 0
 
-#endif
-
-
-
-#if __i386__
-	// returns address of TLV in %eax, all other registers (except %ecx) preserved
-	.globl _tlv_get_addr
-	.private_extern _tlv_get_addr
-_tlv_get_addr:
-	movl	4(%eax),%ecx			// get key from descriptor
-	movl	%gs:0x0(,%ecx,4),%ecx	// get thread value
-	testl	%ecx,%ecx				// if NULL, lazily allocate
-	je		LlazyAllocate
-	movl	8(%eax),%eax			// add offset from descriptor
-	addl	%ecx,%eax
-	ret
-LlazyAllocate:
-	pushl	%ebp
-	movl	%esp,%ebp
-	pushl	%edx					// save edx
-	subl	$548,%esp
-	movl	%eax,-8(%ebp)		    // save descriptor
-	lea		-528(%ebp),%ecx		    // get 512 byte buffer in frame
-	and		$-16, %ecx			    // 16-byte align buffer for fxsave
-	fxsave  (%ecx)
-	movl	-8(%ebp),%eax			// get descriptor
-	movl	4(%eax),%ecx			// get key from descriptor
-	movl	%ecx,(%esp)	            // push key parameter, also leaves stack aligned properly
-	call	_instantiateTLVs_thunk  // instantiateTLVs(key)
-	movl	-8(%ebp),%ecx			// get descriptor
-	movl	8(%ecx),%ecx			// get offset from descriptor
-	addl	%ecx,%eax				// add offset to buffer
-	lea 	-528(%ebp),%ecx
-	and 	$-16, %ecx              // 16-byte align buffer for fxrstor
-	fxrstor (%ecx)
-	addl	$548,%esp
-	popl	%edx	                // restore edx
-	popl	%ebp
-	ret
-#endif
+#endif // __x86_64__
 
 #if __arm64__
+
+    // Note: dyld cache builder finds __tlv_get_addr as _tlv_bootstrap+8
+    .globl          __tlv_bootstrap
+#if TARGET_OS_DRIVERKIT
+    .private_extern __tlv_bootstrap
+#endif
+__tlv_bootstrap:
+    b   __tlv_bootstrap_error
+    nop
+
 	// Parameters: X0 = descriptor
 	// Result:  X0 = address of TLV
 	// Note: all registers except X0, x16, and x17 are preserved
 	.align 2
-	.globl _tlv_get_addr
-	.private_extern _tlv_get_addr
-_tlv_get_addr:
+    .globl          __tlv_get_addr
+    .private_extern __tlv_get_addr
+    .alt_entry      __tlv_get_addr
+__tlv_get_addr:
 #if __LP64__
-	ldr		x16, [x0, #8]			// get key from descriptor
-#else
-	ldr		w16, [x0, #4]			// get key from descriptor
-#endif
+	ldr		w16, [x0, #8]			// get key from descriptor (TLV_Thunkv2.key)
+#else
+	ldrh    w16, [x0, #4]			// get key from descriptor (TLV_Thunkv2_32.key)
+#endif
+#if !TARGET_OS_EXCLAVEKIT
 	mrs		x17, TPIDRRO_EL0
 	and		x17, x17, #-8			// clear low 3 bits???
 #if __LP64__
@@ -243,12 +234,13 @@
 #endif
 	cbz		x17, LlazyAllocate		// if NULL, lazily allocate
 #if __LP64__
-	ldr		x16, [x0, #16]			// get offset from descriptor
-#else
-	ldr		w16, [x0, #8]			// get offset from descriptor
+	ldr		w16, [x0, #12]			// get offset from descriptor (TLV_Thunkv2.offset)
+#else
+	ldrh 	w16, [x0, #6]			// get offset from descriptor (TLV_Thunkv2_32.offset)
 #endif
 	add		x0, x17, x16			// return allocation+offset
 	ret		lr
+#endif // !TARGET_OS_EXCLAVEKIT
 
 LlazyAllocate:
 #if __has_feature(ptrauth_returns)
@@ -271,13 +263,12 @@
 	stp		q6,  q7,  [sp, #-32]!
 	stp		x0, x17,  [sp, #-16]!	// save descriptor
 
-	mov		x0, x16					// use key from descriptor as parameter
-	bl		_instantiateTLVs_thunk  // instantiateTLVs(key)
+	bl		__ZN4dyld20ThreadLocalVariables19instantiateVariableERKNS0_5ThunkE  // ThreadLocalVariables::instantiateVariable(ThreadLocalVariables::Thunk&)
 	ldp		x16, x17, [sp], #16		// pop descriptor
 #if __LP64__
-	ldr		x16, [x16, #16]			// get offset from descriptor
-#else
-	ldr		w16, [x16, #8]			// get offset from descriptor
+	ldr		w16, [x16, #12]			// get offset from descriptor (TLV_Thunkv2.offset)
+#else
+	ldrh	w16, [x16, #6]			// get offset from descriptor (TLV_Thunkv2_32.offset)
 #endif
 	add		x0, x0, x16				// return allocation+offset
 
@@ -302,53 +293,30 @@
 	ret
 #endif
 
-#endif
-
-#if __arm__
-	// returns address of TLV in r0, all other registers preserved
-	.align 2
-	.globl _tlv_get_addr
-	.private_extern _tlv_get_addr
-_tlv_get_addr:
-	push	{r1,r2,r3,r7,lr}
-#if __ARM_ARCH_7K__
-	sub		sp, sp, #12						// align stack to 16 bytes
-#endif
-	mov		r7, r0							// save descriptor in r7
-	ldr		r0, [r7, #4]					// get key from descriptor
-	bl		_pthread_getspecific			// get thread value
-	cmp		r0, #0
-	bne		L2								// if NULL, lazily allocate
-#if __ARM_ARCH_7K__
-	vpush	{d0, d1, d2, d3, d4, d5, d6, d7}
-#endif
-	ldr		r0, [r7, #4]					// get key from descriptor
- 	bl		_instantiateTLVs_thunk          // instantiateTLVs(key)
-#if __ARM_ARCH_7K__
-	vpop	{d0, d1, d2, d3, d4, d5, d6, d7}
-#endif
-L2:	ldr		r1, [r7, #8]					// get offset from descriptor
-	add		r0, r1, r0						// add offset into allocation block
-#if __ARM_ARCH_7K__
-	add		sp, sp, #12
-#endif
-	pop		{r1,r2,r3,r7,pc}
-
-
-#endif // __arm__
-
-
-
+#endif // __arm64__
+
+#if !TARGET_OS_EXCLAVEKIT
      // dyld_stub_binder is no longer used, but needed by old binaries to link
     .align 4
     .globl dyld_stub_binder
 dyld_stub_binder:
-#if __x86_64__ || __i386__
-    jmp __dyld_missing_symbol_abort
-#else
-    b   __dyld_missing_symbol_abort
-#endif
-
+#if __x86_64__
+    jmp _abort
+#else
+    b   _abort
+#endif
+#endif
+
+    // debug builds of libc++ headers generate calls to libcpp_verbose_abort()
+#if DEBUG
+    .private_extern __ZNSt3__122__libcpp_verbose_abortEPKcz
+__ZNSt3__122__libcpp_verbose_abortEPKcz:
+#if __x86_64__
+    jmp _abort_report_np
+#else
+    b   _abort_report_np
+#endif
+#endif // DEBUG
 
 
 	.subsections_via_symbols