为什么动态链接器会尝试打开它知道不存在的文件?

时间:2014-04-08 23:27:36

标签: linker ld dynamic-linking stat

如果我尝试链接到一个未知的库(-lunknown)并查看(使用strace)来查看链接器正在做什么,我注意到,在stat返回-1后立即(ENOENT),链接器尝试open它刚刚发现的文件不存在。从strace输出中,我们看到:

stat("/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/libunknown.so", 0x7fff6694df50) = -1 ENOENT (No such file or directory)
open("/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/libunknown.so", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/libunknown.a", 0x7fff6694dfb0) = -1 ENOENT (No such file or directory)
open("/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/libunknown.a", O_RDONLY) = -1 ENOENT (No such file or directory)
... [lots of similar lines here]

ld版本:

$ ld -v
GNU ld (GNU Binutils for Ubuntu) 2.23.2

为什么链接器会在open返回-1后尝试stat

0 个答案:

没有答案