【问题标题】:bash, can't execute binary filebash,无法执行二进制文件
【发布时间】:2012-01-08 19:15:30
【问题描述】:

我目前正在尝试在我的 Trisquel 发行版上学习汇编(我猜它在引擎盖下使用了 Ubuntu?)。出于某种原因,我被困在创建和执行程序集 sn-p 的第一步。

.section data

.section text
.globl _start
_start:
movl $1, %eax # syscall for exiting a program
movl $0, %ebx # status code to be returned
int $0x80

当我尝试组装和链接它以创建可执行文件并运行可执行文件时,我得到如下内容:

> as myexit.s -o myexit.o && ld myexit.o -o myexit
> ./myexit
bash: ./myexit: cannot execute binary file

我不确定这里到底发生了什么。搜索后,似乎在尝试在 64 位操作系统上执行 32 位可执行文件时通常会弹出此错误,反之亦然,但对我来说并非如此。

这是fileuname 命令的输出:

$ file myexit
myexit: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
$ uname -a
Linux user 2.6.35-28-generic #50trisquel2-Ubuntu SMP Tue May 3 00:54:52 UTC 2011 i686 GNU/Linux

有人可以帮助我了解这里到底出了什么问题吗?谢谢。

【问题讨论】:

  • 可执行位在那里,对吧?
  • @Uku: 是的,否则通常会给出permission denied 错误
  • 我自己也是这么想的,但只是在检查。

标签: linux ubuntu assembly


【解决方案1】:
.section text

不正确,当您需要代码位于 .text 部分时,它会创建一个名为 text 的部分。将其替换为:

.data

.text
.globl _start
_start:
  ...

【讨论】:

  • 哇,非常感谢!将data 替换为.data 并将text 替换为.text 后,代码就像一个魅力。
猜你喜欢
  • 1970-01-01
  • 2011-06-21
  • 2021-05-09
  • 2014-04-22
  • 2021-09-25
  • 1970-01-01
  • 1970-01-01
  • 2013-08-04
  • 1970-01-01
相关资源
最近更新 更多