nasm 和 ld 的汇编/链接问题
我有一个使用 nasm 编译的示例程序集文件:
nasm -f elf syscall.asm
这会生成一个 syscall.o 文件。我尝试将其与 ld 链接:
ld -o syscall syscall.o
ld 命令失败并出现以下错误:
ld: i386 architecture of input file `syscall.o' is incompatible with i386:x86-64 output
但是,如果我执行
ld -o syscall syscall.o -melf_i386
该命令成功,并且我得到一个 syscall 可执行文件。
弄清楚 nasm 没有生成 x86-64 格式的目标代码,我将“BITS 64”指令添加到 syscall.asm 文件的开头。
然后尝试用 nasm 组装 syscall.asm 出现以下错误:
error: elf output format does not support 64-bit code
这似乎很奇怪,因为在我的终端上执行“file /usr/bin/nasm”给出:
/usr/bin/nasm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
我的 64 位 Fedora Core 11 安装了最新版本的 nasm 并且我的 CPU是英特尔酷睿2双核E7200。
[编辑]
我的问题是如何让 nasm 发出与 i386:x86-64 兼容的目标文件。
I have a sample assembly file that I compile with nasm:
nasm -f elf syscall.asm
This generates a syscall.o file. I try to link it with ld:
ld -o syscall syscall.o
The ld command fails with the following error:
ld: i386 architecture of input file `syscall.o' is incompatible with i386:x86-64 output
However, if I do
ld -o syscall syscall.o -melf_i386
the command succeeds and I get a syscall executable.
Figuring out that nasm is not generating object code in x86-64 format I added "BITS 64" directive to the beginning of the syscall.asm file.
Then attempting to assemble syscall.asm with nasm gave the following error:
error: elf output format does not support 64-bit code
That seems strange because doing "file /usr/bin/nasm" on my terminal gives:
/usr/bin/nasm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
My 64-bit Fedora Core 11 has the latest version of nasm installed and my CPU is Intel Core 2 Duo E7200.
[EDIT]
My question is how do I get nasm to emit object files that is compatible with i386:x86-64.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
elf64
作为输出格式。运行示例:
Try using
elf64
as the output format.Example run: