【发布时间】:2012-03-07 16:55:18
【问题描述】:
我正在阅读this 的文章, 在某一时刻,它给了我这个 nasm 程序:
; tiny.asm
BITS 32
GLOBAL main
SECTION .text
main:
mov eax, 42
ret
并告诉我运行以下命令:
$ nasm -f elf tiny.asm
$ gcc -Wall -s tiny.o
我收到以下错误:
ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
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
我大胆猜测可能是什么问题,并将 BITS 行更改为:
BITS 64
但是当我运行 nasm -f elf tiny.asm 时,我得到:
tiny.asm:2: error: `64' is not a valid segment size; must be 16 or 32
如何修改代码以在我的机器上工作?
编辑:
我听取了 cmets 的 Alex 的建议并下载了更新的版本。然而,
./nasm-2.09.10/nasm -f elf tiny.asm
抱怨
tiny.asm:2: error: elf32 output format does not support 64-bit code
另一方面,
./nasm-2.09.10/nasm -f elf64 tiny.asm
gcc -Wall -s tiny.o
抱怨
ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
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
【问题讨论】:
-
@Alex elf64 给了我“无法识别的输出格式”。至于版本, nasm -v 给了我“2011 年 11 月 3 日编译的 NASM 版本 0.98.40(Apple Computer, Inc. build 11)” 0.98 看起来可能是旧版本,但它是在 2011 年编译的,所以它可以'不会那么老吧?苹果为什么要发布过时的软件?无法在 64 位平台上汇编 64 位代码的默认汇编器?
-
你的已经过时了。我的打印“2011 年 7 月 15 日编译的 NASM 版本 2.09.10”。较新的版本是here。