The following assembly code causes a segmentation fault exiting from the main function at the pop rbp
instruction (this code was generated by a compiler I'm writing, so don't mind the superfluous instructions)
.intel_syntax noprefix.global main.textadd: push rbp mov rbp, rsp sub rsp, 4 mov dword [rbp - 4], edi sub rsp, 4 mov dword [rbp - 8], esi mov eax, dword [rbp - 4] mov ebx, dword [rbp - 8] add eax, ebx mov rsp, rbp pop rbp retmain: push rbp mov rbp, rsp sub rsp, 4 mov eax, 5 mov dword [rbp - 8], eax mov eax, 60 mov edi, eax mov eax, 9 mov esi, eax call add mov rsp, rbp pop rbp ret add rsp, 4
I've double checked I'm keeping the stack in order, so I don't see how this error could be occurring.
I've tried debugging it with GDB, but with not much success.