Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Swift Stack Overflow

A Swift Stack Overflow

F34964538565e89f55b1df6e33c9a1e8?s=128

Michael Petrie

September 17, 2021
Tweet

Transcript

  1. @kapsy1312 "4XJGUTUBDLPWFSGMPX HJUIVCDPNLBQTZB@TXJGU@TUBDL@PWFS fl PX JPTEDKQ

  2. $POUFOUT w8IZUIFTUBDLJO4XJGU  w8IBUJTUIFTUBDL  w4UBDLVTBHFJO$ w"UPVSPGUIFTUBDLXJUIlldb w4UBDLVTBHFJO4XJGU w8IBUJTBTUBDLPWFS fl

    PX  w4XJGUTUBDLPWFS fl PXFYBNQMFT w1SFWFOUJOH4XJGUTUBDLPWFS fl PXT w"QQFOEJY
  3. 8IZUIFTUBDLJO4XJGU w.PUJWBUFECZPWFS fl PXTFYQFSJFODFEXJUI;0;0(-"44 w0WFS fl PXDPSSVQUJPOFSSPSTOPUPCWJPVTJONPTUDBTFT w0WFS fl PXTDBOEJTBQQFBSXJUIPQUJNJ[FEDPEF

    w4PNFUIJOHFWFSZQSPHSBNNFSTIPVMELOPXBCPVU w$BOFBTJMZPDDVSXIFOJOUFSGBDJOHXJUI$$ DPEF w4XJGUIJEFTNBOZEFUBJMT
  4. 8IBUJTUIFTUBDL w'VOEBNFOUBMQSPHSBNDPOTUSVDU w"VUPNBUJDBMMZNBOBHFE -*'0EBUBTUSVDUVSF w7JSUVBMNFNPSZ .BD04 TUBSUJOHBUIJHIBEESFTTFT w(SPXTUPXBSETMPXFSBEESFTTFT w7BMJEGPSGVODUJPOTDPQFPOMZ w.BOBHFECZDPNQJMFS

    VTBHFJT fi YFE w.VTUBEIFSFUP04"#* 4ZTUFN7".%GPS.BD04IUUQT FOXJLJQFEJBPSHXJLJ9@DBMMJOH@DPOWFOUJPOT Frame N 31 30 29 28 27 26 Free stack space 25 24 23 22 21 20 19 18 rbp 17 16 15 14 13 12 11 rsp 10 9 8 7 6 5 4 3 2 1 0 TUBSU BEESFTT FOE BEESFTT
  5. Frame N-1 31 30 29 28 27 26 Frame N-1

    rbp 25 Frame N 24 23 22 21 20 19 Free stack space 18 rbp 17 16 15 14 13 12 11 rsp 10 9 8 7 6 5 4 3 2 1 0 8IBUJTUIFTUBDL w'VOEBNFOUBMQSPHSBNDPOTUSVDU w"VUPNBUJDBMMZNBOBHFE -*'0EBUBTUSVDUVSF w7JSUVBMNFNPSZ .BD04 TUBSUJOHBUIJHIBEESFTTFT w(SPXTUPXBSETMPXFSBEESFTTFT w7BMJEGPSGVODUJPOTDPQFPOMZ w.BOBHFECZDPNQJMFS VTBHFJT fi YFE w.VTUBEIFSFUP04"#* 4ZTUFN7".%GPS.BD04IUUQT FOXJLJQFEJBPSHXJLJ9@DBMMJOH@DPOWFOUJPOT TUBSU BEESFTT FOE BEESFTT
  6. Frame N-2 31 30 29 28 27 26 Frame N-2

    rbp 25 Frame N-1 24 23 22 21 20 19 Frame N-1 rbp 18 rbp Frame N 17 16 15 14 13 12 11 rsp Free stack space 10 9 8 7 6 5 4 3 2 1 0 8IBUJTUIFTUBDL w'VOEBNFOUBMQSPHSBNDPOTUSVDU w"VUPNBUJDBMMZNBOBHFE -*'0EBUBTUSVDUVSF w7JSUVBMNFNPSZ .BD04 TUBSUJOHBUIJHIBEESFTTFT w(SPXTUPXBSETMPXFSBEESFTTFT w7BMJEGPSGVODUJPOTDPQFPOMZ w.BOBHFECZDPNQJMFS VTBHFJT fi YFE w.VTUBEIFSFUP04"#* 4ZTUFN7".%GPS.BD04IUUQT FOXJLJQFEJBPSHXJLJ9@DBMMJOH@DPOWFOUJPOT TUBSU BEESFTT FOE BEESFTT
  7. 4UBDLVTBHFJO$ $ #include <stdio.h > int main (int argc, char

    **argv ) { int a = 3 ; int cubed = a*a*a ; printf ("cubed:%d\n", cubed) ; return (0) ; } YBTN .section __TEXT,__text,regular,pure_instruction s .intel_syntax noprefi x .globl _mai n .p2align 4, 0x9 0 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n" clang -S -mllvm --x86-asm-syntax=intel stack1.cc -o stack1.s
  8. "UPVSPGUIFTUBDLXJUIlldb BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700

    7FFEEFBFF6FC 7FFEEFBFF6F8 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF6EC 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n" (lldb) reg read rb p rbp = 0x00007ffeefbff71 8 (lldb) reg read rs p rsp = 0x00007ffeefbff70 8 SCQ STQ 7FFEEFBFF718 7FFEEFBFF708 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738
  9. "UPVSPGUIFTUBDLXJUIlldb _main : push rb p mov rbp, rs p

    sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n" (lldb) thread step-ove r (lldb) reg read rs p rsp = 0x00007ffeefbff70 0 (lldb) mem read -fp -c1 -- 0x00007ffeefbff70 0 0x7ffeefbff700: 0x00007ffeefbff718 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 7FFEEFBFF6F8 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF6EC 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF718 7FFEEFBFF700 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738
  10. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read rb p

    rbp = 0x00007ffeefbff700 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 7FFEEFBFF6F8 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF6EC 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF700 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  11. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read rs p

    rsp = 0x00007ffeefbff6e0 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 7FFEEFBFF6F8 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF6EC 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  12. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) mem read -fy -c4

    -- 0x00007ffeefbff6f c 0x7ffeefbff6fc: 00 00 00 00 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF6EC 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  13. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) mem read -fy -c4

    -- 0x00007ffeefbff6f 8 0x7ffeefbff6f8: 01 00 00 00 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF6EC 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  14. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) mem read -fp -c1

    -- 0x00007ffeefbff6f 0 0x7ffeefbff6f0: 0x00007ffeefbff728 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  15. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) mem read -fy -c4

    -- 0x00007ffeefbff6e c 0x7ffeefbff6ec: 03 00 00 00 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  16. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read ea x

    eax = 0x00000003 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 3 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  17. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read ea x

    eax = 0x00000009 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 9 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  18. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read ea x

    eax = 0x0000001 b (lldb) expr -fd -- 0x0000001 b (int) $0 = 27 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1B 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  19. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) mem read -fy -c4

    -- 0x00007ffeefbff6e 8 0x7ffeefbff6e8: 1b 00 00 00 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1B 1 7FFEEFBFF728 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  20. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read es i

    esi = 0x0000001b BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1B 1 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  21. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r 0x100003f6e <+46>: lea rdi, [rip

    + 0x35 ] (lldb) reg read ri p rip = 0x0000000100003f7 5 (lldb) expr -fx -- 0x0000000100003f75 + 0x3 5 (long) $3 = 0x0000000100003fa a (lldb) reg read rd i rdi = 0x0000000100003faa "cubed:%d\n" BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1B 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  22. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-over BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C

    7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 1B 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  23. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) re re rs p

    rsp = 0x00007ffeefbff6e0 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 9 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  24. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read ec x

    ecx = 0x0000000 0 (lldb) reg read ea x eax = 0x00000009 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 9 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  25. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) mem read -fy -c4

    -- 0x00007ffeefbff6e 4 0x7ffeefbff6e4: 09 00 00 00 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 9 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 9 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  26. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read ea x

    eax = 0x00000000 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 9 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF6E0 FBYSBY FEJSEJ FTJSTJ FEYSEY 0 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  27. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read rs p

    rsp = 0x00007ffeefbff700 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 9 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF700 7FFEEFBFF700 FBYSBY FEJSEJ FTJSTJ FEYSEY 0 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  28. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) reg read rb p

    rbp = 0x00007ffeefbff71 8 (lldb) reg read rs p rsp = 0x00007ffeefbff708 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 9 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF718 7FFEEFBFF708 FBYSBY FEJSEJ FTJSTJ FEYSEY 0 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  29. "UPVSPGUIFTUBDLXJUIlldb (lldb) thread step-ove r (lldb) thread backtrac e *

    thread #1, queue = 'com.apple.main-thread', stop reason = instruction step ove r * frame #0: 0x00007fff203a1621 libdyld.dylib`star t + 1 BEESFTT NFNPSZ 7FFEEFBFF718 7FFEEFBFF714 7FFEEFBFF710 7FFEEFBFF70C 7FFEEFBFF708 7FFEEFBFF704 7FFEEFBFF700 7FFEEFBFF718 7FFEEFBFF6FC 0 7FFEEFBFF6F8 1 7FFEEFBFF6F4 7FFEEFBFF6F0 7FFEEFBFF728 7FFEEFBFF6EC 3 7FFEEFBFF6E8 1B 7FFEEFBFF6E4 9 7FFEEFBFF6E0 7FFEEFBFF6DC 7FFEEFBFF6D8 SCQ STQ 7FFEEFBFF718 7FFEEFBFF708 FBYSBY FEJSEJ FTJSTJ FEYSEY 0 100003FAA 1B 7FFEEFBFF738 _main : push rb p mov rbp, rs p sub rsp, 3 2 mov dword ptr [rbp - 4], 0 mov dword ptr [rbp - 8], ed i mov qword ptr [rbp - 16], rs i mov dword ptr [rbp - 20], 3 mov eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] imul eax, dword ptr [rbp - 20 ] mov dword ptr [rbp - 24], ea x mov esi, dword ptr [rbp - 24 ] lea rdi, [rip + L_.str ] mov al, 0 call _print f xor ecx, ec x mov dword ptr [rbp - 28], ea x mov eax, ec x add rsp, 3 2 pop rb p re t L_.str : .asciz "cubed:%d\n"
  30. 4UBDLVTBHFJO4XJGU 4XJGU let a = 3 let cubed = a*a*

    a print("cubed:\(cubed)") swiftc -g -o stack2.s -emit-assembly -Xllvm --x86-asm-syntax=intel -S stack2.swift YBTN _main : Lfunc_begin0 : push rb p mov rbp, rs p push r1 3 sub rsp, 152 xor eax, ea x lea rcx, [rbp - 24 ] Ltmp0 : mov dword ptr [rbp - 36], ed i mov rdi, rc d mov qword ptr [rbp - 48], rs i mov esi, ea x mov edx, 1 6 call _memse t Ltmp1 : mov qword ptr [rip + _$s5stack1aSivp], 3 Ltmp2 : mov rcx, qword ptr [rip + _$s5stack1aSivp ] imul rcx, qword ptr [rip + _$s5stack1aSivp ] seto r8 b test r8b, 1 mov qword ptr [rbp - 56], rc x jne LBB0_3 jne LBB0_ 4 ~1200 loc
  31. 4UBDLVTBHFJO4XJGU w 4XJGUDPODBUFOBUFTTUSJOHTCFGPSFQBTTJOHUPQSJOU lea r13, [rbp - 24 ] mov

    qword ptr [rbp - 88], rd x call _$ss26DefaultStringInterpolationV13appendLiteralyySS F w 4XJGUBEETNBOZTBGFUZDIFDLT PWFS fl PX GPSFYBNQMF  imul rax, qword ptr [rip + _$s6stack21aSivp ] seto c l test cl, 1 mov qword ptr [rbp - 64], ra x jne LBB0_ 4 w .BOZPCKFDUSFGFSFODFTTUPSFE NBOBHFEPOTUBDL mov rdi, qword ptr [rbp - 160 ] call _swift_bridgeObjectReleas e mov rdi, qword ptr [rbp - 152 ] call _swift_bridgeObjectReleas e w 0QUJNJ[BUJPO -OSFEVDFTVTBHFUP# $WFSTJPOXJUI-OfastSFEVDFTVTBHFUP# w 4FFHJUIVCDPNLBQTZB@TXJGU@TUBDL@PWFS fl PXCMPCNBJODPEFTUBDLTGPSNPSF
  32. 8IBUJTBTUBDLPWFSGMPX w$BVTFECZPVUPGCPVOETTUBDLBMMPDBUJPOBDDFTT w"MMPDBUJPOJTWJSUVBMNFNPSZ NBOBHFECZ04 w(FOFSBMMZNBOJGFTUBTEXC_BAD_ACCESS w/PTQFDJ fi DPWFS fl PXFSSPSTJO4XJGU

    w$BOEJTBQQFBSXJUI-OPQUJNJ[BUJPOT wswiftcEPFTOPUBEE____chkstk_darwinHVBSET w0DDVSXJUISFDVSTJPOPSMBSHFTUSVDUUVQMFEFDMBSBUJPOT Frame N-2 31 30 29 28 27 26 Frame N-2 rbp 25 Frame N-1 24 23 22 21 20 19 Frame N-1 rbp 18 rbp Frame N 17 16 15 14 13 12 11 rsp Free stack space 10 9 8 7 6 5 4 3 2 1 0 UISFBE TUBDL BMMPDBUJPO
  33. "4XJGUTUBDLPWFSGMPX 4XJGU func rec2(_ x: Int) -> Int { return

    rec2(x + 1 ) } let x = rec2(0) YBTN _$s8stack_024rec2yS2iF : Lfunc_begin1 : push rb p mov rbp, rs p sub rsp, 32 xor esi, es i lea rax, [rbp - 8 ] Ltmp2 : mov qword ptr [rbp - 16], rd i mov rdi, ra x mov edx, 8 call _memse t Ltmp3 : mov rax, qword ptr [rbp - 16 ] Ltmp4 : mov qword ptr [rbp - 8], ra x Ltmp5 : inc ra x seto c l test cl, 1 mov qword ptr [rbp - 24], ra x jne LBB1_ 2 mov rdi, qword ptr [rbp - 24 ] call _$s8stack_024rec2yS2i F add rsp, 3 2 pop rb p ret
  34. "4XJGUTUBDLPWFSGMPX *GXFSVOBTNPVUQVUJOMMECJUDSBTIFTXJUI * thread #1, queue = 'com.apple.main-thread', stop reason

    = EXC_BAD_ACCESS (code=2, address=0x7ffeef3ffff0 ) frame #0: 0x0000000100003f4e stack_02`stack_02.rec2(Swift.Int) -> Swift.Int + 1 4 stack_02`stack_02.rec2(Swift.Int) -> Swift.Int : -> 0x100003f4e <+14>: mov qword ptr [rbp - 0x10], rd i 0x100003f52 <+18>: mov rdi, ra x 0x100003f55 <+21>: mov edx, 0x 8 0x100003f5a <+26>: call 0x100003f8 8 8FTVCUSBDUUIFDVSSFOUrbpGSPNUIFJOJUJBMrbpUP fi OEUIFVTFETUBDLTJ[F (lldb) expr -- (0x00007ffeefbff718 - 0x00007ffeef400000 ) (long) $0 = 838632 8 5IJTJTWFSZDMPTFUPPVSTUBDLMJNJUPG8388608B 8FBTTVNFUIFJOJUJBMrbpXBTO`UUIFFYBDUTUBSU BOEUIBUSVOUJNF JOGPSNBUJPOJTTUPSFECFGPSFUIBU 4XJGU func rec2(_ x: Int) -> Int { return rec2(x + 1 ) } let x = rec2(0)
  35. ~2200 loc "4XJGUTUBDLPWFSGMPX 4XJGU var bytes = Int(0 ) func

    rec() { // 32 byte s let a : ( Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int8 , Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int8 , Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int8 , Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int 8 ) = ( 0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0, 0 ) bytes += 32 + Int(a.0 ) print ("tuple bytes on stack:\(bytes)" ) if (bytes < (1 << 20)*8) { rec( ) } } rec() YBTN _$s15stack_02_tuples3recyyF : Lfunc_begin1 : push rb p mov rbp, rs p push r1 3 sub rsp, 60 0 xor eax, ea x lea rcx, [rbp - 40 ] Ltmp3 : mov rdi, rc x mov esi, ea x mov edx, 3 2 mov dword ptr [rbp - 236], ea x call _memse t Ltmp4 : lea rcx, [rbp - 96 ] Ltmp5 : mov rdi, rc x mov esi, dword ptr [rbp - 236 ] mov edx, 1 6 call _memse t Ltmp6 : .loc 1 0 0 prologue_en d mov byte ptr [rbp - 40], 0 mov byte ptr [rbp - 39], 0 mov byte ptr [rbp - 38], 0 mov byte ptr [rbp - 37], 0 mov byte ptr [rbp - 36], 0 mov byte ptr [rbp - 35], 0
  36. "4XJGUTUBDLPWFSGMPX 3VOOJOHHJWFTVT PVUQVUUSVODBUFE  tuple bytes on stack:42953 6 tuple

    bytes on stack:42956 8 tuple bytes on stack:42960 0 tuple bytes on stack:42963 2 tuple bytes on stack:42966 4 tuple bytes on stack:42969 6 tuple bytes on stack:42972 8 tuple bytes on stack:42976 0 tuple bytes on stack:42979 2 tuple bytes on stack:42982 4 tuple bytes on stack:42985 6 tuple bytes on stack:42988 8 tuple bytes on stack:42992 0 tuple bytes on stack:42995 2 tuple bytes on stack:42998 4 zsh: segmentation fault build/stack_02_tuple s 8FEPO`UDPNFBOZXIFSFOFBSPVS.J#MJNJU CFDBVTF4XJGUJT SFTFSWJOHNVDINPSFUIBO#QFSGVODUJPODBMM 4XJGU var bytes = Int(0 ) func rec() { // 32 byte s let a : ( Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int8 , Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int8 , Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int8 , Int8,Int8,Int8,Int8,Int8,Int8,Int8,Int 8 ) = ( 0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0, 0 ) bytes += 32 + Int(a.0 ) print ("tuple bytes on stack:\(bytes)" ) if (bytes < (1 << 20)*8) { rec( ) } } rec()
  37. 4XJGU func myFunc () { var a = large_struct_t( )

    withUnsafeBytes(of: &a.models) { modelPointer i n // Read model data here. } } class LargeStructWrapper { var cStruct = large_struct_t( ) } func myFunc () { let a = LargeStructWrapper() withUnsafeBytes(of: &a.cStruct.models) { modelPointer i n // Read model data here. } } 1SFWFOUJOH4XJGUTUBDLPWFSGMPXT w8SBQMBSHF$TUSVDUTXJUI fi YFETJ[FEBSSBZTJOUP4XJGUPCKFDUT $ #define DATA_COUNT 12 8 #define MODEL_COUNT 12 8 struct model_ t { float data[DATA_COUNT] ; } ; struct large_struct_ t { struct model_t models[MODEL_COUNT] ; };
  38. 1SFWFOUJOH4XJGUTUBDLPWFSGMPXT w3FDVSTJPOTIPVME BOEDBOBMXBZT CFSFQMBDFEXJUIXIJMFMPPQT 4XJGU func rec(_ x: Int) ->

    Int { if(x < (1 << 20)*8) { return rec(x + 1 ) } else { return x } } let x = rec(0 ) print(x ) 0OSVO Thread 1: EXC_BAD_ACCESS 4XJGU var x = 0 while(x < (1 << 20)*8) { x+= 1 } print(x ) 0OSVO 838860 8 Program ended with exit code: 0
  39. 1SFWFOUJOH4XJGUTUBDLPWFSGMPXT w/FWFSVTFBQPJOUFSUPTUBDLNFNPSZPVUTJEFGVODUJPOTDPQF 4XJGUNBLFTUIJTEJ ff i DVMU  w6TFThread.stackSizeUPDIFDLDIBOHFBWBJMBCMFTUBDLTQBDF w)PXFWFS UIFSFTIPVMECFOPSFBTPOUPJODSFBTFBMMPUUFETUBDLTJ[F

    w*GQPTTJCMF EPO`UVTF fi YFE$TUSVDUBSSBZT 4XJGUUVQMFTJ[FMJNJU MPOHDPNQJMFUJNFT  w8PSUIMFBSOJOHBTNUPVOEFSTUBOEVTBHFQBUUFSOT
  40. "QQFOEJY

  41. )PNFXPSL w5SZEFCVHHJOHUIFTUBDLGPSZPVSTFMGŠUIFCFTUXBZUPMFBSO w$MPOFQSPKFDU HJUIVCDPNLBQTZB@TXJGU@TUBDL@PWFS fl PX w3VObuild(n).sh CBUDI fi MFTUPDSFBUFBTNGPSFBDIFYBNQMF

    w3VOlldb -s run(n).sUPEFCVH w5SZlldbDPNNBOETJO"UPVSPGUIFTUBDLXJUIlldbTMJEFT
  42. 4UBDLBOEIFBQDPNQBSJTPO TUBDL IFBQ 6QUPBGFX.J# -JNJUFECZBWBJMBCMFTZTUFNNFNPSZ 7JSUVBMNFNPSZ IJHIBEESFTTFT 7JSUVBMNFNPSZ MPXBEESFTTFT 1FSUISFBE

    GVODUJPOTDPQF (MPCBM BOZXIFSF 4DBMBST TUSVDUT BSSBZT $ /FXPCKFDUT BSSBZT 4XJGU NBMMPD 'BTUFSBDDFTT JO$16DBDIF 4MPXFSBDDFTT "TTJHOFECZDPNQJMFS  fi YFE "MMPDBUFECZQSPHSBN EZOBNJD 'SBHNFOUBUJPOOPUQPTTJCMF 'SBHNFOUTXJUISFQFBUFEVTBHF
  43. YBTNQSJNFS wrbp rspCJUDQVSFHJTUFST DVSSFOUGSBNFTUBDLCBTFBOEFOEQPJOUFS wqwordEBUBXJUIBMFOHUIPG CJUT wpush aTVCUSBDUTqwordGSPNrsp,DPQZDQVSFHJTUFSaPOUPTUBDL wpop aDPQZqwordGSPNTUBDLUPDQVSFHJTUFSa

    BEETqwordUPrsp wmov a bDPQZDQVSFHJTUFSPSQPJOUFSaUPb wsub a bTVCUSBDUbGSPNa TUPSFSFTVMUJOa wcall aDBMMGVODUJPO TVCUSBDUTqwordGSPNrsp TUBSUJOHBOFXTUBDLGSBNF wretBEETqwordUPrsp SFUVSOJOHUPQSFWJPVTTUBDLGSBNF
  44. %FCVHHJOHUIFTUBDL wYBTNVTFEGPSUIJTQSFTFOUBUJPO wlldbQSPWJEFTNBOZVTFGVMDPNNBOET wreg read rsp SFBE341$16SFHJTUFS wmem read -fy

    -c4 -- 0x00007ffeefbff6e8 SFBE#GSPNNFNPSZBEESFTT wexpr -fx -- 0x0000000100003f75 + 0x35 QBSTFFYQSFTTJPOJOIFY w.VTUSFBEBTNUPSFBMMZVOEFSTUBOEXIBU`TIBQQFOJOH
  45. 8IBUBCPVU"3.BTN w.PSFSFMFWBOUUPJ04EFWFMPQNFOU w&WFONPSFTPXJUI"QQMF"3..TFSJFTQSPDFTTPST w%J ffi DVMUUPEFCVHPOEFWJDF J04BQQMJDBUJPO NPSFJOTUSVDUJPOOPJTF  w1PTTJCMFUIBUDPNQJMFEJOTUSVDUJPO

    fl PXEJ ff FSTUPY w4IPVMECFTJNQMFXJUIBO.FRVJQQFE.BD w8PSUIMFBSOJOH
  46. 4UBDLMJNJUTJO.BD04 me@mycomp stack % ulimit - a -t: cpu time

    (seconds) unlimite d -f: file size (blocks) unlimite d -d: data seg size (kbytes) unlimite d -s: stack size (kbytes) 819 2 -c: core file size (blocks) 0 -v: address space (kbytes) unlimite d -l: locked-in-memory size (kbytes) unlimite d -u: processes 1113 6 -n: file descriptors 4864 8192KiB = 8192*(1 << 10)B = 8MiB IUUQTEFWFMPQFSBQQMFDPNMJCSBSZBSDIJWFEPDVNFOUBUJPO$PDPB $PODFQUVBM.VMUJUISFBEJOH$SFBUJOH5ISFBET$SFBUJOH5ISFBETIUNM
  47. 4UBDLMJNJUTJOJ04 w1MiB NBJOUISFBE  w512KiB TFDPOEBSZUISFBET  w6TFThread.stackSizePSNSThread.stackSizeUPDIFDLDIBOHFTJ[F w4J[FNVTUCFDIBOHFECFGPSFTUBSUJOHUISFBE wIUUQTEFWFMPQFSBQQMFDPNMJCSBSZBSDIJWFEPDVNFOUBUJPO$PDPB$PODFQUVBM.VMUJUISFBEJOH

    $SFBUJOH5ISFBET$SFBUJOH5ISFBETIUNM
  48. 4BNQMFDPEF MJOLT w IUUQTHJUIVCDPNLBQTZB@TXJGU@TUBDL@PWFS fl PX w IUUQTFOXJLJQFEJBPSHXJLJ$BMM@TUBDL w IUUQTFOXJLJQFEJBPSHXJLJ9@DBMMJOH@DPOWFOUJPOT

    w IUUQTXXXJOUFMDPNDPOUFOUEBNXXXQVCMJDVTFOEPDVNFOUTNBOVBMTJB BSDIJUFDUVSFTTPGUXBSFEFWFMPQFSJOTUSVDUJPOTFUSFGFSFODFNBOVBMQEG w IUUQTHJUIVCDPNBQQMFTXJGU w IUUQTTUBDLPWFS fl PXDPNRVFTUJPOTIPXUPSFNPWFOPJTFGSPNHDDDMBOH BTTFNCMZPVUQVU w IUUQTGPSVNTTXJGUPSHUJODSFBTFTJ[FPGTUBDL
  49. None