Skip to content

Instantly share code, notes, and snippets.

@eyepaq
Created July 22, 2021 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyepaq/b2e94ecb09b8d39df72c11d2fa7d3527 to your computer and use it in GitHub Desktop.
Save eyepaq/b2e94ecb09b8d39df72c11d2fa7d3527 to your computer and use it in GitHub Desktop.
async call disassembly in Swift
class TestClassSync {
func calc() -> Int {
return 100
}
func run() -> Int {
return 100 + calc()
}
}
// Intel disassembly
AsyncApp`TestClassSync.run():
0x10f19e330 <+0>: pushq %rbp
0x10f19e331 <+1>: movq %rsp, %rbp
0x10f19e334 <+4>: subq $0x10, %rsp
0x10f19e338 <+8>: xorl %esi, %esi
0x10f19e33a <+10>: leaq -0x8(%rbp), %rdi
0x10f19e33e <+14>: movl $0x8, %edx
0x10f19e343 <+19>: callq 0x10f19f826 ; symbol stub for: memset
0x10f19e348 <+24>: movq %r13, -0x8(%rbp)
-> 0x10f19e34c <+28>: movq (%r13), %rax
0x10f19e350 <+32>: callq *0x50(%rax)
0x10f19e353 <+35>: addq $0x64, %rax
0x10f19e357 <+39>: movq %rax, -0x10(%rbp)
0x10f19e35b <+43>: seto %al
0x10f19e35e <+46>: testb $0x1, %al
0x10f19e360 <+48>: jne 0x10f19e36c ; <+60> [inlined] Swift runtime failure: arithmetic overflow at AsyncAppApp.swift:28:20
0x10f19e362 <+50>: movq -0x10(%rbp), %rax
0x10f19e366 <+54>: addq $0x10, %rsp
0x10f19e36a <+58>: popq %rbp
0x10f19e36b <+59>: retq
0x10f19e36c <+60>: ud2
class TestClassAsync {
func calc() async -> Int {
return 100
}
func run() async -> Int {
return 100 + (await calc())
}
}
// Intel disassembly
AsyncApp`TestClassAsync.run():
0x10f19e140 <+0>: btsq $0x3c, %rbp
0x10f19e145 <+5>: pushq %rbp
0x10f19e146 <+6>: pushq %r14
0x10f19e148 <+8>: leaq 0x8(%rsp), %rbp
0x10f19e14d <+13>: subq $0x28, %rsp
0x10f19e151 <+17>: movq %r14, -0x18(%rbp)
0x10f19e155 <+21>: xorl %eax, %eax
0x10f19e157 <+23>: movl %eax, %edi
0x10f19e159 <+25>: callq 0x10f19f330 ; ___lldb_unnamed_symbol12$$AsyncApp
0x10f19e15e <+30>: movq -0x18(%rbp), %rax
0x10f19e162 <+34>: movq %rax, %r14
0x10f19e165 <+37>: addq $0x20, %r14
0x10f19e169 <+41>: movq $0x0, 0x20(%rax)
0x10f19e171 <+49>: movq %rax, 0x18(%rax)
0x10f19e175 <+53>: movq %r13, 0x20(%rax)
-> 0x10f19e179 <+57>: movq (%r13), %rax
0x10f19e17d <+61>: movq 0x50(%rax), %rax
0x10f19e181 <+65>: movslq (%rax), %rdx
0x10f19e184 <+68>: movq %rax, %rcx
0x10f19e187 <+71>: addq %rdx, %rcx
0x10f19e18a <+74>: movq %rcx, -0x10(%rbp)
0x10f19e18e <+78>: movl 0x4(%rax), %eax
0x10f19e191 <+81>: movl %eax, %edi
0x10f19e193 <+83>: callq 0x10f19f8da ; symbol stub for: swift_task_alloc
0x10f19e198 <+88>: movq -0x18(%rbp), %rcx
0x10f19e19c <+92>: movq %rax, %r14
0x10f19e19f <+95>: movq -0x10(%rbp), %rax
0x10f19e1a3 <+99>: movq %r14, 0x28(%rcx)
0x10f19e1a7 <+103>: movq 0x18(%rcx), %rcx
0x10f19e1ab <+107>: movq %rcx, (%r14)
0x10f19e1ae <+110>: leaq 0x1b(%rip), %rcx ; (1) await resume partial function for AsyncApp.TestClassAsync.run() async -> Swift.Int at AsyncAppApp.swift:17
0x10f19e1b5 <+117>: movq %rcx, 0x8(%r14)
0x10f19e1b9 <+121>: addq $0x20, %rsp
0x10f19e1bd <+125>: addq $0x10, %rsp
0x10f19e1c1 <+129>: popq %rbp
0x10f19e1c2 <+130>: btrq $0x3c, %rbp
0x10f19e1c7 <+135>: jmpq *%rax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment