此代码在终端中使用 GCC 可以很好地组装:
.globl _sub
_sub:
push %rbp
mov %rbp,%rsp
mov $0xBEEF,%eax
pop %rbp
ret
.globl _main
_main:
push %rbp
mov %rbp,%rsp
call _sub
mov $0,%eax
pop %rbp
ret
但是当我运行 a.out 文件时,我得到了这个错误:
Segmentation fault: 11
如果我在 GDB 中运行它,这是我得到的错误:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001
0x0000000000000001 in ?? ()
关于为什么会发生这种情况的任何想法?