为什么静态链接__stat和__fstat?

Mat*_*ann 5 glibc

我正在使用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.
Run Code Online (Sandbox Code Playgroud)

Emp*_*ian 1

我很想了解:为什么会出现这种情况?

这个答案解释了为什么会出现这种情况。

你需要包裹__xstat起来。