.globl __dyld_start
-#ifdef __i386__
-
-#if !TARGET_IPHONE_SIMULATOR
+#if __i386__ && !TARGET_OS_SIMULATOR
.text
.align 4, 0x90
.globl __dyld_start
L__dyld_start_picbase:
popl %ebx # set %ebx to runtime value of picbase
- movl Lmh-L__dyld_start_picbase(%ebx), %ecx # ecx = prefered load address
- movl __dyld_start_static_picbase-L__dyld_start_picbase(%ebx), %eax
- subl %eax, %ebx # ebx = slide = L__dyld_start_picbase - [__dyld_start_static_picbase]
- addl %ebx, %ecx # ecx = actual load address
- # call dyldbootstrap::start(app_mh, argc, argv, slide, dyld_mh, &startGlue)
+ # call dyldbootstrap::start(app_mh, argc, argv, dyld_mh, &startGlue)
+ subl $L__dyld_start_picbase-__dyld_start, %ebx # ebx = &__dyld_start
+ subl $0x1000, %ebx # ebx = load address of dyld
movl %edx,(%esp) # param1 = app_mh
movl 4(%ebp),%eax
movl %eax,4(%esp) # param2 = argc
lea 8(%ebp),%eax
movl %eax,8(%esp) # param3 = argv
- movl %ebx,12(%esp) # param4 = slide
- movl %ecx,16(%esp) # param5 = actual load address
+ movl %ebx,12(%esp) # param4 = dyld load address
lea 28(%esp),%eax
- movl %eax,20(%esp) # param6 = &startGlue
- call __ZN13dyldbootstrap5startEPK12macho_headeriPPKclS2_Pm
+ movl %eax,16(%esp) # param5 = &startGlue
+ call __ZN13dyldbootstrap5startEPKN5dyld311MachOLoadedEiPPKcS3_Pm
movl 28(%esp),%edx
cmpl $0,%edx
jne Lnew
movl %ebx,12(%esp) # main param4 = apple
pushl %edx # simulate return address into _start in libdyld
jmp *%eax # jump to main(argc,argv,env,apple) with return address set to _start
-#endif
-
-#if !TARGET_IPHONE_SIMULATOR
- .data
-__dyld_start_static_picbase:
- .long L__dyld_start_picbase
-Lmh: .long ___dso_handle
-#endif
-
-
-#endif /* __i386__ */
-
+#endif /* __i386__ && !TARGET_OS_SIMULATOR*/
-#if __x86_64__
-#if !TARGET_IPHONE_SIMULATOR
- .data
- .align 3
-__dyld_start_static:
- .quad __dyld_start
-#endif
-#if !TARGET_IPHONE_SIMULATOR
+#if __x86_64__ && !TARGET_OS_SIMULATOR
.text
.align 2,0x90
.globl __dyld_start
andq $-16,%rsp # force SSE alignment
subq $16,%rsp # room for local variables
- # call dyldbootstrap::start(app_mh, argc, argv, slide, dyld_mh, &startGlue)
+ # call dyldbootstrap::start(app_mh, argc, argv, dyld_mh, &startGlue)
movl 8(%rbp),%esi # param2 = argc into %esi
leaq 16(%rbp),%rdx # param3 = &argv[0] into %rdx
- movq __dyld_start_static(%rip), %r8
- leaq __dyld_start(%rip), %rcx
- subq %r8, %rcx # param4 = slide into %rcx
- leaq ___dso_handle(%rip),%r8 # param5 = dyldsMachHeader
- leaq -8(%rbp),%r9
- call __ZN13dyldbootstrap5startEPK12macho_headeriPPKclS2_Pm
+ leaq ___dso_handle(%rip),%rcx # param4 = dyldsMachHeader into %rcx
+ leaq -8(%rbp),%r8 # param5 = &glue into %r8
+ call __ZN13dyldbootstrap5startEPKN5dyld311MachOLoadedEiPPKcS3_Pm
movq -8(%rbp),%rdi
cmpq $0,%rdi
jne Lnew
testq %r8,%r8 # look for NULL ending env[] array
jne Lapple # main param4 = apple into %rcx
jmp *%rax # jump to main(argc,argv,env,apple) with return address set to _start
-
-#endif /* TARGET_IPHONE_SIMULATOR */
-#endif /* __x86_64__ */
+#endif /* __x86_64__ && !TARGET_OS_SIMULATOR*/
#if __arm__
- .syntax unified
- .data
- .align 2
-__dyld_start_static_picbase:
- .long L__dyld_start_picbase
-
-
- // Hack to make ___dso_handle work
- // Without this local symbol, assembler will error out about in subtraction expression
- // The real ___dso_handle (non-weak) sythesized by the linker
- // Since this one is weak, the linker will throw this one away and use the real one instead.
- .data
- .globl ___dso_handle
- .weak_definition ___dso_handle
-___dso_handle: .long 0
-
.text
.align 2
__dyld_start:
sub sp, #16 // make room for outgoing parameters
bic sp, sp, #15 // force 16-byte alignment
- // call dyldbootstrap::start(app_mh, argc, argv, slide, dyld_mh, &startGlue)
-
- ldr r3, L__dyld_start_picbase_ptr
-L__dyld_start_picbase:
- sub r0, pc, #8 // load actual PC
- ldr r3, [r0, r3] // load expected PC
- sub r3, r0, r3 // r3 = slide
-
+ // call dyldbootstrap::start(app_mh, argc, argv, dyld_mh, &startGlue)
ldr r0, [r8] // r0 = mach_header
ldr r1, [r8, #4] // r1 = argc
add r2, r8, #8 // r2 = argv
-
- ldr r4, Lmh
-L3: add r4, r4, pc
- str r4, [sp, #0] // [sp] = dyld_mh
+ adr r3, __dyld_start
+ sub r3 ,r3, #0x1000 // r3 = dyld_mh
add r4, sp, #12
- str r4, [sp, #4] // [sp+4] = &startGlue
+ str r4, [sp, #0] // [sp] = &startGlue
- bl __ZN13dyldbootstrap5startEPK12macho_headeriPPKclS2_Pm
+ bl __ZN13dyldbootstrap5startEPKN5dyld311MachOLoadedEiPPKcS3_Pm
ldr r5, [sp, #12]
cmp r5, #0
bne Lnew
bne Lapple // main param4 = apple
bx r5
- .align 2
-L__dyld_start_picbase_ptr:
- .long __dyld_start_static_picbase-L__dyld_start_picbase
-Lmh: .long ___dso_handle-L3-8
-
#endif /* __arm__ */
-#if __arm64__
- .data
- .align 3
-__dso_static:
- .quad ___dso_handle
-
+#if __arm64__ && !TARGET_OS_SIMULATOR
.text
.align 2
.globl __dyld_start
ldr w1, [x28, #4] // get argc into x1 (kernel passes 32-bit int argc as 64-bits on stack to keep alignment)
add w2, w28, #8 // get argv into x2
#endif
- adrp x4,___dso_handle@page
- add x4,x4,___dso_handle@pageoff // get dyld's mh in to x4
- adrp x3,__dso_static@page
- ldr x3,[x3,__dso_static@pageoff] // get unslid start of dyld
- sub x3,x4,x3 // x3 now has slide of dyld
- mov x5,sp // x5 has &startGlue
-
- // call dyldbootstrap::start(app_mh, argc, argv, slide, dyld_mh, &startGlue)
- bl __ZN13dyldbootstrap5startEPK12macho_headeriPPKclS2_Pm
+ adrp x3,___dso_handle@page
+ add x3,x3,___dso_handle@pageoff // get dyld's mh in to x4
+ mov x4,sp // x5 has &startGlue
+
+ // call dyldbootstrap::start(app_mh, argc, argv, dyld_mh, &startGlue)
+ bl __ZN13dyldbootstrap5startEPKN5dyld311MachOLoadedEiPPKcS3_Pm
mov x16,x0 // save entry point address in x16
#if __LP64__
ldr x1, [sp]
br x16
#endif
-#endif // __arm64__
+#endif // __arm64__ && !TARGET_OS_SIMULATOR
// When iOS 10.0 simulator runs on 10.11, abort_with_payload() does not exist,
// so it falls back and uses dyld_fatal_error().
-#if TARGET_IPHONE_SIMULATOR
+#if TARGET_OS_SIMULATOR
.text
.align 2
.globl _dyld_fatal_error
_dyld_fatal_error:
+#if __arm64__ || __arm64e__
+ brk #3
+#else
int3
+#endif
nop
#endif
-
-
-
-