为什么 __stat & __fstat 静态链接?

Why are __stat & __fstat linked statically?

我正在使用 LD_PRELOAD 来包装 libc 函数以用于调用跟踪目的。在我尝试包装 __stat 和 __fstat 之前,一切都在膨胀。看起来这两个函数是静态链接的,不像 open、fdopen 等是动态链接的(因此可以包装)。

我很想明白:为什么会这样?

如果您能回答,可加分:我如何包装 __stat 和 __fstat 电话?

谢谢!

matt@matt-laptop:~/code/test$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build/libc_wrapper_lib/libc_wrapper.os -c -D_GNU_SOURCE -D_REENTRANT -std=gnu++11 -g -fPIC build/libc_wrapper_lib/libc_wrapper.cpp
g++ -o lib/libc_wrapper.so -nostartfiles -fPIC -pthread -shared build/libc_wrapper_lib/libc_wrapper.os -ldl
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(stat.oS): In function `__stat':
(.text+0x0): multiple definition of `__stat'
build/libc_wrapper_lib/libc_wrapper.os:/home/matt/code/test/build/libc_wrapper_lib/libc_wrapper.cpp:252: first defined here
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(fstat.oS): In function `__fstat':
(.text+0x0): multiple definition of `__fstat'
build/libc_wrapper_lib/libc_wrapper.os:/home/matt/code/test/build/libc_wrapper_lib/libc_wrapper.cpp:283: first defined here
collect2: error: ld returned 1 exit status
scons: *** [lib/libc_wrapper.so] Error 1
scons: building terminated because of errors.

I would love to understand: Why this is the case?

answer 解释了为什么会这样。

您需要换行 __xstat