【发布时间】:2012-10-12 14:25:44
【问题描述】:
我想编译并执行一个非常简单的 64 位程序。
section .text
global _start
_start:
mov rdx,len
mov rcx,msg
mov rbx,1
mov rax,4
int 0x80
mov rbx,0
mov rax,1
int 0x80
section .data
msg db "Hello, world!",0xa
len equ $ - msg
编译它的行:
yasm -f elf64 -g dwarf2 example.asm
$ yasm --version
yasm 1.2.0
还尝试了另一种格式macho[|32|64], elf[|32] bin,但都没有成功。
链接它的行:
gcc -o example example.o
ld: warning: ignoring file example.o, file was built for unsupported file format ( 0x7f 0x45 0x4c 0x46 0x 2 0x 1 0x 1 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): example.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
还尝试了gcc 的一些选项,例如-m64 -arch x86_64。
【问题讨论】:
-
MacOS 上的 gcc 不能使用 Mach 格式吗?
-
您是否尝试过使用 NASM/YASM/FASM 的不同
-f选项?我的意思是,那里的马赫格式。 -
所有的-f macho, elf