I have a sample assembly file that I compile with nasm:

我有一个用nasm编译的示例程序集文件:

nasm -f elf syscall.asm 

This generates a syscall.o file. I try to link it with ld:

这会生成一个syscall.o文件。我尝试将它与ld链接:

ld -o syscall syscall.o

The ld command fails with the following error:

ld命令失败,并显示以下错误:

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.

弄清楚nasm没有生成x86-64格式的目标代码我在syscall.asm文件的开头添加了“BITS 64”指令。

Then attempting to assemble syscall.asm with nasm gave the following error:

然后尝试使用nasm组装syscall.asm会出现以下错误:

error: elf output format does not support 64-bit code

That seems strange because doing "file /usr/bin/nasm" on my terminal gives:

这看起来很奇怪,因为在我的终端上执行“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

My 64-bit Fedora Core 11 has the latest version of nasm installed and my CPU is Intel Core 2 Duo E7200.

我的64位Fedora Core 11安装了最新版本的nasm,我的CPU是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.

我的问题是如何让nasm发出与i386兼容的目标文件:x86-64。

1 个解决方案

#1


8

Try using elf64 as the output format.

尝试使用elf64作为输出格式。

Example run:

$ 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)

更多相关文章

  1. Linux基础-常用命令
  2. Linux中iptables基础命令
  3. shell用户配置详解及bash命令参数
  4. CentOS7.2 通过nfs设置共享文件夹
  5. Linux网络和进程管理命令
  6. Linux最常用的基础命令 上篇
  7. linux下查找包含关键字的文件
  8. 【linux学习笔记】vim命令小结
  9. Linux系统下Tar文件安装方法

随机推荐

  1. 如何分析解决Android(安卓)ANR
  2. Android开发(一)Android搭建、HelloWorld
  3. android 完美的ListView实现【原创】
  4. android中置调用指定浏览器
  5. Android实战【可可爱爱一零一动植物志】(
  6. android 随手记 videoview循环播放网络视
  7. Android黑科技动态加载(四)之动态启动插
  8. Android简介
  9. 【Android进阶】android:configChanges属
  10. 很实用的android压缩图片的算法