1 at the call moment 1 hello.c lines 3 to 10 of 11 3 4 int main ( void ) { 5 char buf [ 32 ] ; 6 int f = open ( "note" , 0 ) ; 7 int n = read ( f , buf , 32 ) ; 8 close ( f ) ; 9 write ( 1 , buf , n ) ; 10 return 0 ; disassembly main 4011 7a 4 sub rsp, 0x40 4011 7e mov rax, fs:[0x28] the stack's canary 4011 87 mov [rbp - 8], rax 4011 8b xor eax, eax 4011 8d 6 lea rax, [rip + 0xe70] = 402004 "note" 4011 94 mov esi, 0 rsi 0 4011 99 mov rdi, rax rdi 402004 "note" 4011 9c mov eax, 0 rax 0 4011 a1 call 401070 open@plt open in libc, by the PLT 4011 a6 mov [rbp - 0x38], eax rdi 402004 "note" 4011 a9 7 lea rcx, [rbp - 0x30] rsi O_RDONLY 4011 ad mov eax, [rbp - 0x38] 4011 b0 mov edx, 0x20 4011 b5 mov rsi, rcx 4011 b8 mov edi, eax 4011 ba call 401060 read@plt read 4011 bf mov [rbp - 0x34], eax main calls open by its stub in the PLT. The arguments are in rdi and rsi: "note" and O_RDONLY. 2 in the stub moment 2 hello.c main waits at line 6 · the pc is in the PLT 3 4 int main ( void ) { 5 char buf [ 32 ] ; 6 int f = open ( "note" , 0 ) ; 7 int n = read ( f , buf , 32 ) ; 8 close ( f ) ; 9 write ( 1 , buf , n ) ; 10 return 0 ; disassembly open@plt · the PLT 4011 76 4 push rbp 4011 77 mov rbp, rsp 4011 7a sub rsp, 0x40 4011 7e mov rax, fs:[0x28] the stack's canary 4011 87 mov [rbp - 8], rax 4011 8b xor eax, eax 4011 8d 6 lea rax, [rip + 0xe70] = 402004 "note" 4011 94 mov esi, 0 4011 99 mov rdi, rax 4011 9c mov eax, 0 4011 a1 call 401070 open@plt open ("note", O_RDONLY) 4011 a6 mov [rbp - 0x38], eax open@plt the PLT · its jmp reads open@got, 403fd8 4010 70 jmp [rip + 0x2f62] 7ffff7d10ec0 open 4010 76 push 4 lazy binding: unused 4010 7b jmp 401020 4010 80 endbr64 _start The call pushed main+48 and went down: main's window keeps its call, ringed; the stub's opens under it, and its jmp reads the GOT. 3 the crossing moments 4 and 5 hello.c main waits at line 6 · the pc is in libc's open 3 4 int main ( void ) { 5 char buf [ 32 ] ; 6 int f = open ( "note" , 0 ) ; 7 int n = read ( f , buf , 32 ) ; 8 close ( f ) ; 9 write ( 1 , buf , n ) ; 10 return 0 ; disassembly open · libc.so.6 4011 9c 6 mov eax, 0 4011 a1 call 401070 open@plt open ("note", O_RDONLY) 4011 a6 mov [rbp - 0x38], eax open@plt the PLT, jumped through 4010 70 jmp [rip + 0x2f62] 7ffff7d10ec0 open open libc.so.6 · no source 7ffff7d10f b6 xor r8d, r8d r8 0 7ffff7d10f b9 mov rdi, 0xffffffffffffff9c rdi -100 AT_FDCWD 7ffff7d10f c0 mov eax, 0x101 rax 0x101 257 7ffff7d10f c5 syscall openat nr 257 7ffff7d10f c7 mov rdx, rax rdi -100 7ffff7d10f ca cmp rax, -0x1000 rsi 402004 "note" 7ffff7d10f d0 ja 7ffff7d10fe8 rdx O_RDONLY 7ffff7d10f d2 mov eax, edx r10 0 the kernel openat, system call 257 openat(AT_FDCWD, "note", O_RDONLY, 0) returns 3 "note" rcx, r11: clobbered libc's open is a wrapper: it puts openat's number in rax and its arguments in rdi, rsi, rdx, r10; syscall crosses down. 4 back up moment 6 hello.c lines 3 to 10 of 11 3 4 int main ( void ) { 5 char buf [ 32 ] ; 6 int f = open ( "note" , 0 ) ; 7 int n = read ( f , buf , 32 ) ; 8 close ( f ) ; 9 write ( 1 , buf , n ) ; 10 return 0 ; disassembly main 4011 7a 4 sub rsp, 0x40 4011 7e mov rax, fs:[0x28] the stack's canary 4011 87 mov [rbp - 8], rax 4011 8b xor eax, eax 4011 8d 6 lea rax, [rip + 0xe70] = 402004 "note" 4011 94 mov esi, 0 4011 99 mov rdi, rax 4011 9c mov eax, 0 4011 a1 call 401070 open@plt open ("note", O_RDONLY) = 3 4011 a6 mov [rbp - 0x38], eax 7fffffffecc8 0 4011 a9 7 lea rcx, [rbp - 0x30] 4011 ad mov eax, [rbp - 0x38] 4011 b0 mov edx, 0x20 4011 b5 mov rsi, rcx 4011 b8 mov edi, eax 4011 ba call 401060 read@plt read 4011 bf mov [rbp - 0x34], eax open's ret came straight back to main+48: the stub was a jump, not a call. The windows close up, and eax holds 3, the descriptor.