Segmentation fault when run hello.s by GNU Assembler in Cygwin

守給你的承諾、 提交于 2019-12-11 04:15:47

问题


I use gcc in Cygwin (in Windows7-64 bit) to run this example http://asm.sourceforge.net/howto/build.html

.data                   # section declaration
msg:
    .ascii  "Hello, world!\n"   # our dear string
    len = .-msg         # length of our dear string
.text                   # section declaration
            # we must export the entry point to the ELF linker or
    .global _start  # loader. They conventionally recognize _start as their
            # entry point. Use ld -e foo to override the default.
_start:
# write our string to stdout
    movl    $len,%edx   # third argument: message length
    movl    $msg,%ecx   # second argument: pointer to message to write
    movl    $1,%ebx     # first argument: file handle (stdout)
    movl    $4,%eax     # system call number (sys_write)
    int $0x80       # call kernel
# and exit
    movl    $0,%ebx     # first argument: exit code
    movl    $1,%eax     # system call number (sys_exit)
    int $0x80       # call kernel

by command line in Cygwin $as -o hello.o hello.s && ld -s -o hello hello.o && ./hello the result is Segmentation fault

Can you help me?


回答1:


Cygwin doens't make Windows binary-compatible with Linux, so Linux system calls using int $0x80 will fail as Windows has a completely different convention for system calls. The generated binaries should work fine in an actual (or compatible) Linux environment, though.



来源:https://stackoverflow.com/questions/17132781/segmentation-fault-when-run-hello-s-by-gnu-assembler-in-cygwin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!