linux“无法执行二进制文件”在我编译的每个可执行文件上, chmod 777 没有帮助

发布于 2024-10-04 08:54:48 字数 375 浏览 7 评论 0原文

我运行的是 red linux 7.3(旧的,我知道),在过去的几个月里我一直在学习汇编编程,编写小程序并使用 nasm 进行编译。几个月来,一切都进展顺利,但现在由于某种未知的原因,我无法执行我编译的任何程序。

nasm file.s //used to work just fine, then I'd execute ./file

现在,当我运行 ./file 时,首先我得到“权限被拒绝”,这以前从未发生过。然后,一旦我 chmod +777 文件,我得到“无法执行二进制文件”。

我不知道为什么会发生这种情况,但这非常令人沮丧,因为我编译的任何内容都不会再运行。

以 root 身份登录不会改变任何内容。 欢迎所有建议,谢谢!

I am running red had linux 7.3 (old, I know), and for the past few months I've been learning assembly programming, writing small programs and compiling with nasm. For months, things have been going fine, and now for some unknown reason, I cannot execute any programs that I compile.

nasm file.s //used to work just fine, then I'd execute ./file

now, when I run ./file, first I get "permission denied", which never used to happen before. then, once i chmod +777 file, I get "cannot execute binary file".

I have NO IDEA why this is happening, but it is extremely frustrating since NOTHING I compile will run anymore.

Logging in as root doesn't change anything.
All suggestions are welcome, THANK YOU!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

瑶笙 2024-10-11 08:54:48

nasm 不会生成可执行文件,而只是生成目标文件(如 gcc -c 那样)。您仍然需要在其上运行链接器。

注意:“0777 几乎总是错误的。”

nasm does not produce an executable, but just an object file (like gcc -c would). You still need to run the linker on it.

N.B.: “0777 is almost always wrong.”

何其悲哀 2024-10-11 08:54:48

对二进制文件运行 file 命令,并确保它们被正确识别为可执行文件。

另请尝试 ldd 命令。它很可能会因为完全相同的原因而失败,但值得一试。

Run the file command on your binaries and make sure they're identified correctly as executables.

Also try the ldd command. It will very likely fail for the exact same reason, but it's worth a shot.

夏日浅笑〃 2024-10-11 08:54:48

如果您操作的文件系统是使用 noexec 选项挂载的,则可能会发生这种情况。您可以通过执行 mount | 来检查这一点。 grep noexec 并查看您当前的工作目录是否受到此问题的影响。

This can happen if the file system you operate on is mounted with the noexec option. You could check that by doing mount | grep noexec and see if your current working directory suffers from that.

檐上三寸雪 2024-10-11 08:54:48

“无法执行二进制文件”是错误代码 ENOEXECstrerror(3) 消息。这有一个非常具体的含义:(引用 execve(2) 的联机帮助页)

[ENOEXEC]          The new process file has the appropriate access
                   permission, but has an unrecognized format
                   (e.g., an invalid magic number in its header).

所以这意味着,您的 nasm 调用不会生成可执行文件,而是生成其他内容。正如 John Kugelman 所建议的,file 命令会告诉你它是什么(user502515 很可能是正确的,它是一个未链接的目标文件,但我自己从未使用过 nasm,所以我不知道) 。

顺便说一句,如果您现在学习 GAS/“AT&T”汇编语法,而不是当您需要为不支持英特尔奇异世界语法的架构重写汇编代码时,您会对自己有帮助。我确实希望您仅将汇编用于实际上需要手动优化的内循环子例程。

"Cannot execute binary file" is the strerror(3) message for the error code ENOEXEC. That has a very specific meaning: (quoting the manpage for execve(2))

[ENOEXEC]          The new process file has the appropriate access
                   permission, but has an unrecognized format
                   (e.g., an invalid magic number in its header).

So what that means is, your nasm invocation is not producing an executable, but rather something else. As John Kugelman suggests, the file command will tell you what it is (user502515 is very likely to be right that it's an unlinked object file, but I have never used nasm myself so I don't know).

BTW, you'll do yourself a favor if you learn GAS/"AT&T" assembly syntax now, rather than when you need to rewrite your assembly code for an architecture that doesn't do Intel bizarro-world syntax. And I do hope you're using assembly only for inner-loop subroutines that actually need to be hand-optimized.

一影成城 2024-10-11 08:54:48

这件事刚刚发生在我身上。 后

运行file

输出 ELF 64 位 LSB 可执行文件,x86-64,版本 1 (SYSV),动态链接(使用共享库),适用于 GNU/Linux 2.6.15,未剥离

问题是我试图运行32 位 机器上的 64 位 应用程序!

This just happened to me. After running

file <executable name>

it output <file name> ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped

And the problem was that I was trying to run a 64 bit app on a 32 bit machine!

清风疏影 2024-10-11 08:54:48

您可以尝试查看 /var/log 以了解从此时开始系统中发生的某些变化。

You may try looking into /var/log for some change in the system from this start to happen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文