Linux nasm和ld的装配/链接问题
我有一个使用nasm编译的示例程序集文件:Linux nasm和ld的装配/链接问题,linux,assembly,linker,x86-64,nasm,Linux,Assembly,Linker,X86 64,Nasm,我有一个使用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 error: elf output format does not support 6
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
error: elf output format does not support 64-bit code
然而,如果我这样做
ld -o syscall syscall.o -melf_i386
命令成功,我得到一个系统调用可执行文件
我发现nasm没有生成x86-64格式的目标代码,于是在syscall.asm文件的开头添加了“BITS 64”指令
然后,尝试使用nasm组装syscall.asm时出现以下错误:
ld: i386 architecture of input file `syscall.o' is incompatible with i386:x86-64 output
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是Intel Core 2 Duo E7200
[编辑]
我的问题是如何让nasm发出与i386:x86-64兼容的对象文件。尝试使用
elf64
作为输出格式
运行示例:
$ cat elf64.asm
section .text
jmp [rax]
$ nasm -f elf64 elf64.asm
$ objdump -Sr elf64.o
elf64.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <.text>:
0: ff 20 jmpq *(%rax)
$cat elf64.asm
第节.案文
jmp[rax]
$nasm-f elf64 elf64.asm
$objdump-Sr elf64.o
o:文件格式elf64-x86-64
第节的分解。正文:
0000000000000000 :
0:ff 20 jmpq*(%rax)
那么问题是什么?