Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15491

pop rbp causes segmentation fault

$
0
0

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.


Viewing all articles
Browse latest Browse all 15491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>