我有以下的C程序:我的编译器如何查找stat(文件状态)函数?
#include <sys/stat.h>
int main(int argc, char **argv) {
struct stat fileStat;
if(stat(argv[1],&fileStat) < 0)
return 1;
}
当我它编译使用锵LLVM IR到,我可以看到stat
被声明为以下:
declare i32 @stat(i8*, %struct.stat*)
通常,这样的外部呼叫到系统函数直接映射到C标准库函数。例如,我可以找到malloc
有以下几点:
nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep malloc
然而,stat
功能似乎要区别对待。当grepping为stat
时,我可以找到相关函数,如__xstat
,但不是stat
函数本身。
当我通过ltrace
跟踪到外部库的调用时,我看到以下调用:__xstat(1, ".", 0x7fff7928c6f0)
。此外,可执行文件中的代码还确认,不是调用stat
函数,而是调用__xstat
函数。
我没有观察到C标准库的其他函数调用的名称与C程序中声明的名称不同。为什么在标准库中没有直接的等价物,我的编译器如何发现它应该调用__xstat
而不是stat
?
这可能会帮助你很多http://stackoverflow.com/questions/8237294/intercepting-stat –