0
我正在开发一个针对x86和amd64的编译器。我的编译器在64位计算机上工作的非常好。在32位,我得到一个段错误。从主函数调用函数(生成的NASM代码)时出现分段错误
一个简单的空的程序(只是主要方法)编译成以下组件:
extern GC_init
global main
global f_main
segment .data
segment .text
main:
; argc = dword [ebp+8]
; argv = dword [ebp+12]
push edx
; line 3
; proceed GC_init[]
xor dword eax, dword eax
call GC_init
; line 4
; proceed [email protected][argc, argv]
push dword [ebp+12]
push dword [ebp+8]
xor dword eax, dword eax
call f_main
sub dword esp, dword 8
pop edx
ret
f_main:
push edx
; line 7
; oax = 0
mov dword eax, dword 0
; line 8
.L0:
pop edx
ret
f_main
是实际的主要方法。 main
只需呼叫GC_init
,然后f_main
。
我编译和使用下列命令运行的代码:
$ nasm -f elf -o test.o test.asm
$ gcc -o etest test.o -lgc
$ ./etest
Segmentation fault (core dumped)
我调试使用GDB程序,发现段错误来自于第二按压指令(push dword [ebp+12]
)。
这里是我的电脑的一些信息:
$ uname -a
Linux [name] 3.13.0-37-generiC#64-Ubuntu SMP Mon Sep 22 21:30:01 UTC 2014 i686 athlon i686 GNU/Linux
我在做什么错?