简体   繁体   English

bash,无法执行二进制文件

[英]bash, can't execute binary file

I'm currently trying to learn assembly on my Trisquel distribution (which I guess uses Ubuntu under the hood?). 我目前正在尝试在Trisquel发行版上学习汇编语言(我猜想是在后台使用Ubuntu?)。 For some reason, I'm stuck on the very first step of creating and executing a assembly snippet. 由于某些原因,我停留在创建和执行程序集摘要的第一步。

.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

When I try to assemble and link it for creating an executable and run the executable, I get something like: 当我尝试组装并链接它以创建可执行文件并运行该可执行文件时,我得到如下信息:

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

I'm not sure what exactly is going on here. 我不确定这里到底发生了什么。 After searching around, it seems that this error usually pops up when trying to execute 32 bit executable on a 64 bit OS or maybe vice-versa which isn't the case for me. 搜索后,似乎在尝试在64位OS上执行32位可执行文件时通常会弹出此错误,反之亦然,这对我而言并非如此。

Here is the output of file and uname command: 这是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

Can someone help me out in understanding what exactly is going wrong here? 有人可以帮助我了解这里到底出了什么问题吗? Thanks. 谢谢。

.section text

is incorrect, that creates a section called text when you need your code to be in the .text section. 是不正确的,当您需要将代码放在.text节中时,会创建一个名为text的节。 Replace that with: 替换为:

.data

.text
.globl _start
_start:
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM