【发布时间】:2014-07-01 01:58:08
【问题描述】:
我有以下汇编代码(复制自here):
hello.asm:
section .data
msg: db 'hello, world!', 0
section .text
global _start
_start:
mov rax, 4
mov rdi, 1
mov rsi, qword msg ; I added qword because the compiler complained
mov rdx, 13
syscall
mov rax, 1
xor rdi, rdi
syscall
正如上面评论中所解释的,我添加了qword,因为我收到了以下错误消息:
$ yasm -f macho64 hello.asm
hello.asm:10: error: macho: sorry, cannot apply 32 bit absolute relocations in 64 bit mode, consider "[_symbol wrt rip]" for mem access, "qword" and "dq _foo" for pointers.
进行更改后,编译和链接都成功,但运行时出现总线错误:
$ yasm -f macho64 hello.asm
$ ld -o hello -e _start hello.o
$ ./hello
bus error ./hello
qword 的添加是否不正确,还是我需要更改其他内容?
【问题讨论】: