【发布时间】:2019-03-23 22:42:26
【问题描述】:
我对 bash 并不陌生,但这是我第一次看到这种情况发生。
[OP@localhost linking]$ ls
helloworld-lib.o helloworld-lib.s helloworld_s
[OP@localhost linking]$ ./helloworld_s
bash: ./helloworld_s: No such file or directory
我在测试链接器ld 时发生此错误。 helloworld-lib.s的内容是:
[OP@localhost linking]$ cat helloworld-lib.s
.section .data
helloworld:
.ascii "Hello, world!\n\0"
.section .text
.globl _start
_start:
mov $helloworld, %rdi
call printf
mov $0, %rdi
call exit
此文件helloworld_s 生成如下。
[OP@localhost linking]$ as helloworld-lib.s -o helloworld-lib.o
[OP@localhost linking]$ ld -lc helloworld-lib.o -o helloworld_s
IDK(如果有任何相关信息)。作为一个仅供参考,如果我尝试运行其他文件,我只会得到一个权限被拒绝(如预期的那样)。有什么想法吗?
编辑:按照建议,这是ls -l 的输出:
[OP@localhost linking]$ ls -l
total 88
-rw-rw-r--. 1 OP OP 968 Mar 23 18:40 helloworld-lib.o
-rw-rw-r--. 1 OP OP 159 Mar 23 18:40 helloworld-lib.s
-rwxrwxr-x. 1 OP OP 14384 Mar 23 18:41 helloworld_s
这是id的输出:
[OP@localhost linking]$ id
uid=1000(OP) gid=1000(OP) groups=1000(OP),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
编辑:有关答案,请参阅 cmets。 See here
【问题讨论】:
-
@Kenster 我不相信它。例如,我可以
cat该文件没有问题。使用basename,我没有发现文件名有任何异常。 -
将
ls -l和id的输出添加到您的问题中。 -
很可能,
ldd会告诉您它正在寻找像/lib/ld64.so.1这样不存在的东西。 -
@DavidSchwartz 哦,是的,确实如此。
readelf -l helloworld_s告诉我程序请求解释器/lib/ld64.so.1,正如你所说,它不存在。很明显,这里有东西。当我将解释器明确指定为/usr/lib64/ld-linux-x86-64.so.2时,一切正常。首先,您可以将其发布为答案吗?但是,如果是这种情况,为什么我会将此作为我的错误?此外,为什么 GNU 链接器默认请求一个不存在的程序解释器? -
我们可以在答案中得到这个并将其标记为已回答或关闭吗?