【发布时间】:2014-01-22 23:59:48
【问题描述】:
我正在尝试用 64 位汇编编写一个简单的 hello world 程序并在 Ubuntu 64 位上运行。程序如下:
global _start ; entry point export for ld section .text
_start: ; system call to write message to stdout
mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
mov rsi, mes ; message address
mov rdx, len ; message length
syscall ; exit sys call
mov rax, 60 ; exit call id
mov rdi, 0 ; return success
syscall
section .data
mes: db 'Hello, world!',0x0A ; message
len : equ $-mes
我使用nasm -f elf64 hello64.asm 组装它
并尝试使用ld -o hello64 hello64.o 链接它
它给了我以下错误 -
ld: 输入文件 `hello64.o' 的 i386:x86-64 架构不兼容 带 i386 输出
即使使用标志 --oformat elf64-x86-64 或 elf64-little 或 elf64-big,我也会遇到同样的错误。
有人可以帮忙吗?
【问题讨论】:
-
相关:building static / dynamic binaries from asm with GNU tools。
_start或main,带/不带 libc。可能您使用的是 32 位安装的 Ubuntu?试试file /usr/bin/ld,虽然我实际上希望32位ld能够使用正确的--oformat制作64位可执行文件。
标签: ubuntu assembly 64-bit nasm